Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

Commit

Permalink
Merge ded49ab into 693bf7f
Browse files Browse the repository at this point in the history
  • Loading branch information
bruth committed Feb 6, 2014
2 parents 693bf7f + ded49ab commit 6498dd1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 31 deletions.
12 changes: 2 additions & 10 deletions serrano/resources/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def category_posthook(instance, data, request):
class CategoryParametizer(Parametizer):
"Supported params and their defaults for Category endpoints."

published = BoolParam()
unpublished = BoolParam(False)


class CategoryBase(ThrottledResource):
Expand Down Expand Up @@ -101,15 +101,7 @@ def get(self, request, pk=None):

# For privileged users, check if any filters are applied, otherwise
# only allow for published objects.
if can_change_category(request.user):
filters = {}

if params['published'] is not None:
filters['published'] = params['published']

if filters:
queryset = queryset.filter(**filters)
else:
if not can_change_category(request.user) or not params['unpublished']:
queryset = queryset.published()

return self.prepare(request, queryset, **params)
Expand Down
12 changes: 2 additions & 10 deletions serrano/resources/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ConceptParametizer(Parametizer):

sort = StrParam()
order = StrParam('asc')
published = BoolParam()
unpublished = BoolParam(False)
embed = BoolParam(False)
brief = BoolParam(False)
query = StrParam()
Expand Down Expand Up @@ -215,15 +215,7 @@ def get(self, request, pk=None):

# For privileged users, check if any filters are applied, otherwise
# only allow for published objects.
if can_change_concept(request.user):
filters = {}

if params['published'] is not None:
filters['published'] = params['published']

if filters:
queryset = queryset.filter(**filters)
else:
if not can_change_concept(request.user) or not params['unpublished']:
queryset = queryset.published()

# If Haystack is installed, perform the search
Expand Down
12 changes: 2 additions & 10 deletions serrano/resources/field/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class FieldParametizer(Parametizer):

sort = StrParam()
order = StrParam('asc')
published = BoolParam()
unpublished = BoolParam(False)
brief = BoolParam(False)
query = StrParam()
limit = IntParam()
Expand Down Expand Up @@ -142,15 +142,7 @@ def get(self, request):

# For privileged users, check if any filters are applied, otherwise
# only allow for published objects.
if can_change_field(request.user):
filters = {}

if params['published'] is not None:
filters['published'] = params['published']

if filters:
queryset = queryset.filter(**filters)
else:
if not can_change_field(request.user) or not params['unpublished']:
queryset = queryset.published()

# If Haystack is installed, perform the search
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/resources/tests/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_get_privileged(self):
# Superuser sees everything
self.client.login(username='root', password='password')

response = self.client.get('/api/fields/',
response = self.client.get('/api/fields/?unpublished=1',
HTTP_ACCEPT='application/json')
self.assertEqual(len(json.loads(response.content)), 12)

Expand Down

0 comments on commit 6498dd1

Please sign in to comment.