From c09252876af8c6fb450c80994079d48454280acf Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Thu, 27 Feb 2014 18:05:40 +0530 Subject: [PATCH] Add Last Updated functionality for KHMDL --- mouchak/server.py | 25 ++++++++++++++++++++++--- mouchak/static/js/editor.js | 19 ++++++++++++++++++- mouchak/static/js/mouchak.js | 5 +++++ mouchak/templates/editor.html | 4 ++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/mouchak/server.py b/mouchak/server.py index f74b4bc..d077766 100644 --- a/mouchak/server.py +++ b/mouchak/server.py @@ -31,6 +31,7 @@ import conf 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 @@ dbClient = pymongo.MongoClient() 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 @@ def getContent(): 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 updateMenu(_id): 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,12 +361,27 @@ def analytics(): 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') @app.route('/crossdomain.xml') diff --git a/mouchak/static/js/editor.js b/mouchak/static/js/editor.js index 8649a23..c3ef74b 100644 --- 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))); @@ -109,6 +110,22 @@ 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() { //TODO: validate if the menu order list matches with the list of pages diff --git a/mouchak/static/js/mouchak.js b/mouchak/static/js/mouchak.js index 2f91fa9..d334e7c 100644 --- a/mouchak/static/js/mouchak.js +++ b/mouchak/static/js/mouchak.js @@ -42,6 +42,10 @@ var AppView = Backbone.View.extend({ }, 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.init = function() { M.appView = new AppView(); M.appView.render(); + M.appView.renderLastUpdated(); var app_router = new AppRouter(); Backbone.history.start(); diff --git a/mouchak/templates/editor.html b/mouchak/templates/editor.html index b2b2bfc..941b5ab 100644 --- 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

-- 1.7.10.4