Changeset 2520
- Timestamp:
- 02/02/10 12:15:28 (6 weeks ago)
- Files:
-
- 1 modified
-
PyLucidPlugins/weave/views.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
PyLucidPlugins/weave/views.py
r2519 r2520 2 2 3 3 import time 4 import datetime 5 import traceback 4 6 5 7 try: … … 28 30 # influence the "newer" and "older" modifiers 29 31 return round(time.time(), 2) 32 33 34 def _datetime2epochtime(dt): 35 assert isinstance(dt, datetime.datetime) 36 timestamp = time.mktime(dt.timetuple()) # datetime -> time since the epoch 37 # Add microseconds. FIXME: Is there a easier way? 38 timestamp += (dt.microsecond / 1000000.0) 39 return round(timestamp, 2) 40 30 41 31 42 def _debug_request(request): … … 76 87 raise AssertionError(msg) 77 88 78 data_string = json.dumps(data, sort_keys=True) 79 response = http.HttpResponse(data_string, content_type='application/json') 89 try: 90 data_string = json.dumps(data, sort_keys=True) 91 except Exception, err: 92 print traceback.format_exc() 93 raise 94 95 response = http.HttpResponse(data_string, 96 # content_type='application/json' 97 content_type='text/plain' 98 ) 80 99 response["X-Weave-Timestamp"] = _timestamp() 81 100 … … 100 119 101 120 return "weave plugin, use this url: %s" % request.build_absolute_uri() 121 102 122 103 123 … … 130 150 for wbo in wbos: 131 151 lastupdatetime = wbo["lastupdatetime"] 132 # FIXME: Milliseconds 133 timestamp = time.mktime(lastupdatetime.timetuple()) # datetime -> time since the epoch 152 timestamp = _datetime2epochtime(lastupdatetime) # datetime -> time since the epoch 134 153 timestamps[wbo["wboid"]] = str(timestamp) 135 154 … … 195 214 196 215 # The server will return the timestamp associated with the modification. 197 data = {wboid: wbo.lastupdatetime}216 data = {wboid: _datetime2epochtime(wbo.lastupdatetime)} 198 217 return data 199 218 elif request.method == 'GET': 200 219 # Returns a list of the WBO ids contained in a collection. 201 collection = Collection.on_site.get(user=user, name=col_name) 220 try: 221 collection = Collection.on_site.get(user=user, name=col_name) 222 except Collection.DoesNotExist: 223 raise http.Http404 224 202 225 wbos = Wbo.objects.all().filter(collection=collection) 203 226 print "+++", wbos … … 205 228 for wbo in wbos: 206 229 lastupdatetime = wbo.lastupdatetime 207 # FIXME: Milliseconds 208 timestamp = time.mktime(lastupdatetime.timetuple()) # datetime -> time since the epoch 230 timestamp = _datetime2epochtime(lastupdatetime) # datetime -> time since the epoch 209 231 timestamps[wbo.wboid] = str(timestamp) 210 232