Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated datetime handling for posted start/end time. If dateuti.parse…

…r is available, use that; otherwise, assume RFC 2822 per the spec.
  • Loading branch information...
commit 333686419a3c3c90b9c7c8e6cbbd6f7b885cd087 1 parent 88ffa4f
Jacob Kaplan-Moss authored

Showing 2 changed files with 17 additions and 3 deletions. Show diff stats Hide diff stats

  1. +1 1  pony_server/handlers.py
  2. +16 2 pony_server/utils.py
2  pony_server/handlers.py
@@ -181,7 +181,7 @@ def create(self, request, slug):
181 181 host = request.data['client']['host'],
182 182 arch = request.data['client']['arch'],
183 183 user = request.user.is_authenticated() and request.user or None,
184   -
  184 +
185 185 # Because of some weirdness with the way fields are handled in
186 186 # __init__, we have to encode extra as JSON manually here.
187 187 # TODO: investiage why and fix JSONField
18 pony_server/utils.py
@@ -2,9 +2,11 @@
2 2 Piston API helpers.
3 3 """
4 4
  5 +import time
5 6 import datetime
6 7 import functools
7 8 import mimeparse
  9 +import email.utils
8 10 import piston.resource
9 11 import piston.emitters
10 12 import piston.handler
@@ -19,6 +21,13 @@
19 21 from django.utils import dateformat
20 22 from django.utils.http import urlencode
21 23
  24 +# Try to use dateutil for maximum date-parsing niceness. Fall back to
  25 +# hard-coded RFC2822 parsing if that's not possible.
  26 +try:
  27 + import dateutil.parser
  28 +except ImportError:
  29 + dateutil = None
  30 +
22 31 class Resource(piston.resource.Resource):
23 32 """Chooses an emitter based on mime types."""
24 33
@@ -169,5 +178,10 @@ def _view(self, request, *args, **kwargs):
169 178 def format_dt(dt):
170 179 return dateformat.format(dt, 'r')
171 180
172   -def mk_datetime(string):
173   - return datetime.datetime.strptime(string, '%Y-%m-%dT%H:%M:%S')
  181 +# Try to use dateutil for maximum date-parsing niceness. Fall back to
  182 +# hard-coded RFC2822 parsing if that's not possible.
  183 +if dateutil:
  184 + mk_datetime = dateutil.parser.parse
  185 +else:
  186 + def mk_datetime(string):
  187 + return datetime.datetime.fromtimestamp(time.mktime(email.utils.parsedate(string)))

0 comments on commit 3336864

Please sign in to comment.
Something went wrong with that request. Please try again.