Commit c09252876af8c6fb450c80994079d48454280acf

Add Last Updated functionality for KHMDL
  
3131import os
3232import json
3333from werkzeug import secure_filename
34from datetime import datetime
3435
3536PLUGIN_UPLOAD_FOLDER = os.path.join(os.path.dirname(os.path.abspath(__file__))
3637 + '/static/user_plugins')
5252db = dbClient[conf.DB]
5353siteContent = db['content']
5454siteMenu = db['menu']
55lastUpdated = db['last_updated']
5556analytics_coll = db['analytics']
5657
5758if siteMenu.find_one() == None:
9494 del(header['_id'])
9595 header['id'] = str(objId)
9696
97 last_updated = lastUpdated.find_one()
98 last_updated_date = last_updated['last_updated']
99
97100 return {'content': content, 'menu': menu, 'footer': footer, 'header':
98 header}
101 header, 'last_updated': last_updated_date.isoformat()}
99102
100103
101104def allowed_file(filename):
264264def login():
265265 error = None
266266 if flask.request.method == 'POST':
267 print flask.request.form
268267 if flask.request.form['username'] != conf.ADMIN_USERNAME:
269268 error = 'Invalid username'
270269 elif flask.request.form['password'] != conf.ADMIN_PASSWORD:
361361 if data['type'] == 'pageview':
362362 data['page'] = flask.request.form['page']
363363
364 print data
365364 analytics_coll.insert(data)
366365 total_hits = analytics_coll.find({'type': 'pageview'}).count()
367366
368367 return flask.jsonify(total_hits=total_hits)
368
369@app.route('/updated-content', methods=['POST'])
370def updateLastUpdated():
371 if "logged_in" not in flask.session:
372 abort(403)
373
374 response = flask.make_response()
375 last_updated = lastUpdated.find_one()
376 if last_updated == None:
377 lastUpdated.insert({'last_updated': datetime.utcnow()})
378 else:
379 lastUpdated.update({'_id': last_updated['_id']},
380 {'last_updated': datetime.utcnow()})
381
382 response.status_code = 200
383 return response
369384
370385
371386@app.route('/robots.txt')
  
1212 'click #menu-config': 'showMenu',
1313 'click #footer-config': 'showFooterConfig',
1414 'click #header-config': 'showHeaderConfig',
15 'click #uploads': 'uploads'
15 'click #uploads': 'uploads',
16 'click #last-updated': 'updateLastUpdated'
1617 },
1718 initialize: function() {
1819 _.bindAll.apply(_, [this].concat(_.functions(this)));
109109 event.preventDefault();
110110 this.uploadview.render();
111111 return false;
112 },
113 // update the last updated time of the website
114 // adding for KHMDL, because they want a last updated in their footer
115 updateLastUpdated: function() {
116 $.ajax({
117 url: M.lastUpdatedURL(),
118 type: 'POST',
119 data: {},
120 success: function(data) {
121 console.log('last updated updated');
122 },
123 error: function(jqxhr, error, status_text) {
124 console.log('Unable to update last updated');
125 console.log(error, status_text);
126 }
127 });
112128 },
113129 // validate the page list with menu order list
114130 validate: function() {
  
4242 },
4343 updatePageViewCounter: function(data) {
4444 this.$pageview_counter.html(data.total_hits);
45 },
46 renderLastUpdated: function() {
47 var date = new Date(M.site_content.last_updated);
48 $('#last-updated').html(date.toString());
4549 }
4650});
4751
215215
216216 M.appView = new AppView();
217217 M.appView.render();
218 M.appView.renderLastUpdated();
218219
219220 var app_router = new AppRouter();
220221 Backbone.history.start();
  
2727 M.PageURL = function() { return "{{ url_for('insertPage') }}"; };
2828 M.PluginUploadURL = function() { return "{{ url_for('uploadPlugin') }}"; };
2929 M.UploadsURL = function() { return "{{ url_for('static', filename='uploads/') }}"; };
30 M.lastUpdatedURL = function() { return "{{ url_for('updateLastUpdated') }}"; };
3031 M.site_content = {{ content|tojson|safe }};
3132 window.onload = function() {
3233 M.editor.init();
146146 <p> <a href="#" id="footer-config"> Footer </a> </p>
147147 <p> <a href="#" id="menu-config"> Navigation Menu </a> </p>
148148 <p> <a href="#" id="uploads"> Uploads </a> </p>
149 <p> <a href="#" class="btn btn-default" id="last-updated">
150 Content updated
151 </a> </p>
149152 <p><a href="{{ url_for('index') }}"> Go to site </a></p>
150153 </div>
151154 </script>