Commit 48b777251353260ed7534b644df0e1a69b7a6f3e
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
| |   |
99 | 99 | def getFrontendSwts(): |
100 | 100 | return Sweet.query.order_by(Sweet.created.desc()).all() |
101 | 101 | |
# get sweets all sweets authored by a particular user |
# get all sweets authored by a particular user |
103 | 103 | @staticmethod |
104 | 104 | def getByCreator(user): |
105 | 105 | return Sweet.query.filter_by(who=user).\ |
… | … | |
125 | 125 | 'context_id': self.context_id, |
126 | 126 | 'where': self.where, |
127 | 127 | 'how': self.how, |
'created': self.created.isoformat() |
#'created': self.created.isoformat() |
'created': self.created.strftime('%a, %d %b %Y, %I:%M %p UTC'), |
129 | 130 | } |
130 | 131 | |
131 | 132 | |
| |   |
60 | 60 | 'id': self.id, |
61 | 61 | 'username': self.username, |
62 | 62 | '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') |
65 | 67 | } |
66 | 68 | |
67 | 69 | def __repr__(self): |
| |   |
5 | 5 | from flask import Module, jsonify, request, render_template, redirect,\ |
6 | 6 | url_for, g, current_app |
7 | 7 | |
from sqlalchemy import desc |
|
10 | 8 | from swtstore.classes.models import Sweet, User |
11 | 9 | |
12 | 10 | |
… | … | |
13 | 13 | @frontend.route('/', methods=['GET']) |
14 | 14 | def index(): |
15 | 15 | sweets = Sweet.getFrontendSwts() |
|
user = User.getCurrentUser() |
sweets = [sweet.to_dict() for sweet in sweets] |
18 | 17 | |
19 | 18 | return render_template('frontend/index.html', sweets=sweets) |
20 | 19 | |
| |   |
21 | 21 | sweet = Sweet.query.get(id) |
22 | 22 | if sweet: |
23 | 23 | print "sweet found " + str(sweet) |
return render_template('sweet/specific.html', sweet=sweet) |
return render_template('sweet/specific.html', sweet=sweet.to_dict()) |
25 | 25 | else: |
26 | 26 | abort(404) |
| |   |
89 | 89 | return redirect(url_for('frontend.index')) |
90 | 90 | |
91 | 91 | if request.method == 'GET': |
return render_template('user/me.html', user=current_user) |
return render_template('user/me.html', user=current_user.to_dict()) |
93 | 93 | |
94 | 94 | # else POST request |
95 | 95 | username = request.form.get('username') |
… | … | |
110 | 110 | return redirect(url_for('frontend.index')) |
111 | 111 | |
112 | 112 | swts = Sweet.getByCreator(user) |
swts = [swt.to_dict() for swt in swts] |
113 | 114 | return render_template('user/sweets.html', sweets=swts) |
114 | 115 | |
115 | 116 | |
| |   |
23 | 23 | font-size: 0.8em; |
24 | 24 | text-align: center; |
25 | 25 | } |
.created { |
font-size: 0.9em; |
font-style: italic; |
} |
| |   |
6 | 6 | |
7 | 7 | {% if sweets|length > 0 %} |
8 | 8 | |
<ul class="entries unstyled"> |
<ul class="list-group"> |
10 | 10 | {% for sweet in sweets %} |
<li> |
<li class="list-group-item"> |
12 | 12 | <span class="who"> |
13 | 13 | <a href="#"> |
@{{ sweet.who.username }} |
@{{ sweet.who }} |
15 | 15 | </a> |
16 | 16 | </span> |
17 | 17 | <span class="what"> |
<b> #{{ sweet.what.name }} </b> |
<b> #{{ sweet.what }} </b> |
19 | 19 | </span> |
20 | 20 | <span class="where"> |
21 | 21 | {{ sweet.where }} |
… | … | |
25 | 25 | {{ sweet.how|escape|safe }} |
26 | 26 | </span> |
27 | 27 | |
<small><i>created: {{sweet.created }}</i></small> |
<p></p> |
<span class="created">created: |
<span>{{ sweet.created }}</span> |
</span> |
29 | 32 | |
30 | 33 | <span class="pull-right permalink"> |
31 | 34 | <a href="{{ url_for('sweet.showSweet', id=sweet.id) }}"> |
| |   |
2 | 2 | |
3 | 3 | {% block body %} |
4 | 4 | |
<ul class="entries unstyled"> |
<li> |
<ul class="list-group"> |
<li class="list-group-item"> |
7 | 7 | <span class="who"> |
8 | 8 | <a href="#"> |
@{{ sweet.who.username }} |
@{{ sweet.who }} |
10 | 10 | </a> |
11 | 11 | </span> |
12 | 12 | <span class="what"> |
<b> #{{ sweet.what.name }} </b> |
<b> #{{ sweet.what }} </b> |
14 | 14 | </span> |
15 | 15 | <span class="where"> |
16 | 16 | {{ sweet.where }} |
| |   |
26 | 26 | </p> |
27 | 27 | </div> |
28 | 28 | </div> |
<div class="form-group"> |
<label class="control-label">Last Active</label> |
<div class=""> |
<p class="form-control-static" id="last-active"> |
{{ user.last_active }} |
</p> |
</div> |
</div> |
29 | 37 | <button type="submit" class="btn btn-primary">Update</button> |
30 | 38 | </form> |
|
{% endblock %} |
|
{% block scripts %} |
|
<script> |
var created = new Date("{{ user.created }}"); |
window.onload = function() { |
$('#user-created').html(created.toString()); |
}; |
</script> |
42 | 39 | |
43 | 40 | {% endblock %} |
| |   |
4 | 4 | |
5 | 5 | {% if sweets|length > 0 %} |
6 | 6 | |
<ul class="entries unstyled"> |
<ul class="list-group"> |
8 | 8 | {% for sweet in sweets %} |
<li> |
<li class="list-group-item"> |
10 | 10 | <span class="who"> |
11 | 11 | <a href="#"> |
@{{ sweet.who.username }} |
@{{ sweet.who }} |
13 | 13 | </a> |
14 | 14 | </span> |
15 | 15 | <span class="what"> |
<b> #{{ sweet.what.name }} </b> |
<b> #{{ sweet.what }} </b> |
17 | 17 | </span> |
18 | 18 | <span class="where"> |
19 | 19 | {{ sweet.where }} |