Revision b6bc4afa snf-django-lib/snf_django/lib/api/utils.py
b/snf-django-lib/snf_django/lib/api/utils.py | ||
---|---|---|
34 | 34 |
import datetime |
35 | 35 |
from dateutil.parser import parse as date_parse |
36 | 36 |
from django.utils import simplejson as json |
37 |
from django.http import HttpResponse |
|
37 | 38 |
|
38 | 39 |
from django.conf import settings |
39 | 40 |
from snf_django.lib.api import faults |
... | ... | |
115 | 116 |
prefix += '/' |
116 | 117 |
pattern = '^' + prefix |
117 | 118 |
return pattern |
119 |
|
|
120 |
|
|
121 |
def filter_modified_since(request, objects): |
|
122 |
"""Filter DB objects based on 'changes-since' request parameter. |
|
123 |
|
|
124 |
Parse request for 'changes-since' parameter and get only the DB objects |
|
125 |
that have been updated after that time. Otherwise, return the non-deleted |
|
126 |
objects. |
|
127 |
|
|
128 |
""" |
|
129 |
since = isoparse(request.GET.get("changes-since")) |
|
130 |
if since: |
|
131 |
modified_objs = objects.filter(updated__gte=since) |
|
132 |
if not modified_objs: |
|
133 |
return HttpResponse(status=304) |
|
134 |
return modified_objs |
|
135 |
else: |
|
136 |
return objects.filter(deleted=False) |
Also available in: Unified diff