Matthew Schinckel avatar Matthew Schinckel committed b49897b

Order Messages by send_date.
Add local_send_time property that looks for a timezone field on billee.

Comments (0)

Files changed (1)

sms/models/message.py

 from django.db import models
 from django.contrib.contenttypes import generic
 from django.utils.translation import ugettext as _
+from django.conf import settings
 
 import uuidfield.fields
 import picklefield
+if 'timezones' in settings.INSTALLED_APPS:
+    from timezones.utils import adjust_datetime_to_timezone
+else:
+    def adjust_datetime_to_timezone(a,b,c):
+        return a
 
 from gateway import Gateway
 
         permissions = (
             ('view_message', 'Can view message'),
         )
+        ordering = ('send_date',)
     
     def send(self, gateway):
         gateway.send(self)
     def length(self):
         return len(self.content) / 160 + 1
     
+    @property
+    def local_send_time(self):
+        if self.billee.timezone:
+            return adjust_datetime_to_timezone(
+                self.send_date, 
+                settings.TIME_ZONE, 
+                self.billee.timezone
+            )
+        return self.send_date
+            
     def __unicode__(self):
         return "[%s] Sent to %s by %s at %s [%i]" % (
             self.status,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.