# CCS CS Lab Wall JSON # # Douglas Thrift # # $Id$ from ccscslab.main.utils import timezone from ccscslab.wall.models import Post from django.db.models.query import QuerySet try: import simplejson as json except ImportError: import json class LCDJSONEncoder(json.JSONEncoder): def default(self, object): if isinstance(object, QuerySet): return tuple(object) elif isinstance(object, Post): return { 'postid': object.id, 'name': object.person.name + ' (' + object.user_full_name() + ')', 'posted': timezone(object.posted).strftime('%Y-%m-%d %H:%M %Z'), 'post': object.post_text_minimized() } else: return super(LCDJSONEncoder, self).default(object)