Commit d2a059f6b6f8eef3c76cabc085018b3fe9d116f3
- Diff rendering mode:
- inline
- side by side
mouchak/server.py
(25 / 0)
  | |||
47 | 47 | ||
48 | 48 | ||
49 | 49 | dbClient = pymongo.MongoClient() | |
50 | |||
50 | 51 | db = dbClient[conf.DB] | |
51 | 52 | siteContent = db['content'] | |
52 | 53 | siteMenu = db['menu'] | |
54 | analytics_coll = db['analytics'] | ||
55 | |||
53 | 56 | if siteMenu.find_one() == None: | |
54 | 57 | siteMenu.insert({'customMenu': False, 'menuOrder': [], 'html': ''}) | |
55 | 58 | ||
… | … | ||
340 | 340 | res = os.remove(filepath) | |
341 | 341 | print res | |
342 | 342 | return '200 OK' | |
343 | |||
344 | # KHMDL needs analytics. So adding analytics to their website. | ||
345 | @app.route('/analytics', methods=['GET', 'POST']) | ||
346 | def analytics(): | ||
347 | response = flask.make_response() | ||
348 | if flask.request.method == 'GET': | ||
349 | #TODO: gather analytics data from db and send back a HTML rendering it | ||
350 | pass | ||
351 | elif flask.request.method == 'POST': | ||
352 | if 'type' not in flask.request.form: | ||
353 | abort(400) | ||
354 | |||
355 | data = {} | ||
356 | data['type'] = flask.request.form['type'] | ||
357 | if data['type'] == 'pageview': | ||
358 | data['page'] = flask.request.form['page'] | ||
359 | |||
360 | print data | ||
361 | analytics_coll.insert(data) | ||
362 | total_hits = analytics_coll.find({'type': 'pageview'}).count() | ||
363 | |||
364 | return flask.jsonify(total_hits=total_hits) | ||
343 | 365 | ||
344 | 366 | ||
345 | 367 | @app.route('/robots.txt') |
mouchak/static/js/mouchak.js
(21 / 0)
  | |||
12 | 12 | }, | |
13 | 13 | initialize: function() { | |
14 | 14 | _.bindAll.apply(_, [this].concat(_.functions(this))); | |
15 | this.$pageview_counter = $('#pageview-counter'); | ||
15 | 16 | }, | |
16 | 17 | render: function() { | |
17 | 18 | var menu = new M.types.model.menu(M.site_content.menu); | |
… | … | ||
23 | 23 | updateBreadcrumbs: function(event) { | |
24 | 24 | //TODO: write code to use bootstrap's breadcrumbs to render a | |
25 | 25 | // navigational breadcrumb | |
26 | }, | ||
27 | recordPageView: function(page) { | ||
28 | var self = this; | ||
29 | $.ajax({ | ||
30 | url: M.AnalyticsURL(), | ||
31 | type: 'POST', | ||
32 | data: {'type': 'pageview', 'page': page}, | ||
33 | success: function(data) { | ||
34 | //console.log('recorded by server'); | ||
35 | self.updatePageViewCounter(data); | ||
36 | }, | ||
37 | error: function(jqxhr, error, status_text) { | ||
38 | console.log('Unable to post page view analytics'); | ||
39 | console.log(error, status_text); | ||
40 | } | ||
41 | }); | ||
42 | }, | ||
43 | updatePageViewCounter: function(data) { | ||
44 | this.$pageview_counter.html(data.total_hits); | ||
26 | 45 | } | |
27 | 46 | }); | |
28 | 47 | ||
… | … | ||
158 | 158 | } | |
159 | 159 | //console.log('navclicked'); | |
160 | 160 | M.appView.navView.trigger('navclicked'); | |
161 | M.appView.recordPageView(page); | ||
161 | 162 | }, | |
162 | 163 | render404: function() { | |
163 | 164 | $('.pageview').hide(); |
mouchak/templates/index.html
(1 / 0)
  | |||
22 | 22 | window.M = window.M || {}; | |
23 | 23 | M.MenuURL = function() { return "{{ url_for('insertMenu') }}"}; | |
24 | 24 | M.PageURL = function() { return "{{ url_for('insertPage') }}"; }; | |
25 | M.AnalyticsURL = function() { return "{{ url_for('analytics') }}"; }; | ||
25 | 26 | M.site_content = {{ content|tojson|safe }}; | |
26 | 27 | window.onload = function() { | |
27 | 28 | M.init(); |