--- a/mouchak/server.py +++ b/mouchak/server.py @@ -31,6 +31,7 @@ import os import json from werkzeug import secure_filename +from datetime import datetime PLUGIN_UPLOAD_FOLDER = os.path.join(os.path.dirname(os.path.abspath(__file__)) + '/static/user_plugins') @@ -51,6 +52,7 @@ db = dbClient[conf.DB] siteContent = db['content'] siteMenu = db['menu'] +lastUpdated = db['last_updated'] analytics_coll = db['analytics'] if siteMenu.find_one() == None: @@ -92,8 +94,11 @@ del(header['_id']) header['id'] = str(objId) + last_updated = lastUpdated.find_one() + last_updated_date = last_updated['last_updated'] + return {'content': content, 'menu': menu, 'footer': footer, 'header': - header} + header, 'last_updated': last_updated_date.isoformat()} def allowed_file(filename): @@ -259,7 +264,6 @@ def login(): error = None if flask.request.method == 'POST': - print flask.request.form if flask.request.form['username'] != conf.ADMIN_USERNAME: error = 'Invalid username' elif flask.request.form['password'] != conf.ADMIN_PASSWORD: @@ -357,11 +361,26 @@ if data['type'] == 'pageview': data['page'] = flask.request.form['page'] - print data analytics_coll.insert(data) total_hits = analytics_coll.find({'type': 'pageview'}).count() return flask.jsonify(total_hits=total_hits) + +@app.route('/updated-content', methods=['POST']) +def updateLastUpdated(): + if "logged_in" not in flask.session: + abort(403) + + response = flask.make_response() + last_updated = lastUpdated.find_one() + if last_updated == None: + lastUpdated.insert({'last_updated': datetime.utcnow()}) + else: + lastUpdated.update({'_id': last_updated['_id']}, + {'last_updated': datetime.utcnow()}) + + response.status_code = 200 + return response @app.route('/robots.txt') --- a/mouchak/static/js/editor.js +++ b/mouchak/static/js/editor.js @@ -12,7 +12,8 @@ 'click #menu-config': 'showMenu', 'click #footer-config': 'showFooterConfig', 'click #header-config': 'showHeaderConfig', - 'click #uploads': 'uploads' + 'click #uploads': 'uploads', + 'click #last-updated': 'updateLastUpdated' }, initialize: function() { _.bindAll.apply(_, [this].concat(_.functions(this))); @@ -108,6 +109,22 @@ event.preventDefault(); this.uploadview.render(); return false; + }, + // update the last updated time of the website + // adding for KHMDL, because they want a last updated in their footer + updateLastUpdated: function() { + $.ajax({ + url: M.lastUpdatedURL(), + type: 'POST', + data: {}, + success: function(data) { + console.log('last updated updated'); + }, + error: function(jqxhr, error, status_text) { + console.log('Unable to update last updated'); + console.log(error, status_text); + } + }); }, // validate the page list with menu order list validate: function() { --- a/mouchak/static/js/mouchak.js +++ b/mouchak/static/js/mouchak.js @@ -42,6 +42,10 @@ }, updatePageViewCounter: function(data) { this.$pageview_counter.html(data.total_hits); + }, + renderLastUpdated: function() { + var date = new Date(M.site_content.last_updated); + $('#last-updated').html(date.toString()); } }); @@ -211,6 +215,7 @@ M.appView = new AppView(); M.appView.render(); + M.appView.renderLastUpdated(); var app_router = new AppRouter(); Backbone.history.start(); --- a/mouchak/templates/editor.html +++ b/mouchak/templates/editor.html @@ -27,6 +27,7 @@ M.PageURL = function() { return "{{ url_for('insertPage') }}"; }; M.PluginUploadURL = function() { return "{{ url_for('uploadPlugin') }}"; }; M.UploadsURL = function() { return "{{ url_for('static', filename='uploads/') }}"; }; + M.lastUpdatedURL = function() { return "{{ url_for('updateLastUpdated') }}"; }; M.site_content = {{ content|tojson|safe }}; window.onload = function() { M.editor.init(); @@ -145,6 +146,9 @@

Footer

Navigation Menu

Uploads

+

+ Content updated +

Go to site