Commit fe1e839dfa72c3d82e8d377fcab725e88936c491
1 parent
9d290dd6
Exists in
master
and in
39 other branches
Add compatibility to django 1.7
-Add backward compatibility to django 1.6 -Add compabitlity to django 1.7
Showing
5 changed files
with
25 additions
and
15 deletions
Show diff stats
requirements.txt
src/badger/models.py
| 1 | 1 | # -*- coding: utf-8 -*- |
| 2 | 2 | |
| 3 | 3 | from django.conf import settings |
| 4 | -from django.contrib.auth import get_user_model | |
| 5 | 4 | from django.db import models |
| 6 | 5 | from django.utils.translation import ugettext_lazy as _ |
| 7 | 6 | from i18n_model.models import I18nModel |
| ... | ... | @@ -58,7 +57,7 @@ class Badge(models.Model): |
| 58 | 57 | null=True |
| 59 | 58 | ) |
| 60 | 59 | awardees = models.ManyToManyField( |
| 61 | - get_user_model(), | |
| 60 | + settings.AUTH_USER_MODEL, | |
| 62 | 61 | verbose_name=_(u'Awardees'), |
| 63 | 62 | blank=True, |
| 64 | 63 | null=True | ... | ... |
src/colab/custom_settings.py
src/super_archives/managers.py
| 1 | - | |
| 2 | 1 | from django.db import models |
| 3 | 2 | |
| 4 | 3 | from haystack.query import SearchQuerySet |
| 5 | - | |
| 4 | +import django | |
| 6 | 5 | |
| 7 | 6 | class NotSpamManager(models.Manager): |
| 8 | 7 | """Only return objects which are not marked as spam.""" |
| 9 | 8 | |
| 10 | - def get_query_set(self): | |
| 11 | - return super(NotSpamManager, self).get_query_set().exclude(spam=True) | |
| 9 | + def get_queryset(self): | |
| 10 | + if django.VERSION < (1, 7): | |
| 11 | + return super(NotSpamManager, self).get_queryset().exclude(spam=True) | |
| 12 | + else: | |
| 13 | + return super(NotSpamManager, self).get_query_set().exclude(spam=True) | |
| 14 | + | |
| 15 | + if django.VERSION < (1, 7): | |
| 16 | + # in 1.7+, get_query_set gets defined by the base ChangeList and complains if it's called. | |
| 17 | + # otherwise, we have to define it ourselves. | |
| 18 | + get_query_set = get_queryset | |
| 12 | 19 | |
| 13 | 20 | |
| 14 | 21 | class HighestScore(NotSpamManager): |
| 15 | - def get_query_set(self): | |
| 16 | - queryset = super(HighestScore, self).get_query_set() | |
| 22 | + def get_queryset(self): | |
| 23 | + if django.VERSION < (1, 7): | |
| 24 | + queryset = super(HighestScore, self).get_queryset() | |
| 25 | + else: | |
| 26 | + queryset = super(HighestScore, self).get_query_set() | |
| 17 | 27 | return queryset.order_by('-score', '-latest_message__received_time') |
| 18 | 28 | |
| 19 | 29 | def from_haystack(self): |
| ... | ... | @@ -21,11 +31,14 @@ class HighestScore(NotSpamManager): |
| 21 | 31 | |
| 22 | 32 | |
| 23 | 33 | class MostVotedManager(NotSpamManager): |
| 24 | - def get_query_set(self): | |
| 34 | + def get_queryset(self): | |
| 25 | 35 | """Query for the most voted messages sorting by the sum of |
| 26 | 36 | voted and after by date.""" |
| 27 | 37 | |
| 28 | - queryset = super(MostVotedManager, self).get_query_set() | |
| 38 | + if django.VERSION < (1, 7): | |
| 39 | + queryset = super(MostVotedManager, self).get_queryset() | |
| 40 | + else: | |
| 41 | + queryset = super(MostVotedManager, self).get_query_set() | |
| 29 | 42 | |
| 30 | 43 | sql = """ |
| 31 | 44 | SELECT | ... | ... |
src/super_archives/models.py
| ... | ... | @@ -23,7 +23,7 @@ from .utils import blocks |
| 23 | 23 | from .utils.etiquetador import etiquetador |
| 24 | 24 | |
| 25 | 25 | |
| 26 | -User = get_user_model() | |
| 26 | +User = settings.AUTH_USER_MODEL | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | class EmailAddressValidation(models.Model): |
| ... | ... | @@ -360,7 +360,7 @@ class Message(models.Model): |
| 360 | 360 | class MessageBlock(models.Model): |
| 361 | 361 | message = models.ForeignKey(Message, related_name='blocks') |
| 362 | 362 | text = models.TextField() |
| 363 | - is_reply = models.BooleanField() | |
| 363 | + is_reply = models.BooleanField(default=False) | |
| 364 | 364 | order = models.IntegerField() |
| 365 | 365 | |
| 366 | 366 | def __unicode__(self): | ... | ... |