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
  
9999 def getFrontendSwts():
100100 return Sweet.query.order_by(Sweet.created.desc()).all()
101101
102 # get sweets all sweets authored by a particular user
102 # get all sweets authored by a particular user
103103 @staticmethod
104104 def getByCreator(user):
105105 return Sweet.query.filter_by(who=user).\
125125 'context_id': self.context_id,
126126 'where': self.where,
127127 'how': self.how,
128 'created': self.created.isoformat()
128 #'created': self.created.isoformat()
129 'created': self.created.strftime('%a, %d %b %Y, %I:%M %p UTC'),
129130 }
130131
131132
  
6060 'id': self.id,
6161 'username': self.username,
6262 'email': self.email,
63 'created': self.created.isoformat(),
64 'last_active': self.last_active.isoformat()
63 #'created': self.created.isoformat(),
64 'created': self.created.strftime('%a, %d %b %Y, %I:%M %p UTC'),
65 #'last_active': self.last_active.isoformat()
66 'last_active': self.last_active.strftime('%a, %d %b %Y, %I:%M %p UTC')
6567 }
6668
6769 def __repr__(self):
  
55from flask import Module, jsonify, request, render_template, redirect,\
66 url_for, g, current_app
77
8from sqlalchemy import desc
9
108from swtstore.classes.models import Sweet, User
119
1210
1313@frontend.route('/', methods=['GET'])
1414def index():
1515 sweets = Sweet.getFrontendSwts()
16
17 user = User.getCurrentUser()
16 sweets = [sweet.to_dict() for sweet in sweets]
1817
1918 return render_template('frontend/index.html', sweets=sweets)
2019
  
2121 sweet = Sweet.query.get(id)
2222 if sweet:
2323 print "sweet found " + str(sweet)
24 return render_template('sweet/specific.html', sweet=sweet)
24 return render_template('sweet/specific.html', sweet=sweet.to_dict())
2525 else:
2626 abort(404)
  
8989 return redirect(url_for('frontend.index'))
9090
9191 if request.method == 'GET':
92 return render_template('user/me.html', user=current_user)
92 return render_template('user/me.html', user=current_user.to_dict())
9393
9494 # else POST request
9595 username = request.form.get('username')
110110 return redirect(url_for('frontend.index'))
111111
112112 swts = Sweet.getByCreator(user)
113 swts = [swt.to_dict() for swt in swts]
113114 return render_template('user/sweets.html', sweets=swts)
114115
115116
  
2323 font-size: 0.8em;
2424 text-align: center;
2525}
26.created {
27 font-size: 0.9em;
28 font-style: italic;
29}
  
66
77 {% if sweets|length > 0 %}
88
9 <ul class="entries unstyled">
9 <ul class="list-group">
1010 {% for sweet in sweets %}
11 <li>
11 <li class="list-group-item">
1212 <span class="who">
1313 <a href="#">
14 @{{ sweet.who.username }}
14 @{{ sweet.who }}
1515 </a>
1616 </span>
1717 <span class="what">
18 <b> #{{ sweet.what.name }} </b>
18 <b> #{{ sweet.what }} </b>
1919 </span>
2020 <span class="where">
2121 {{ sweet.where }}
2525 {{ sweet.how|escape|safe }}
2626 </span>
2727
28 <small><i>created: {{sweet.created }}</i></small>
28 <p></p>
29 <span class="created">created:
30 <span>{{ sweet.created }}</span>
31 </span>
2932
3033 <span class="pull-right permalink">
3134 <a href="{{ url_for('sweet.showSweet', id=sweet.id) }}">
  
22
33{% block body %}
44
5<ul class="entries unstyled">
6 <li>
5<ul class="list-group">
6 <li class="list-group-item">
77 <span class="who">
88 <a href="#">
9 @{{ sweet.who.username }}
9 @{{ sweet.who }}
1010 </a>
1111 </span>
1212 <span class="what">
13 <b> #{{ sweet.what.name }} </b>
13 <b> #{{ sweet.what }} </b>
1414 </span>
1515 <span class="where">
1616 {{ sweet.where }}
  
2626 </p>
2727 </div>
2828 </div>
29 <div class="form-group">
30 <label class="control-label">Last Active</label>
31 <div class="">
32 <p class="form-control-static" id="last-active">
33 {{ user.last_active }}
34 </p>
35 </div>
36 </div>
2937 <button type="submit" class="btn btn-primary">Update</button>
3038</form>
31
32{% endblock %}
33
34{% block scripts %}
35
36<script>
37 var created = new Date("{{ user.created }}");
38 window.onload = function() {
39 $('#user-created').html(created.toString());
40 };
41</script>
4239
4340{% endblock %}
  
44
55 {% if sweets|length > 0 %}
66
7 <ul class="entries unstyled">
7 <ul class="list-group">
88 {% for sweet in sweets %}
9 <li>
9 <li class="list-group-item">
1010 <span class="who">
1111 <a href="#">
12 @{{ sweet.who.username }}
12 @{{ sweet.who }}
1313 </a>
1414 </span>
1515 <span class="what">
16 <b> #{{ sweet.what.name }} </b>
16 <b> #{{ sweet.what }} </b>
1717 </span>
1818 <span class="where">
1919 {{ sweet.where }}