Commit b9b464ed14ec185845b7097e3a299489dcf98f82
1 parent
7fa6f9ce
Exists in
master
and in
39 other branches
Replaced get_user_model into models
Django 1.7 requires that references to custom users into models.py to be by settings instead of get_user_model
Showing
2 changed files
with
11 additions
and
21 deletions
Show diff stats
requirements.txt
src/super_archives/models.py
@@ -8,11 +8,9 @@ from hashlib import md5 | @@ -8,11 +8,9 @@ from hashlib import md5 | ||
8 | from django.db import models | 8 | from django.db import models |
9 | from django.conf import settings | 9 | from django.conf import settings |
10 | from django.utils import timezone | 10 | from django.utils import timezone |
11 | -from django.core.cache import cache | ||
12 | from django.dispatch import receiver | 11 | from django.dispatch import receiver |
13 | -from django.contrib.auth import get_user_model | ||
14 | from django.db.models.signals import post_save | 12 | from django.db.models.signals import post_save |
15 | -from django.core.urlresolvers import reverse, NoReverseMatch | 13 | +from django.core.urlresolvers import reverse |
16 | from django.utils.translation import ugettext_lazy as _ | 14 | from django.utils.translation import ugettext_lazy as _ |
17 | 15 | ||
18 | from html2text import html2text | 16 | from html2text import html2text |
@@ -25,12 +23,9 @@ from .utils import blocks | @@ -25,12 +23,9 @@ from .utils import blocks | ||
25 | from .utils.etiquetador import etiquetador | 23 | from .utils.etiquetador import etiquetador |
26 | 24 | ||
27 | 25 | ||
28 | -User = settings.AUTH_USER_MODEL | ||
29 | - | ||
30 | - | ||
31 | class EmailAddressValidation(models.Model): | 26 | class EmailAddressValidation(models.Model): |
32 | address = models.EmailField(unique=True) | 27 | address = models.EmailField(unique=True) |
33 | - user = models.ForeignKey(User, null=True, | 28 | + user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, |
34 | related_name='emails_not_validated') | 29 | related_name='emails_not_validated') |
35 | validation_key = models.CharField(max_length=32, null=True, | 30 | validation_key = models.CharField(max_length=32, null=True, |
36 | default=lambda: uuid4().hex) | 31 | default=lambda: uuid4().hex) |
@@ -41,8 +36,8 @@ class EmailAddressValidation(models.Model): | @@ -41,8 +36,8 @@ class EmailAddressValidation(models.Model): | ||
41 | 36 | ||
42 | 37 | ||
43 | class EmailAddress(models.Model): | 38 | class EmailAddress(models.Model): |
44 | - user = models.ForeignKey(User, null=True, related_name='emails', | ||
45 | - on_delete=models.SET_NULL) | 39 | + user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, |
40 | + related_name='emails', on_delete=models.SET_NULL) | ||
46 | address = models.EmailField(unique=True) | 41 | address = models.EmailField(unique=True) |
47 | real_name = models.CharField(max_length=64, blank=True, db_index=True) | 42 | real_name = models.CharField(max_length=64, blank=True, db_index=True) |
48 | md5 = models.CharField(max_length=32, null=True) | 43 | md5 = models.CharField(max_length=32, null=True) |
@@ -71,7 +66,7 @@ class MailingList(models.Model): | @@ -71,7 +66,7 @@ class MailingList(models.Model): | ||
71 | name = models.CharField(max_length=80) | 66 | name = models.CharField(max_length=80) |
72 | email = models.EmailField() | 67 | email = models.EmailField() |
73 | description = models.TextField() | 68 | description = models.TextField() |
74 | - logo = models.FileField(upload_to='list_logo') #TODO | 69 | + logo = models.FileField(upload_to='list_logo') # TODO |
75 | last_imported_index = models.IntegerField(default=0) | 70 | last_imported_index = models.IntegerField(default=0) |
76 | 71 | ||
77 | def get_absolute_url(self): | 72 | def get_absolute_url(self): |
@@ -88,7 +83,7 @@ class MailingList(models.Model): | @@ -88,7 +83,7 @@ class MailingList(models.Model): | ||
88 | 83 | ||
89 | 84 | ||
90 | class MailingListMembership(models.Model): | 85 | class MailingListMembership(models.Model): |
91 | - user = models.ForeignKey(User) | 86 | + user = models.ForeignKey(settings.AUTH_USER_MODEL) |
92 | mailinglist = models.ForeignKey(MailingList) | 87 | mailinglist = models.ForeignKey(MailingList) |
93 | 88 | ||
94 | def __unicode__(self): | 89 | def __unicode__(self): |
@@ -101,7 +96,7 @@ class Keyword(models.Model): | @@ -101,7 +96,7 @@ class Keyword(models.Model): | ||
101 | thread = models.ForeignKey('Thread') | 96 | thread = models.ForeignKey('Thread') |
102 | 97 | ||
103 | class Meta: | 98 | class Meta: |
104 | - ordering = ('?', ) # random order | 99 | + ordering = ('?', ) # random order |
105 | 100 | ||
106 | def __unicode__(self): | 101 | def __unicode__(self): |
107 | return self.keyword | 102 | return self.keyword |
@@ -221,7 +216,7 @@ class Thread(models.Model, HitCounterModelMixin): | @@ -221,7 +216,7 @@ class Thread(models.Model, HitCounterModelMixin): | ||
221 | 216 | ||
222 | 217 | ||
223 | class Vote(models.Model): | 218 | class Vote(models.Model): |
224 | - user = models.ForeignKey(User) | 219 | + user = models.ForeignKey(settings.AUTH_USER_MODEL) |
225 | message = models.ForeignKey('Message') | 220 | message = models.ForeignKey('Message') |
226 | created = models.DateTimeField(auto_now_add=True) | 221 | created = models.DateTimeField(auto_now_add=True) |
227 | 222 | ||
@@ -392,12 +387,7 @@ class MessageMetadata(models.Model): | @@ -392,12 +387,7 @@ class MessageMetadata(models.Model): | ||
392 | return 'Email Message Id: %s - %s: %s' % (self.Message.id, | 387 | return 'Email Message Id: %s - %s: %s' % (self.Message.id, |
393 | self.name, self.value) | 388 | self.name, self.value) |
394 | 389 | ||
395 | - | ||
396 | -# For django 1.7 erase the 2 next lines | ||
397 | -from django.contrib.auth import get_user_model | ||
398 | -User = get_user_model() | ||
399 | - | ||
400 | -@receiver(post_save, sender=User) | 390 | +@receiver(post_save, sender=settings.AUTH_USER_MODEL) |
401 | def create_email_address(sender, instance, created, **kwargs): | 391 | def create_email_address(sender, instance, created, **kwargs): |
402 | if not created: | 392 | if not created: |
403 | return | 393 | return |