From 59a8b68ffd8773e280549fe8c326bc1c735cb830 Mon Sep 17 00:00:00 2001 From: Guido Espinosa Date: Tue, 23 Sep 2014 12:59:38 -0500 Subject: [PATCH 1/3] compatibility for Django version>1.5 removes usage of deprecated urls.defaults module when Django version > 1.5. Checks Django version so it remains backwards compatible. --- follow/urls.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/follow/urls.py b/follow/urls.py index fa681d2..aa24168 100644 --- a/follow/urls.py +++ b/follow/urls.py @@ -1,4 +1,9 @@ -from django.conf.urls.defaults import * +from django import VERSION as DjangoVersion +if float('%s.%s' % DjangoVersion[:2]) > 1.5: + from django.conf.urls import patterns, url +else: + from django.conf.urls.defaults import * + urlpatterns = patterns('', url(r'^toggle/(?P[^\/]+)/(?P[^\/]+)/(?P\d+)/$', 'follow.views.toggle', name='toggle'), From b59097fbfe031cca1bba23170e16e873422ad79f Mon Sep 17 00:00:00 2001 From: Guido Espinosa Date: Sun, 9 Aug 2015 22:52:52 -0500 Subject: [PATCH 2/3] handles Django v1.8 deprecation Django 1.8 deprecates 'module_name' attribute in Options object. This uses an if statement to test against Django version, and if it finds version 1.8, it uses 'model_name' instead. --- follow/utils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/follow/utils.py b/follow/utils.py index aa0d4b6..b280645 100644 --- a/follow/utils.py +++ b/follow/utils.py @@ -2,6 +2,11 @@ from django.db.models.fields.related import ManyToManyField, ForeignKey from follow.models import Follow from follow.registry import registry, model_map +from django import VERSION as DjangoVersion +if float('%s.%s' % DjangoVersion[:2]) > 1.7: + module_name = 'model_name' +else: + module_name = 'module_name' def get_followers_for_object(instance): return Follow.objects.get_follows(instance) @@ -9,18 +14,18 @@ def get_followers_for_object(instance): def register(model, field_name=None, related_name=None, lookup_method_name='get_follows'): """ This registers any model class to be follow-able. - + """ if model in registry: return registry.append(model) - + if not field_name: - field_name = 'target_%s' % model._meta.module_name - + field_name = 'target_%s' % model._meta.__getattribute__(module_name) + if not related_name: - related_name = 'follow_%s' % model._meta.module_name + related_name = 'follow_%s' % model._meta.__getattribute__(module_name) field = ForeignKey(model, related_name=related_name, null=True, blank=True, db_index=True) From fcc77ac1557ab7f5c3d5605240ea505b8b61b321 Mon Sep 17 00:00:00 2001 From: Guido Espinosa Date: Sat, 6 Feb 2016 23:51:21 -0600 Subject: [PATCH 3/3] Update utils.py --- follow/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/follow/utils.py b/follow/utils.py index b280645..52fd1eb 100644 --- a/follow/utils.py +++ b/follow/utils.py @@ -3,7 +3,7 @@ from follow.models import Follow from follow.registry import registry, model_map from django import VERSION as DjangoVersion -if float('%s.%s' % DjangoVersion[:2]) > 1.7: +if float('%s.%s' % DjangoVersion[:2]) >= 1.7: module_name = 'model_name' else: module_name = 'module_name'