Просмотр исходного кода

UserModel.AUTO_SUBSCRIBE_* constants rename

Rafał Pitoń 8 лет назад
Родитель
Сommit
8a4ad39075

+ 4 - 7
misago/threads/api/postingendpoint/subscribe.py

@@ -6,9 +6,6 @@ from ...models import Subscription
 
 UserModel = get_user_model()
 
-SUBSCRIBE_NONE = UserModel.AUTO_SUBSCRIBE_NONE
-SUBSCRIBE_ALL = UserModel.AUTO_SUBSCRIBE_NOTIFY_AND_EMAIL
-
 
 class SubscribeMiddleware(PostingMiddleware):
     def use_this_middleware(self):
@@ -22,20 +19,20 @@ class SubscribeMiddleware(PostingMiddleware):
         if self.mode != PostingEndpoint.START:
             return
 
-        if self.user.subscribe_to_started_threads == SUBSCRIBE_NONE:
+        if self.user.subscribe_to_started_threads == UserModel.SUBSCRIBE_NONE:
             return
 
         self.user.subscription_set.create(
             category=self.thread.category,
             thread=self.thread,
-            send_email=self.user.subscribe_to_started_threads == SUBSCRIBE_ALL
+            send_email=self.user.subscribe_to_started_threads == UserModel.SUBSCRIBE_ALL
         )
 
     def subscribe_replied_thread(self):
         if self.mode != PostingEndpoint.REPLY:
             return
 
-        if self.user.subscribe_to_replied_threads == SUBSCRIBE_NONE:
+        if self.user.subscribe_to_replied_threads == UserModel.SUBSCRIBE_NONE:
             return
 
         try:
@@ -51,5 +48,5 @@ class SubscribeMiddleware(PostingMiddleware):
         self.user.subscription_set.create(
             category=self.thread.category,
             thread=self.thread,
-            send_email=self.user.subscribe_to_replied_threads == SUBSCRIBE_ALL
+            send_email=self.user.subscribe_to_replied_threads == UserModel.SUBSCRIBE_ALL
         )

+ 9 - 9
misago/threads/tests/test_subscription_middleware.py

@@ -40,8 +40,8 @@ class SubscribeStartedThreadTests(SubscriptionMiddlewareTestCase):
 
     def test_dont_subscribe(self):
         """middleware makes no subscription to thread"""
-        self.user.subscribe_to_started_threads = UserModel.AUTO_SUBSCRIBE_NONE
-        self.user.subscribe_to_replied_threads = UserModel.AUTO_SUBSCRIBE_NOTIFY
+        self.user.subscribe_to_started_threads = UserModel.SUBSCRIBE_NONE
+        self.user.subscribe_to_replied_threads = UserModel.SUBSCRIBE_NOTIFY
         self.user.save()
 
         response = self.client.post(self.api_link, data={
@@ -56,7 +56,7 @@ class SubscribeStartedThreadTests(SubscriptionMiddlewareTestCase):
 
     def test_subscribe(self):
         """middleware subscribes thread"""
-        self.user.subscribe_to_started_threads = UserModel.AUTO_SUBSCRIBE_NOTIFY
+        self.user.subscribe_to_started_threads = UserModel.SUBSCRIBE_NOTIFY
         self.user.save()
 
         response = self.client.post(self.api_link, data={
@@ -75,7 +75,7 @@ class SubscribeStartedThreadTests(SubscriptionMiddlewareTestCase):
 
     def test_email_subscribe(self):
         """middleware subscribes thread with an email"""
-        self.user.subscribe_to_started_threads = UserModel.AUTO_SUBSCRIBE_NOTIFY_AND_EMAIL
+        self.user.subscribe_to_started_threads = UserModel.SUBSCRIBE_ALL
         self.user.save()
 
         response = self.client.post(self.api_link, data={
@@ -103,8 +103,8 @@ class SubscribeRepliedThreadTests(SubscriptionMiddlewareTestCase):
 
     def test_dont_subscribe(self):
         """middleware makes no subscription to thread"""
-        self.user.subscribe_to_started_threads = UserModel.AUTO_SUBSCRIBE_NOTIFY
-        self.user.subscribe_to_replied_threads = UserModel.AUTO_SUBSCRIBE_NONE
+        self.user.subscribe_to_started_threads = UserModel.SUBSCRIBE_NOTIFY
+        self.user.subscribe_to_replied_threads = UserModel.SUBSCRIBE_NONE
         self.user.save()
 
         response = self.client.post(self.api_link, data={
@@ -117,7 +117,7 @@ class SubscribeRepliedThreadTests(SubscriptionMiddlewareTestCase):
 
     def test_subscribe(self):
         """middleware subscribes thread"""
-        self.user.subscribe_to_replied_threads = UserModel.AUTO_SUBSCRIBE_NOTIFY
+        self.user.subscribe_to_replied_threads = UserModel.SUBSCRIBE_NOTIFY
         self.user.save()
 
         response = self.client.post(self.api_link, data={
@@ -133,7 +133,7 @@ class SubscribeRepliedThreadTests(SubscriptionMiddlewareTestCase):
 
     def test_email_subscribe(self):
         """middleware subscribes thread with an email"""
-        self.user.subscribe_to_replied_threads = UserModel.AUTO_SUBSCRIBE_NOTIFY_AND_EMAIL
+        self.user.subscribe_to_replied_threads = UserModel.SUBSCRIBE_ALL
         self.user.save()
 
         response = self.client.post(self.api_link, data={
@@ -149,7 +149,7 @@ class SubscribeRepliedThreadTests(SubscriptionMiddlewareTestCase):
 
     def test_dont_subscribe_replied(self):
         """middleware omits threads user already replied"""
-        self.user.subscribe_to_replied_threads = UserModel.AUTO_SUBSCRIBE_NOTIFY_AND_EMAIL
+        self.user.subscribe_to_replied_threads = UserModel.SUBSCRIBE_ALL
         self.user.save()
 
         response = self.client.post(self.api_link, data={

+ 2 - 2
misago/users/forms/admin.py

@@ -167,12 +167,12 @@ class EditUserForm(UserBaseForm):
     subscribe_to_started_threads = forms.TypedChoiceField(
         label=_("Started threads"),
         coerce=int,
-        choices=User.AUTO_SUBSCRIBE_CHOICES
+        choices=User.SUBSCRIBE_CHOICES
     )
     subscribe_to_replied_threads = forms.TypedChoiceField(
         label=_("Replid threads"),
         coerce=int,
-        choices=User.AUTO_SUBSCRIBE_CHOICES
+        choices=User.SUBSCRIBE_CHOICES
     )
 
     class Meta:

+ 2 - 2
misago/users/forms/options.py

@@ -21,11 +21,11 @@ class ForumOptionsForm(forms.ModelForm):
         coerce=int,
     )
     subscribe_to_started_threads = forms.TypedChoiceField(
-        choices=UserModel.AUTO_SUBSCRIBE_CHOICES,
+        choices=UserModel.SUBSCRIBE_CHOICES,
         coerce=int,
     )
     subscribe_to_replied_threads = forms.TypedChoiceField(
-        choices=UserModel.AUTO_SUBSCRIBE_CHOICES,
+        choices=UserModel.SUBSCRIBE_CHOICES,
         coerce=int,
     )
 

+ 12 - 12
misago/users/models/user.py

@@ -48,9 +48,9 @@ class UserManager(BaseUserManager):
             extra_fields['joined_from_ip'] = '127.0.0.1'
 
         WATCH_DICT = {
-            'no':  self.model.AUTO_SUBSCRIBE_NONE,
-            'watch':  self.model.AUTO_SUBSCRIBE_NOTIFY,
-            'watch_email':  self.model.AUTO_SUBSCRIBE_NOTIFY_AND_EMAIL,
+            'no':  self.model.SUBSCRIBE_NONE,
+            'watch':  self.model.SUBSCRIBE_NOTIFY,
+            'watch_email':  self.model.SUBSCRIBE_ALL,
         }
 
         if not 'subscribe_to_started_threads' in extra_fields:
@@ -147,18 +147,18 @@ class User(AbstractBaseUser, PermissionsMixin):
     ACTIVATION_REQUIRED_USER = 1
     ACTIVATION_REQUIRED_ADMIN = 2
 
-    AUTO_SUBSCRIBE_NONE = 0
-    AUTO_SUBSCRIBE_NOTIFY = 1
-    AUTO_SUBSCRIBE_NOTIFY_AND_EMAIL = 2
+    SUBSCRIBE_NONE = 0
+    SUBSCRIBE_NOTIFY = 1
+    SUBSCRIBE_ALL = 2
 
     LIMITS_PRIVATE_THREAD_INVITES_TO_NONE = 0
     LIMITS_PRIVATE_THREAD_INVITES_TO_FOLLOWED = 1
     LIMITS_PRIVATE_THREAD_INVITES_TO_NOBODY = 2
 
-    AUTO_SUBSCRIBE_CHOICES = (
-        (AUTO_SUBSCRIBE_NONE, _("No")),
-        (AUTO_SUBSCRIBE_NOTIFY, _("Notify")),
-        (AUTO_SUBSCRIBE_NOTIFY_AND_EMAIL, _("Notify with e-mail"))
+    SUBSCRIBE_CHOICES = (
+        (SUBSCRIBE_NONE, _("No")),
+        (SUBSCRIBE_NOTIFY, _("Notify")),
+        (SUBSCRIBE_ALL, _("Notify with e-mail"))
     )
 
     PRIVATE_THREAD_INVITES_LIMITS_CHOICES = (
@@ -256,10 +256,10 @@ class User(AbstractBaseUser, PermissionsMixin):
     sync_unread_private_threads = models.BooleanField(default=False)
 
     subscribe_to_started_threads = models.PositiveIntegerField(
-        default=AUTO_SUBSCRIBE_NONE
+        default=SUBSCRIBE_NONE
     )
     subscribe_to_replied_threads = models.PositiveIntegerField(
-        default=AUTO_SUBSCRIBE_NONE
+        default=SUBSCRIBE_NONE
     )
 
     threads = models.PositiveIntegerField(default=0)