~ubuntu-branches/ubuntu/utopic/python-django-threadedcomments/utopic

« back to all changes in this revision

Viewing changes to threadedcomments/utils.py

  • Committer: Package Import Robot
  • Author(s): Bernhard Reiter, Bernhard Reiter, Jakub Wilk
  • Date: 2013-08-09 19:12:14 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130809191214-p8482p4e1ctekffq
Tags: 0.9.0-1
[ Bernhard Reiter ]
* New upstream release
* debian/compat: Bump to 9.
* debian/control, debian/copyright: Update upstream links. (Closes: #713930)
* debian/control: 
  - Remove python-textile, python-markdown, python-docutils from
    Build-Depends: and Suggests:
  - Bump debhelper Build-Depends to >= 9.
  - Bump Standards-Version to 3.9.4.
  - Add Suggests: python-django-south
* debian/copyright: s/BSD-new/BSD-3-clause/
* debian/docs, debian/doc-base: Update/remove to correspond with
  upstream sources.
* debian/patches/series, debian/patches/add_markup_deps_to_install,
  debian/patches/gravatar_default_url, debian/patches/django14:
  Remove patches, as obsolete.
* debian/rules: Add a SECRET_KEY for tests during building. (Closes: #711369)
* debian/NEWS.Debian: Add.

[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from django.core.serializers import serialize
2
 
from django.http import HttpResponse
3
 
from django.utils import simplejson
4
 
from django.utils.functional import Promise
5
 
from django.utils.encoding import force_unicode 
6
 
 
7
 
class LazyEncoder(simplejson.JSONEncoder):
8
 
    def default(self, obj):
9
 
        if isinstance(obj, Promise):
10
 
            return force_unicode(obj)
11
 
        return obj
12
 
 
13
 
class JSONResponse(HttpResponse):
14
 
    """
15
 
    A simple subclass of ``HttpResponse`` which makes serializing to JSON easy.
16
 
    """
17
 
    def __init__(self, object, is_iterable = True):
18
 
        if is_iterable:
19
 
            content = serialize('json', object)
20
 
        else:
21
 
            content = simplejson.dumps(object, cls=LazyEncoder)
22
 
        super(JSONResponse, self).__init__(content, mimetype='application/json')
23
 
 
24
 
class XMLResponse(HttpResponse):
25
 
    """
26
 
    A simple subclass of ``HttpResponse`` which makes serializing to XML easy.
27
 
    """
28
 
    def __init__(self, object, is_iterable = True):
29
 
        if is_iterable:
30
 
            content = serialize('xml', object)
31
 
        else:
32
 
            content = object
33
 
        super(XMLResponse, self).__init__(content, mimetype='application/xml')
 
 
b'\\ No newline at end of file'