From 19093d01f34277943280100b185f902fa7c47a04 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 18 Jul 2017 13:54:11 +0200 Subject: [PATCH] Small fixes --- communication/models.py | 19 ++++++++++---- vim | 56 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 vim 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: