Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add client-side activity tracking. #637. #638.

  • Loading branch information...
commit 4dd0d7ebd5c3fd49553716a14a1d1591b607719e 1 parent 69b54cd
@onyxfish onyxfish authored
View
15 client/static/js/models/activity_log.js
@@ -0,0 +1,15 @@
+PANDA.models.ActivityLog = Backbone.Model.extend({
+ /*
+ Equivalent of panda.models.ActivityLog.
+ */
+ urlRoot: PANDA.API + "/activity_log"
+});
+
+PANDA.collections.ActivityLogs = Backbone.Collection.extend({
+ /*
+ A collection of panda.models.ActivityLog equivalents.
+ */
+ model: PANDA.models.ActivityLog,
+ urlRoot: PANDA.API + "/activity_log"
+});
+
View
23 client/static/js/views/root.js
@@ -84,8 +84,8 @@ PANDA.views.Root = Backbone.View.extend({
}));
// Fetch latest notifications (doubles as a verification of the user's credentials)
- this.refresh_notifications();
-
+ this.refresh_notifications();
+
return true;
}
@@ -185,6 +185,24 @@ PANDA.views.Root = Backbone.View.extend({
return dfd;
},
+ log_user_activity: function() {
+ /*
+ * Record that the user was on-site.
+ */
+ if (!this._current_user) {
+ return;
+ }
+
+ var activity_recorded = $.cookie("activity_recorded") === "true" ? true : false;
+
+ if (!activity_recorded) {
+ activity_log = new PANDA.models.ActivityLog();
+ activity_log.save();
+
+ $.cookie("activity_recorded", "true", { expires: 1 });
+ }
+ },
+
configure_navbar: function(no_scroll) {
/*
* Reconfigures the Bootstrap navbar based on the current user.
@@ -259,6 +277,7 @@ PANDA.views.Root = Backbone.View.extend({
if (this._current_user) {
this._current_user.refresh_notifications(_.bind(function() {
this.configure_navbar();
+ this.log_user_activity();
}, this));
}
},
View
1  client/templates/index.html
@@ -80,6 +80,7 @@
<script type="text/javascript" src="templates.js"></script>
{% compress js %}
+ <script type="text/javascript" src="{{ settings.STATIC_URL }}js/models/activity_log.js"></script>
<script type="text/javascript" src="{{ settings.STATIC_URL }}js/models/notifications.js"></script>
<script type="text/javascript" src="{{ settings.STATIC_URL }}js/models/users.js"></script>
<script type="text/javascript" src="{{ settings.STATIC_URL }}js/models/data_uploads.js"></script>
View
8 panda/api/activity_log.py
@@ -23,3 +23,11 @@ class Meta:
authorization = DjangoAuthorization()
serializer = PandaSerializer()
+ def obj_create(self, bundle, request=None, **kwargs):
+ """
+ Create an activity log for the accessing user.
+ """
+ bundle = super(ActivityLogResource, self).obj_create(bundle, request=request, user=request.user, **kwargs)
+
+ return bundle
+
View
5 panda/fixtures/init_panda.json
@@ -61,6 +61,11 @@
"delete_relatedupload",
"panda",
"relatedupload"
+ ],
+ [
+ "add_activitylog",
+ "panda",
+ "activitylog"
]
]
}
View
2  panda/models/activity_log.py
@@ -24,7 +24,7 @@ class Meta:
verbose_name_plural = 'ActivityLogs'
def __unicode__(self):
- return '%s was %s at %s' % (self.user, self.activity, self.when)
+ return '%s at %s' % (self.user, self.when)
def save(self, *args, **kwargs):
if not self.when:
Please sign in to comment.
Something went wrong with that request. Please try again.