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: diff --git a/vim b/vim new file mode 100644 index 0000000..930386b --- /dev/null +++ b/vim @@ -0,0 +1,56 @@ +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: