Maybe you can start by copying the jsonify decorator, and modify it to suit your needs.
On Sat, Jan 12, 2013 at 2:44 AM, Joel <jrwdun...@gmail.com> wrote: > Yeah, the jsonify decorator works. But I need to be able to pass a custom > JSONEncoder subclass to json.dumps, e.g., return json.dumps(result, > cls=h.JSONOLDEncoder) so I think that rules out using @jsonify, right? > Also, I've looked at the jsonify code and it's not doing anything special > that I'm not doing ... I'm quite puzzled about why response.content_type = > 'application/json' has no effect in my controller actions. I feel like I > must be missing something quite obvious ... > > > On Friday, January 11, 2013 3:26:12 PM UTC-8, ronan wrote: > >> Does it work if you use the jsonify decorator? >> >> >> On Sat, Jan 12, 2013 at 12:14 AM, Joel <jrwd...@gmail.com> wrote: >> >>> Hey Ronan, >>> >>> Thanks. However, the FileApp stuff is a bit of a red herring. FileApp >>> correctly sets the content type (i.e., to the MIMEtype of the file being >>> served) without any interference on my part. >>> >>> The problem is that I can't get my JSON responses to have the correct >>> content type header. I'm returning JSON in nearly every controller action >>> and no matter what I do I get text/html; charset=utf-8 as the content type >>> ... >>> >>> >>> On Friday, January 11, 2013 10:43:50 AM UTC-8, ronan wrote: >>>> >>>> Hi Joel, >>>> >>>> Try passing the Content-Type header to FileApp like this: >>>> >>>> @restrict('GET') >>>> @h.authenticate >>>> def retrieve(self, id): >>>> """Return the file data (binary stream) for the file in files/ with >>>> name=id or an error message if the file does not exist or the user >>>> is >>>> not authorized to access it. >>>> """ >>>> file = Session.query(File).filter(**Fil**e.name==id).first() >>>> if file: >>>> unrestrictedUsers = h.getUnrestrictedUsers() >>>> if h.**userIsAuthorizedToAccessMode**l(**session['user'], >>>> file, unrestrictedUsers): >>>> filePath = >>>> os.path.join(config['app_conf'****]['permanent_store'], >>>> id) >>>> headers = [('Content-Type', 'application/json')] >>>> result = forward(FileApp(filePath, headers=headers)) >>>> else: >>>> response.status_int = 403 >>>> result = h.unauthorizedJSONMsg >>>> else: >>>> response.status_int = 404 >>>> result = json.dumps({'error': 'There is no file with name %s' % >>>> id}) >>>> return result >>>> >>>> See >>>> http://pythonpaste.org/**modules**/fileapp.html<http://pythonpaste.org/modules/fileapp.html> >>>> >>>> Hope this helps, >>>> >>>> -- >>>> Ronan Amicel >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "pylons-discuss" group. >>> To view this discussion on the web visit https://groups.google.com/d/** >>> msg/pylons-discuss/-/**Zxo2qWgfAEMJ<https://groups.google.com/d/msg/pylons-discuss/-/Zxo2qWgfAEMJ> >>> . >>> >>> To post to this group, send email to pylons-...@googlegroups.**com. >>> To unsubscribe from this group, send email to pylons-discus...@** >>> googlegroups.com. >>> >>> For more options, visit this group at http://groups.google.com/** >>> group/pylons-discuss?hl=en<http://groups.google.com/group/pylons-discuss?hl=en> >>> . >>> >> >> -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/pylons-discuss/-/7sE6FBrIzuYJ. > > To post to this group, send email to pylons-discuss@googlegroups.com. > To unsubscribe from this group, send email to > pylons-discuss+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/pylons-discuss?hl=en. > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.