From 48b777251353260ed7534b644df0e1a69b7a6f3e Mon Sep 17 00:00:00 2001
From: Anon Ray
Date: Tue, 3 Jun 2014 16:17:20 +0530
Subject: [PATCH] Add timestamp format at server-side; code consistency at
views
- Decided to moment.js but later. Until then, the to_dict method of sweet and
user returns formatted date in UTC.
- Making all sweet and user related views to use the to_dict method and be
consistent
---
swtstore/classes/models/sweet.py | 5 +++--
swtstore/classes/models/user.py | 6 ++++--
swtstore/classes/views/frontend.py | 5 +----
swtstore/classes/views/sweet.py | 2 +-
swtstore/classes/views/user.py | 3 ++-
swtstore/static/css/style.css | 4 ++++
swtstore/templates/frontend/index.html | 13 ++++++++-----
swtstore/templates/sweet/specific.html | 8 ++++----
swtstore/templates/user/me.html | 19 ++++++++-----------
swtstore/templates/user/sweets.html | 8 ++++----
10 files changed, 39 insertions(+), 34 deletions(-)
diff --git a/swtstore/classes/models/sweet.py b/swtstore/classes/models/sweet.py
index 59538e1..f4c13e5 100644
--- a/swtstore/classes/models/sweet.py
+++ b/swtstore/classes/models/sweet.py
@@ -99,7 +99,7 @@ class Sweet(db.Model):
def getFrontendSwts():
return Sweet.query.order_by(Sweet.created.desc()).all()
- # get sweets all sweets authored by a particular user
+ # get all sweets authored by a particular user
@staticmethod
def getByCreator(user):
return Sweet.query.filter_by(who=user).\
@@ -125,7 +125,8 @@ class Sweet(db.Model):
'context_id': self.context_id,
'where': self.where,
'how': self.how,
- 'created': self.created.isoformat()
+ #'created': self.created.isoformat()
+ 'created': self.created.strftime('%a, %d %b %Y, %I:%M %p UTC'),
}
diff --git a/swtstore/classes/models/user.py b/swtstore/classes/models/user.py
index f57e450..c0ee7d6 100644
--- a/swtstore/classes/models/user.py
+++ b/swtstore/classes/models/user.py
@@ -60,8 +60,10 @@ class User(db.Model):
'id': self.id,
'username': self.username,
'email': self.email,
- 'created': self.created.isoformat(),
- 'last_active': self.last_active.isoformat()
+ #'created': self.created.isoformat(),
+ 'created': self.created.strftime('%a, %d %b %Y, %I:%M %p UTC'),
+ #'last_active': self.last_active.isoformat()
+ 'last_active': self.last_active.strftime('%a, %d %b %Y, %I:%M %p UTC')
}
def __repr__(self):
diff --git a/swtstore/classes/views/frontend.py b/swtstore/classes/views/frontend.py
index 9dcaacd..1cd3581 100644
--- a/swtstore/classes/views/frontend.py
+++ b/swtstore/classes/views/frontend.py
@@ -5,8 +5,6 @@
from flask import Module, jsonify, request, render_template, redirect,\
url_for, g, current_app
-from sqlalchemy import desc
-
from swtstore.classes.models import Sweet, User
@@ -15,8 +13,7 @@ frontend = Module(__name__)
@frontend.route('/', methods=['GET'])
def index():
sweets = Sweet.getFrontendSwts()
-
- user = User.getCurrentUser()
+ sweets = [sweet.to_dict() for sweet in sweets]
return render_template('frontend/index.html', sweets=sweets)
diff --git a/swtstore/classes/views/sweet.py b/swtstore/classes/views/sweet.py
index 9e089a6..77c8616 100644
--- a/swtstore/classes/views/sweet.py
+++ b/swtstore/classes/views/sweet.py
@@ -21,7 +21,7 @@ def showSweet(id):
sweet = Sweet.query.get(id)
if sweet:
print "sweet found " + str(sweet)
- return render_template('sweet/specific.html', sweet=sweet)
+ return render_template('sweet/specific.html', sweet=sweet.to_dict())
else:
abort(404)
diff --git a/swtstore/classes/views/user.py b/swtstore/classes/views/user.py
index 81cb379..fa1b7d2 100644
--- a/swtstore/classes/views/user.py
+++ b/swtstore/classes/views/user.py
@@ -89,7 +89,7 @@ def profile():
return redirect(url_for('frontend.index'))
if request.method == 'GET':
- return render_template('user/me.html', user=current_user)
+ return render_template('user/me.html', user=current_user.to_dict())
# else POST request
username = request.form.get('username')
@@ -110,6 +110,7 @@ def mySweets():
return redirect(url_for('frontend.index'))
swts = Sweet.getByCreator(user)
+ swts = [swt.to_dict() for swt in swts]
return render_template('user/sweets.html', sweets=swts)
diff --git a/swtstore/static/css/style.css b/swtstore/static/css/style.css
index 836145a..8ff4bbd 100644
--- a/swtstore/static/css/style.css
+++ b/swtstore/static/css/style.css
@@ -23,3 +23,7 @@
font-size: 0.8em;
text-align: center;
}
+.created {
+ font-size: 0.9em;
+ font-style: italic;
+}
diff --git a/swtstore/templates/frontend/index.html b/swtstore/templates/frontend/index.html
index 04736a4..a4bd745 100644
--- a/swtstore/templates/frontend/index.html
+++ b/swtstore/templates/frontend/index.html
@@ -6,16 +6,16 @@
{% if sweets|length > 0 %}
-
+
{% endblock %}
-
-{% block scripts %}
-
-
-
-{% endblock %}
diff --git a/swtstore/templates/user/sweets.html b/swtstore/templates/user/sweets.html
index 130126b..55ddfc8 100644
--- a/swtstore/templates/user/sweets.html
+++ b/swtstore/templates/user/sweets.html
@@ -4,16 +4,16 @@
{% if sweets|length > 0 %}
-