Browse Source

Improvements in Alerts API

Ralfp 12 years ago
parent
commit
faa7068270
2 changed files with 15 additions and 3 deletions
  1. 12 0
      misago/alerts/models.py
  2. 3 3
      misago/threads/views/posting.py

+ 12 - 0
misago/alerts/models.py

@@ -38,6 +38,18 @@ class Alert(models.Model):
             self.vars_raw = {var: url}
         return self
     
+    def user(self, var, user):
+        from django.core.urlresolvers import reverse
+        return self.url(var, user.username, reverse('user', kwargs={'user': user.pk, 'username': user.username_slug}))
+    
+    def thread(self, var, thread):
+        from django.core.urlresolvers import reverse
+        return self.url(var, thread.name, reverse('thread', kwargs={'thread': thread.pk, 'slug': thread.slug}))
+    
+    def post(self, var, thread, post):
+        from django.core.urlresolvers import reverse
+        return self.url(var, thread.name, reverse('thread_find', kwargs={'thread': thread.pk, 'slug': thread.slug, 'post': post.pk}))
+    
     def save_all(self, *args, **kwargs):
         self.save(force_insert=True)
         self.user.save(force_update=True)

+ 3 - 3
misago/threads/views/posting.py

@@ -133,9 +133,9 @@ class PostingView(BaseView):
                             thread.score += request.settings['thread_ranking_reply_score']
                         # Notify quoted poster of reply?
                         if self.quote and self.quote.user_id and self.quote.user_id != request.user.pk:
-                            alert = self.quote.user.alert(ugettext_lazy("%(username)s has replied to your post in thread %(thread)s.").message)
-                            alert.url('username', request.user.username, reverse('user', kwargs={'user': request.user.pk, 'username': request.user.username_slug}))
-                            alert.url('thread', self.thread.name, reverse('thread_find', kwargs={'thread': self.thread.pk, 'slug': self.thread.slug, 'post': post.pk}))
+                            alert = self.quote.user.alert(ugettext_lazy("%(username)s has replied to your post in thread %(thread)s").message)
+                            alert.user('username', request.user)
+                            alert.post('thread', self.thread, post)
                             alert.save_all()
                         if (self.request.settings.thread_length > 0
                             and not thread.closed