Modèles de commentaires et de notifications #18

Merged
lstephan merged 21 commits from Aufinal/communication_models into master 2017-07-21 16:58:51 +02:00
Showing only changes of commit 4e8873226f - Show all commits

56
vim
View file

@ -1,56 +0,0 @@
diff --git a/communication/models.py b/communication/models.py
index 220d29d..8a89504 100644
--- a/communication/models.py
+++ b/communication/models.py
@@ -1,5 +1,4 @@
from django.db import models
-from django.conf import settings
from django.contrib.auth.models import Group
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.fields import (
@@ -16,31 +15,41 @@ class Subscription(models.Model):
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
+ class Meta:
+ abstract = True
+
class UserSubscription(Subscription):
- user = models.ForeignKey(settings.AUTH_USER_MODEL)
+ user = models.ForeignKey(User)
is_unsub = models.BooleanField(
_("désinscription"),
default=False
)
+ class Meta:
+ verbose_name = _("souscription utilisateur")
+
class GroupSubscription(Subscription):
group = models.ForeignKey(Group)
+ class Meta:
+ verbose_name = _("souscription en groupe")
+
class SubscriptionMixin(models.Model):
subscribed_users = GenericRelation(UserSubscription)
subscribed_groups = GenericRelation(GroupSubscription)
- def get_unique_users(self):
+ def get_manual_subscribers(self):
return self.subscribed_users.filter(is_unsub=False)
- def get_group_users(self):
+ def get_subscribers_from_groups(self):
return User.objects.filter(group__in=self.subscribed_groups.all())
def get_all_subscribers(self):
- return (self.get_unique_users().union(self.get_group_users())
+ return (self.get_manual_subscribers()
+ .union(self.get_subscribers_from_groups())
.exclude(is_unsub=True))
class Meta: