Skip to content

Commit

Permalink
add filters
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentVW committed Nov 20, 2016
1 parent 3a2e536 commit 6ace8b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions OIPA/api/activity/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ class ActivityFilter(TogetherFilterSet):
fk='current_activity',
)

related_activity_transaction_receiver_organisation_name = ToManyFilter(
qs=RelatedActivity,
lookup_type='in',
name='ref_activity__transaction__receiver_organisation__narratives__content',
fk='current_activity',
)

related_activity_recipient_country = ToManyFilter(
qs=RelatedActivity,
lookup_type='in',
Expand Down Expand Up @@ -543,6 +550,7 @@ def remove_invalid_fields(self, queryset, ordering, view):
'actual_end_date': 'actual_end',
'start_date': 'start_date',
'end_date': 'end_date',
'xml_source_ref': 'xml_source_ref'
}

for i, term in enumerate(ordering):
Expand Down
7 changes: 7 additions & 0 deletions OIPA/api/transaction/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ class TransactionFilter(FilterSet):
fk='transaction',
)

provider_activity_reporting_org = ToManyFilter(
qs=TransactionProvider,
lookup_type='in',
name='provider_activity__reporting_organisations__ref',
fk='transaction',
)

provider_organisation_primary_name = ToManyFilter(
qs=TransactionProvider,
lookup_type='in',
Expand Down
7 changes: 3 additions & 4 deletions tools/collect_and_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import gzip
import tarfile
import StringIO
from random import randint

from email.utils import parsedate

def _parse_http_datetime(s):
return time.mktime(parsedate(s))


file_grabber = FileGrabber()
source_count = IatiXmlSource.objects.count()

if source_count is 0:
Expand All @@ -40,18 +40,17 @@ def _parse_http_datetime(s):
os.makedirs(directory)

def handle_response(tar, source):
file_grabber = FileGrabber()
response = file_grabber.get_the_file(source.source_url)

if not response or response.code != 200:
print("source url {} down or doesn't exist".format(source.source_url))
return

modified_time = response.info().get('Last-Modified')

iati_file = StringIO.StringIO(response.read())

info = tarfile.TarInfo(
name="{}_{}.xml".format(source.publisher, source.ref)
name="{}.xml".format(source.ref)
)

info.size = len(iati_file.buf)
Expand Down

0 comments on commit 6ace8b8

Please sign in to comment.