Repository: dotkom/onlineweb4

Issue:
Datetime timezone stuff gives runtime warnings in server log
/home/vagrant/.virtualenvs/onlineweb/local/lib/python2.7/site-packages/django/db/models/fields/**init**.py:827: RuntimeWarning: DateTimeField received a naive datetime (2013-09-05 00:00:00) while time zone support is active.
  RuntimeWarning)

humdum.



Discussion:
This is because the API requires dates for event_end / event_start gte/lte filters in `YYYY-MM-DD` format. And dates are natively timezone naive (unaware), and does not support timezone stuff.

It might be possible to convert it to a tz-aware datetime and then get the different attributes from it,
or we have to rewrite the offset calculations for which year students are on, marks and stuff.

Edit: I see now that there might be a non-aware datetime lurking somewhere in the models, but this RuntimeWarning also pops up when you do api-calls with date filtering.

Did this fucker go away? :p

Nope, still lingers.. But maybe there is some setting in tastypie that converts to timezoneaware (utc) datetimes... The reasonable thing would be that tastypie used django settings to do this automatically.. But seems like it doesnt. It is the event_end__gte filter from the API that gives timezone naive datetimes to the model manager (or whatever it's called).

http://www.tryolabs.com/Blog/2013/03/16/displaying-timezone-aware-dates-tastypie/

Anything of use?

TASTYPIE_DATETIME_FORMATTING = 'rfc-2822'

:o

This will magically disappear when we change API


Resolving patch:
diff --git a/apps/companyprofile/utils.py b/apps/companyprofile/utils.py
--- a/apps/companyprofile/utils.py
+++ b/apps/companyprofile/utils.py
@@ -4,11 +4,9 @@
 def find_image_versions(company):
     img = company.old_image
     img_strings = []
-    print("gnna find sm imgs")
 
     for ver in VERSIONS.keys():
         if ver.startswith('companies_'):
-            print(ver)
             img_strings.append(img.version_generate(ver).url)
 
     return img_strings
diff --git a/apps/events/utils.py b/apps/events/utils.py
--- a/apps/events/utils.py
+++ b/apps/events/utils.py
@@ -53,7 +53,7 @@ def handle_waitlist_bump(event, host, attendees, payment=None):
             for attendee in attendees:
                 payment.create_payment_delay(attendee.user, extended_deadline)
             message += u"Dette arrangementet krever betaling og du må betale innen 48 timer."
-        
+
         elif payment.payment_type == 2: #Deadline
             if payment.deadline > extended_deadline: #More than 2 days left of payment deadline
                 message += u"Dette arrangementet krever betaling og fristen for og betale er %s" % (payment.deadline.strftime('%-d %B %Y kl: %H:%M'))
@@ -61,7 +61,7 @@ def handle_waitlist_bump(event, host, attendees, payment=None):
                 for attendee in attendees:
                     payment.create_payment_delay(attendee.user, extended_deadline)
                 message += u"Dette arrangementet krever betaling og du har 48 timer på å betale"
-        
+
         elif payment.payment_type == 3: #Delay
             deadline = timezone.now() + timedelta(days=payment.delay)
             for attendee in attendees:
@@ -177,11 +177,9 @@ def events(self):
 def find_image_versions(event):
     img = event.image
     img_strings = []
-    print("gnna find sm imgs")
 
     for ver in VERSIONS.keys():
         if ver.startswith('events_'):
-            print(ver)
             img_strings.append(img.version_generate(ver).url)
 
     return img_strings


Test patch: