1. Jesper Noehr
  2. django-piston
  3. Issues
Issue #27 resolved

AnonymousBaseHandler does not filter on fields

Seph Soliman
created an issue

As specified in the Getting started documentation, the fields tuple should specify what model fields that are outputted. Using a BaseHandler abides by the fields tuple definition but switching to AnonymousBaseHandler will ignore the fields definition.

I'm assuming this isn't intentional.

example:

{{{

!python

class VideoHandler(BaseHandler): model = Video fields = ('title',) def read(self, request, video_id): v = Video() v.title = 'Hello world!' return { 'video': v } }}}

returns: {{{

!javascript

{"video": {"title": "Hello world!"}} }}}

Changing to AnonymousBaseHandler suddenly yields: {{{

!javascript

{"video":{ "title": "Hello world!", description: "This is a description", id: null, created: null (...) }} }}}

Note that the example outputs are hand-made

Piston version 0.2. Django 1.0. Python 2.4 (with a minor modification to make Piston work)

Comments (6)

  1. Jesper Noehr repo owner

    If you look at the bundled example application (examples/blogserver/) you will see a handler for authorized requests and one for anonymous ones. Both define fields =, and after testing it across formats, I found that AnonymousBaseHandler respects fields just fine.

    Can you try to run the example app, and change the 'fields' in the anonymous handler, and see what goes on? You can do it via curl -v http://127.0.0.1:8000/api/posts.json.

  2. Seph Soliman reporter

    Inheriting directly from AnonymousBaseHandler seems to be the issue. Creating a proxy class that inherits from BaseHandler and assigns anonymous access to the handler (as seen in the blogserver will work).

  3. Log in to comment