Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/lidermanrony/Open-Knesset:
  issue #172: an _extremely_  partial remediation. issue should not be considered as solved. this only solves the issue for votes page and the from_date and to_date filels. long term solution should be somehow reusing the same filter code in the API and in the views
  • Loading branch information
ofri committed Feb 21, 2015
2 parents d5c05c1 + 22fa23f commit 85bb6e7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions laws/api.py
Expand Up @@ -2,7 +2,6 @@
API for the laws app
'''
import logging

from django.core.urlresolvers import reverse
from tastypie.constants import ALL
import tastypie.fields as fields
Expand All @@ -19,6 +18,7 @@
from simple.management.commands.syncdata_globals import p_explanation
from agendas.models import AgendaVote

from datetime import datetime, timedelta
logger = logging.getLogger("open-knesset.laws.api")

class LawResource(BaseResource):
Expand Down Expand Up @@ -53,7 +53,9 @@ class Meta(BaseResource.Meta):
filtering = dict(tag=('exact'),
member=ALL,
member_for=ALL,
member_against=ALL)
member_against=ALL,
from_date=ALL,
to_date=ALL)

votes = fields.ToManyField(VoteActionResource,
attribute=lambda bundle:VoteAction.objects.filter(
Expand All @@ -80,6 +82,14 @@ def build_filters(self, filters={}):
# hard-coded the __in filter. not great, but works.
orm_filters["tagged_items__tag__in"] = \
filters["tag"].split(',')
if 'from_date' in filters:
orm_filters["time__gte"] = filters['from_date']
if 'to_date' in filters:
# the to_date needs to be incremented by a day since when humans say to_date=2014-07-30 they
# actually mean midnight between 30 to 31. python on the other hand interperts this as midnight between
# 29 and 30
to_date = datetime.strptime(filters["to_date"], "%Y-%M-%d")+timedelta(days=1)
orm_filters["time__lte"] = to_date.strftime("%Y-%M-%d")
return orm_filters

def dehydrate_agendas(self, bundle):
Expand Down

0 comments on commit 85bb6e7

Please sign in to comment.