From 01298ebadb7ba8c43f2374f0e823139f2534a276 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Thu, 6 Jun 2013 16:56:05 +0530 Subject: [PATCH] Fixed password change not allowed for non Privilaged users. Fixed storing utc dates in message tables. Created utc class for time-aware dates. Updated home to show age of Threads and open in new window available. Modified message detail template to show editable by privileged user. Added subscribers to thread detail. Improved markup for message-detail to use less space. Improved the chosen directive for when there is no create option. Added method 'Names' to user resource for use in message subscribers. Payment and Receipt clear typeahead on adding ledgers. TODO: Implement thread read status per user. TODO: Implemented edit post functionality for privileged user. TODO: Implement thread filtering on main page for subscribers Signed-off-by: Tanshu --- brewman/brewman/models/auth.py | 4 + brewman/brewman/models/messaging.py | 6 +- brewman/brewman/models/tzinfoutc.py | 35 +++ brewman/brewman/static/offline.appcache | 2 +- brewman/brewman/static/partial/home.html | 15 +- .../static/partial/message-detail.html | 26 ++- .../static/scripts/angular_directive.js | 19 +- .../brewman/static/scripts/angular_service.js | 3 +- brewman/brewman/static/scripts/journal.js | 1 - brewman/brewman/static/scripts/message.js | 17 +- brewman/brewman/static/scripts/payment.js | 2 +- brewman/brewman/static/scripts/receipt.js | 1 + brewman/brewman/views/auth/user.py | 206 +++++++++++------- brewman/brewman/views/messaging.py | 59 +++-- 14 files changed, 268 insertions(+), 128 deletions(-) create mode 100644 brewman/brewman/models/tzinfoutc.py diff --git a/brewman/brewman/models/auth.py b/brewman/brewman/models/auth.py index b625816e..97e37958 100644 --- a/brewman/brewman/models/auth.py +++ b/brewman/brewman/models/auth.py @@ -130,6 +130,10 @@ class User(Base): def list(cls): return DBSession.query(cls).order_by(cls.name).all() + @classmethod + def query(cls): + return DBSession.query(cls) + @classmethod def filtered_list(cls, name): query = DBSession.query(cls) diff --git a/brewman/brewman/models/messaging.py b/brewman/brewman/models/messaging.py index 7285c4fe..7e08d012 100644 --- a/brewman/brewman/models/messaging.py +++ b/brewman/brewman/models/messaging.py @@ -63,7 +63,7 @@ class Thread(Base): def __init__(self, title=None, creation_date=None, user_id=None, priority=5, public=False, closed=False): self.title = title - self.creation_date = datetime.now() if creation_date is None else creation_date + self.creation_date = datetime.utcnow() if creation_date is None else creation_date self.user_id = user_id self.priority = priority self.public = public @@ -96,7 +96,7 @@ class Post(Base): def __init__(self, content='', creation_date=None, user_id=None, date=None): self.content = content - self.creation_date = datetime.now() if creation_date is None else creation_date + self.creation_date = datetime.utcnow() if creation_date is None else creation_date self.user_id = user_id self.date = self.creation_date if date is None else date @@ -123,7 +123,7 @@ class Subscriber(Base): user = relationship('User', primaryjoin="User.id==Subscriber.user_id", cascade=None) - def __init__(self, thread_id=None, user_id=None, read=None): + def __init__(self, thread_id=None, user_id=None, read=False): self.thread_id = thread_id self.user_id = user_id self.read = read \ No newline at end of file diff --git a/brewman/brewman/models/tzinfoutc.py b/brewman/brewman/models/tzinfoutc.py new file mode 100644 index 00000000..78085421 --- /dev/null +++ b/brewman/brewman/models/tzinfoutc.py @@ -0,0 +1,35 @@ +from datetime import timedelta, tzinfo, datetime + +__author__ = 'tanshu' + + +ZERO = timedelta(0) +HOUR = timedelta(hours=1) + +# A UTC class. + +class UTC(tzinfo): + """UTC""" + + def utcoffset(self, dt): + return ZERO + + def tzname(self, dt): + return "UTC" + + def dst(self, dt): + return ZERO + +utc = UTC() + + +def get_age(old_date): + now = datetime.utcnow().replace(tzinfo=utc) + delta = now - old_date + if delta.days > 0: + return '{0} days'.format(delta.days) + if delta.seconds > 3600: + return '{0} hours'.format(delta.seconds // 3600) + if delta.seconds > 60: + return '{0} minutes'.format(delta.seconds // 3600) + return '{0} seconds'.format(delta.seconds) diff --git a/brewman/brewman/static/offline.appcache b/brewman/brewman/static/offline.appcache index 6e069717..b3de24ea 100644 --- a/brewman/brewman/static/offline.appcache +++ b/brewman/brewman/static/offline.appcache @@ -1,6 +1,6 @@ CACHE MANIFEST -# version 2013-05-30.1 +# version 2013-06-06.1 CACHE: /partial/404.html diff --git a/brewman/brewman/static/partial/home.html b/brewman/brewman/static/partial/home.html index 32b7ba5b..6647a80a 100644 --- a/brewman/brewman/static/partial/home.html +++ b/brewman/brewman/static/partial/home.html @@ -18,17 +18,28 @@
+ + + + + + +
+ + +
Details
+
- + -

{{item.Title}}

+

{{item.Title}}

{{tag}}
diff --git a/brewman/brewman/static/partial/message-detail.html b/brewman/brewman/static/partial/message-detail.html index 2d6b1f21..a366c673 100644 --- a/brewman/brewman/static/partial/message-detail.html +++ b/brewman/brewman/static/partial/message-detail.html @@ -4,7 +4,8 @@
- +
@@ -32,13 +33,30 @@
+
+ + +
+ +
+