<commit_before>from piston.handler import BaseHandler
from knesset.simple.models import Vote, Member, Party, Membership

def limit_by_request(qs, request):
    if 'num' in request.GET:
        num = int(request.GET['num'])
        page = 'page' in request.GET and int(request.GET['page']) or 0
        return qs[page*num:(page+1)*num]
    return qs

class MemberHandler(BaseHandler):
    fields = ('id', 'name', 'start_date', 'end_date',
              'membership',
             )
    allowed_methods = ('GET',)
    model = Member
    def read(self, request, member_id=None):
        if member_id:
            return Member.objects.get(pk=member_id)
        else:
            qs = Member.objects.all()
            return limit_by_request(qs, request)

    @classmethod
    def membership (self, member):
        qs = Membership.objects.filter(member=member)
        return qs.values('start_date', 'end_date', 'party_id')

class VoteHandler(BaseHandler):
    # fields = ('for', 'against', 'abstain')
    fields = ('id', 'title', 'time', 'ForVotesCount', 'AgainstVotesCount',
              ('voted_for' , ('member', ('id'))),
              ('voted_against' , ('member', ('id'))),
              ('voted_abstain' , ('member', ('id'))),
              ('didn_vote' , ('member', ('id'))),
              'topics_for',
              'topics_against',
             )
    allowed_methods = ('GET',)
    model = Vote
    def read(self, request, vote_id=None):
        if vote_id:
            return Vote.objects.get(pk=vote_id)
        else:
            qs = Vote.objects.all()
            return limit_by_request(qs, request)<commit_msg>A more Interesting order - getting Azmi of the top.<commit_after>from piston.handler import BaseHandler
from knesset.simple.models import Vote, Member, Party, Membership

def limit_by_request(qs, request):
    if 'num' in request.GET:
        num = int(request.GET['num'])
        page = 'page' in request.GET and int(request.GET['page']) or 0
        return qs[page*num:(page+1)*num]
    return qs

class MemberHandler(BaseHandler):
    fields = ('id', 'name', 'start_date', 'end_date',
              'membership',
             )
    allowed_methods = ('GET',)
    model = Member
    def read(self, request, member_id=None):
        if member_id:
            return Member.objects.get(pk=member_id)
        else:
            qs = Member.objects.all().order_by('-end_date', 'name')
            return limit_by_request(qs, request)

    @classmethod
    def membership (self, member):
        qs = Membership.objects.filter(member=member)
        return qs.values('start_date', 'end_date', 'party_id')

class VoteHandler(BaseHandler):
    # fields = ('for', 'against', 'abstain')
    fields = ('id', 'title', 'time', 'ForVotesCount', 'AgainstVotesCount',
              ('voted_for' , ('member', ('id'))),
              ('voted_against' , ('member', ('id'))),
              ('voted_abstain' , ('member', ('id'))),
              ('didn_vote' , ('member', ('id'))),
              'topics_for',
              'topics_against',
             )
    allowed_methods = ('GET',)
    model = Vote
    def read(self, request, vote_id=None):
        if vote_id:
            return Vote.objects.get(pk=vote_id)
        else:
            qs = Vote.objects.all()
            return limit_by_request(qs, request)
{'fraction_non_alphanumeric': 0.14909638554216867, 'fraction_numerical': 0.0012048192771084338, 'mean_word_length': 2.455775234131113, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7121151', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1012, 'n_words': 234}