Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed observer code

  • Loading branch information...
commit 7781513d225bca7fd51fb89d7a2ae264bedb7052 1 parent 09fbf58
@brosner brosner authored
Showing with 1 addition and 82 deletions.
  1. +1 −2  notification/admin.py
  2. +0 −80 notification/models.py
View
3  notification/admin.py
@@ -1,6 +1,6 @@
from django.contrib import admin
-from notification.models import NoticeType, NoticeSetting, ObservedItem, NoticeQueueBatch
+from notification.models import NoticeType, NoticeSetting, NoticeQueueBatch
class NoticeTypeAdmin(admin.ModelAdmin):
@@ -14,4 +14,3 @@ class NoticeSettingAdmin(admin.ModelAdmin):
admin.site.register(NoticeQueueBatch)
admin.site.register(NoticeType, NoticeTypeAdmin)
admin.site.register(NoticeSetting, NoticeSettingAdmin)
-admin.site.register(ObservedItem)
View
80 notification/models.py
@@ -239,83 +239,3 @@ def get_for(self, observed, observer, signal):
content_type = ContentType.objects.get_for_model(observed)
observed_item = self.get(content_type=content_type, object_id=observed.id, user=observer, signal=signal)
return observed_item
-
-
-class ObservedItem(models.Model):
-
- user = models.ForeignKey(User, verbose_name=_("user"))
-
- content_type = models.ForeignKey(ContentType)
- object_id = models.PositiveIntegerField()
- observed_object = generic.GenericForeignKey("content_type", "object_id")
-
- notice_type = models.ForeignKey(NoticeType, verbose_name=_("notice type"))
-
- added = models.DateTimeField(_("added"), default=datetime.datetime.now)
-
- # the signal that will be listened to send the notice
- signal = models.TextField(verbose_name=_("signal"))
-
- objects = ObservedItemManager()
-
- class Meta:
- ordering = ["-added"]
- verbose_name = _("observed item")
- verbose_name_plural = _("observed items")
-
- def send_notice(self, extra_context=None):
- if extra_context is None:
- extra_context = {}
- extra_context.update({"observed": self.observed_object})
- send([self.user], self.notice_type.label, extra_context)
-
-
-def observe(observed, observer, notice_type_label, signal="post_save"):
- """
- Create a new ObservedItem.
-
- To be used by applications to register a user as an observer for some object.
- """
- notice_type = NoticeType.objects.get(label=notice_type_label)
- observed_item = ObservedItem(
- user=observer, observed_object=observed,
- notice_type=notice_type, signal=signal
- )
- observed_item.save()
- return observed_item
-
-
-def stop_observing(observed, observer, signal="post_save"):
- """
- Remove an observed item.
- """
- observed_item = ObservedItem.objects.get_for(observed, observer, signal)
- observed_item.delete()
-
-
-def send_observation_notices_for(observed, signal="post_save", extra_context=None):
- """
- Send a notice for each registered user about an observed object.
- """
- if extra_context is None:
- extra_context = {}
- observed_items = ObservedItem.objects.all_for(observed, signal)
- for observed_item in observed_items:
- observed_item.send_notice(extra_context)
- return observed_items
-
-
-def is_observing(observed, observer, signal="post_save"):
- if isinstance(observer, AnonymousUser):
- return False
- try:
- observed_items = ObservedItem.objects.get_for(observed, observer, signal)
- return True
- except ObservedItem.DoesNotExist:
- return False
- except ObservedItem.MultipleObjectsReturned:
- return True
-
-
-def handle_observations(sender, instance, *args, **kw):
- send_observation_notices_for(instance)
Please sign in to comment.
Something went wrong with that request. Please try again.