From e5b7332d18cf37087373b334ebf65ab727dfa8cf Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Thu, 18 Jul 2013 19:13:26 +0100 Subject: [PATCH] Fixed wrong user on follow activity --- .gitignore | 1 + spa/api/v1/NotificationResource.py | 2 +- spa/management/commands/drop.py | 16 ++++++++++++---- spa/models/activity.py | 13 +++++++++++-- static/js/app/lib/realtimeController.js | 7 ++++--- .../notifications/notificationCollection.js | 11 ++++------- static/js/app/views/activity/activityListView.js | 10 ++++------ .../views/notifications/notificationsListView.js | 12 +++++------- 8 files changed, 42 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 322cb5d..16b287e 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .gitignore~ +.coverage tags .tags .tags_sorted_by_file diff --git a/spa/api/v1/NotificationResource.py b/spa/api/v1/NotificationResource.py index c4517ae..e6521fd 100644 --- a/spa/api/v1/NotificationResource.py +++ b/spa/api/v1/NotificationResource.py @@ -12,7 +12,7 @@ class NotificationResource(BackboneCompatibleResource): authentication = SessionAuthentication() authorization = DjangoAuthorization() always_return_data = True - excludes = ['accepted_date', 'id'] + excludes = ['accepted_date'] def authorized_read_list(self, object_list, bundle): return object_list.filter(to_user=bundle.request.user) diff --git a/spa/management/commands/drop.py b/spa/management/commands/drop.py index ee433ac..91798b3 100755 --- a/spa/management/commands/drop.py +++ b/spa/management/commands/drop.py @@ -7,14 +7,22 @@ class Command(NoArgsCommand): help = "Drop and re-create the database" def handle_noargs(self, **options): - self.pgsql_handle_noargs(options) + if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql_psycopg2': + self.pgsql_handle_noargs(**options) + else: + self.mysql_handle_noargs(**options) def pgsql_handle_noargs(self, **options): import psycopg2 - db = psycopg2.connect("dbname=%s user=%s password=%s" % (settings.DATABASES['default']['NAME'], settings.DATABASES['default']['USER'], settings.DATABASES['default']['PASSWORD'])) + + db = psycopg2.connect(database='postgres', #settings.DATABASES['default']['NAME'], + host=settings.DATABASES['default']['HOST'], + user=settings.DATABASES['default']['USER'], + password=settings.DATABASES['default']['PASSWORD']) cur = db.cursor() - cur.execute("drop database %s; create database %s;" % settings.DATABASES['default']['NAME'], settings.DATABASES['default']['NAME']) + cur.execute("drop database %s; create database %s;" % ( + settings.DATABASES['default']['NAME'], settings.DATABASES['default']['NAME'])) print "Dropped" @@ -31,6 +39,6 @@ class Command(NoArgsCommand): cursor = db.cursor() print "Dropping database %s" % settings.DATABASES['default']['NAME'] cursor.execute("drop database %s; create database %s;" % ( - settings.DATABASES['default']['NAME'], settings.DATABASES['default']['NAME'])) + settings.DATABASES['default']['NAME'], settings.DATABASES['default']['NAME'])) print "Dropped" diff --git a/spa/models/activity.py b/spa/models/activity.py index 194293b..e7be204 100755 --- a/spa/models/activity.py +++ b/spa/models/activity.py @@ -14,6 +14,7 @@ ACTIVITYTYPES = ( ('f', 'favourited'), ) + class ActivityThread(threading.Thread): def __init__(self, instance, **kwargs): self.instance = instance @@ -35,7 +36,9 @@ class Activity(_BaseModel): notification = Notification() notification.from_user = self.user notification.to_user = self.get_target_user() - notification.notification_text = "%s %s %s" % (self.user or "Anonymous", self.get_verb_past(), self.get_object_name()) + notification.notification_text = "%s %s %s" % ( + self.user.get_nice_name() or "Anonymous", self.get_verb_past(), self.get_object_name_for_notification()) + notification.notification_url = self.get_object_url() notification.verb = self.get_verb_past() notification.target = self.get_object_name() @@ -63,6 +66,9 @@ class Activity(_BaseModel): def get_object_singular(self): pass + def get_object_name_for_notification(self): + return self.get_object_name() + class ActivityFollow(Activity): to_user = models.ForeignKey('spa.UserProfile', related_name='follower_activity') @@ -71,7 +77,7 @@ class ActivityFollow(Activity): return self.to_user def get_object_name(self): - return self.user.get_nice_name() + return self.to_user.get_nice_name() def get_object_url(self): return self.user.get_profile_url() @@ -82,6 +88,9 @@ class ActivityFollow(Activity): def get_verb_past(self): return "followed" + def get_object_name_for_notification(self): + return "You" + class ActivityFavourite(Activity): mix = models.ForeignKey('spa.Mix', related_name='favourites') diff --git a/static/js/app/lib/realtimeController.js b/static/js/app/lib/realtimeController.js index a02991d..8e1ea12 100644 --- a/static/js/app/lib/realtimeController.js +++ b/static/js/app/lib/realtimeController.js @@ -1,20 +1,21 @@ -// Generated by CoffeeScript 1.6.2 +// Generated by CoffeeScript 1.3.3 (function() { + define(['vent', 'socket.io'], function(vent, SocketIO) { var RealtimeController; - RealtimeController = (function() { + function RealtimeController() {} RealtimeController.prototype.startSocketIO = function() { var _this = this; - console.log("RealtimeController: Socket IO starting"); this.socket = SocketIO.connect(com.podnoms.settings.REALTIME_HOST); this.socket.on("hello", function(data) { return console.log("RealtimeController: Connected " + data['message']); }); "@socket.on \"activity\", (data) =>\n console.log(\"RealtimeController: activity \" + data['message'])\n vent.trigger(\"model:activity:new\", data['message'])"; + return this.socket.on("notification", function(data) { console.log("RealtimeController: notification " + data['message']); return vent.trigger("model:notification:new", data['message']); diff --git a/static/js/app/models/notifications/notificationCollection.js b/static/js/app/models/notifications/notificationCollection.js index 0f6a331..4af688e 100644 --- a/static/js/app/models/notifications/notificationCollection.js +++ b/static/js/app/models/notifications/notificationCollection.js @@ -1,17 +1,16 @@ -// Generated by CoffeeScript 1.6.2 +// Generated by CoffeeScript 1.3.3 (function() { var __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; define(['backbone', 'vent', 'models/notifications/notificationItem', 'app.lib/backbone.dss.model.collection'], function(Backbone, vent, NotificationItem, DssCollection) { - var NotificationCollection, _ref; - + var NotificationCollection; NotificationCollection = (function(_super) { + __extends(NotificationCollection, _super); function NotificationCollection() { - _ref = NotificationCollection.__super__.constructor.apply(this, arguments); - return _ref; + return NotificationCollection.__super__.constructor.apply(this, arguments); } NotificationCollection.prototype.model = NotificationItem; @@ -22,10 +21,8 @@ NotificationCollection.prototype.initialize = function() { var _this = this; - return this.listenTo(vent, "model:notification:new", function(url) { var item; - console.log("NotificationCollection: notification:new"); item = new NotificationItem(); return item.fetch({ diff --git a/static/js/app/views/activity/activityListView.js b/static/js/app/views/activity/activityListView.js index 3fdba72..bea4740 100755 --- a/static/js/app/views/activity/activityListView.js +++ b/static/js/app/views/activity/activityListView.js @@ -1,17 +1,16 @@ -// Generated by CoffeeScript 1.6.2 +// Generated by CoffeeScript 1.3.3 (function() { var __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; define(['marionette', 'models/activity/activityCollection', 'views/activity/activityItemView', 'text!/tpl/ActivityListView'], function(Marionette, ActivityCollection, ActivityItemView, Template) { - var ActivityListView, _ref; - + var ActivityListView; ActivityListView = (function(_super) { + __extends(ActivityListView, _super); function ActivityListView() { - _ref = ActivityListView.__super__.constructor.apply(this, arguments); - return _ref; + return ActivityListView.__super__.constructor.apply(this, arguments); } ActivityListView.prototype.template = _.template(Template); @@ -31,7 +30,6 @@ ActivityListView.prototype.appendHtml = function(collectionView, itemView, index) { var children, childrenContainer; - childrenContainer = (collectionView.itemViewContainer ? collectionView.$(collectionView.itemViewContainer) : collectionView.$el); children = childrenContainer.children(); if (children.size() <= index) { diff --git a/static/js/app/views/notifications/notificationsListView.js b/static/js/app/views/notifications/notificationsListView.js index d204964..26422cb 100644 --- a/static/js/app/views/notifications/notificationsListView.js +++ b/static/js/app/views/notifications/notificationsListView.js @@ -1,18 +1,18 @@ -// Generated by CoffeeScript 1.6.2 +// Generated by CoffeeScript 1.3.3 (function() { var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; define(['marionette', 'underscore', 'vent', 'utils', 'models/notifications/notificationCollection', 'views/notifications/notificationsItemView', 'text!/tpl/NotificationsListView'], function(Marionette, _, vent, utils, NotificationCollection, NotificationsItemView, Template) { - var NotificationsListView, _ref; - + var NotificationsListView; NotificationsListView = (function(_super) { + __extends(NotificationsListView, _super); function NotificationsListView() { - this.initialize = __bind(this.initialize, this); _ref = NotificationsListView.__super__.constructor.apply(this, arguments); - return _ref; + this.initialize = __bind(this.initialize, this); + return NotificationsListView.__super__.constructor.apply(this, arguments); } NotificationsListView.prototype.template = _.template(Template); @@ -36,7 +36,6 @@ NotificationsListView.prototype.initialize = function() { var _this = this; - this.collection = new NotificationCollection; return this.collection.fetch({ success: function() { @@ -69,7 +68,6 @@ NotificationsListView.prototype.showNotifications = function() { var _this = this; - return $.ajax({ url: '/ajax/mark_read/', type: 'post',