Commit c09252876af8c6fb450c80994079d48454280acf
- Diff rendering mode:
- inline
- side by side
mouchak/server.py
(22 / 3)
  | |||
31 | 31 | import os | |
32 | 32 | import json | |
33 | 33 | from werkzeug import secure_filename | |
34 | from datetime import datetime | ||
34 | 35 | ||
35 | 36 | PLUGIN_UPLOAD_FOLDER = os.path.join(os.path.dirname(os.path.abspath(__file__)) | |
36 | 37 | + '/static/user_plugins') | |
… | … | ||
52 | 52 | db = dbClient[conf.DB] | |
53 | 53 | siteContent = db['content'] | |
54 | 54 | siteMenu = db['menu'] | |
55 | lastUpdated = db['last_updated'] | ||
55 | 56 | analytics_coll = db['analytics'] | |
56 | 57 | ||
57 | 58 | if siteMenu.find_one() == None: | |
… | … | ||
94 | 94 | del(header['_id']) | |
95 | 95 | header['id'] = str(objId) | |
96 | 96 | ||
97 | last_updated = lastUpdated.find_one() | ||
98 | last_updated_date = last_updated['last_updated'] | ||
99 | |||
97 | 100 | return {'content': content, 'menu': menu, 'footer': footer, 'header': | |
98 | header} | ||
101 | header, 'last_updated': last_updated_date.isoformat()} | ||
99 | 102 | ||
100 | 103 | ||
101 | 104 | def allowed_file(filename): | |
… | … | ||
264 | 264 | def login(): | |
265 | 265 | error = None | |
266 | 266 | if flask.request.method == 'POST': | |
267 | print flask.request.form | ||
268 | 267 | if flask.request.form['username'] != conf.ADMIN_USERNAME: | |
269 | 268 | error = 'Invalid username' | |
270 | 269 | elif flask.request.form['password'] != conf.ADMIN_PASSWORD: | |
… | … | ||
361 | 361 | if data['type'] == 'pageview': | |
362 | 362 | data['page'] = flask.request.form['page'] | |
363 | 363 | ||
364 | print data | ||
365 | 364 | analytics_coll.insert(data) | |
366 | 365 | total_hits = analytics_coll.find({'type': 'pageview'}).count() | |
367 | 366 | ||
368 | 367 | return flask.jsonify(total_hits=total_hits) | |
368 | |||
369 | @app.route('/updated-content', methods=['POST']) | ||
370 | def 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 | ||
369 | 384 | ||
370 | 385 | ||
371 | 386 | @app.route('/robots.txt') |
mouchak/static/js/editor.js
(18 / 1)
  | |||
12 | 12 | 'click #menu-config': 'showMenu', | |
13 | 13 | 'click #footer-config': 'showFooterConfig', | |
14 | 14 | 'click #header-config': 'showHeaderConfig', | |
15 | 'click #uploads': 'uploads' | ||
15 | 'click #uploads': 'uploads', | ||
16 | 'click #last-updated': 'updateLastUpdated' | ||
16 | 17 | }, | |
17 | 18 | initialize: function() { | |
18 | 19 | _.bindAll.apply(_, [this].concat(_.functions(this))); | |
… | … | ||
109 | 109 | event.preventDefault(); | |
110 | 110 | this.uploadview.render(); | |
111 | 111 | 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 | }); | ||
112 | 128 | }, | |
113 | 129 | // validate the page list with menu order list | |
114 | 130 | validate: function() { |
mouchak/static/js/mouchak.js
(5 / 0)
  | |||
42 | 42 | }, | |
43 | 43 | updatePageViewCounter: function(data) { | |
44 | 44 | 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()); | ||
45 | 49 | } | |
46 | 50 | }); | |
47 | 51 | ||
… | … | ||
215 | 215 | ||
216 | 216 | M.appView = new AppView(); | |
217 | 217 | M.appView.render(); | |
218 | M.appView.renderLastUpdated(); | ||
218 | 219 | ||
219 | 220 | var app_router = new AppRouter(); | |
220 | 221 | Backbone.history.start(); |
  | |||
27 | 27 | M.PageURL = function() { return "{{ url_for('insertPage') }}"; }; | |
28 | 28 | M.PluginUploadURL = function() { return "{{ url_for('uploadPlugin') }}"; }; | |
29 | 29 | M.UploadsURL = function() { return "{{ url_for('static', filename='uploads/') }}"; }; | |
30 | M.lastUpdatedURL = function() { return "{{ url_for('updateLastUpdated') }}"; }; | ||
30 | 31 | M.site_content = {{ content|tojson|safe }}; | |
31 | 32 | window.onload = function() { | |
32 | 33 | M.editor.init(); | |
… | … | ||
146 | 146 | <p> <a href="#" id="footer-config"> Footer </a> </p> | |
147 | 147 | <p> <a href="#" id="menu-config"> Navigation Menu </a> </p> | |
148 | 148 | <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> | ||
149 | 152 | <p><a href="{{ url_for('index') }}"> Go to site </a></p> | |
150 | 153 | </div> | |
151 | 154 | </script> |