# CCS CS Lab Webcam JSON # # Douglas Thrift # # $Id$ import calendar from ccscslab.main.utils import timezone from ccscslab.webcam.models import Webcam from django.utils.dateformat import format try: import simplejson as json except ImportError: import json class WebcamJSONEncoder(json.JSONEncoder): def default(self, object): if isinstance(object, Webcam): return { 'number': object.number, '_updated': format(timezone(object.updated), 'Y-m-d H:i:s T'), 'updated': calendar.timegm(object.updated.utctimetuple()) } else: return super(WebcamJSONEncoder, self).default(object)