Skip to content

Commit 04072f9

Browse files
committed
some code clean, removes old compatibility related code
1 parent 0cfa6f1 commit 04072f9

File tree

8 files changed

+20
-42
lines changed

8 files changed

+20
-42
lines changed

src/concurrency/compat.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, print_function, unicode_literals
33

4+
# from django.core.urlresolvers import get_callable
5+
# from django.db.transaction import atomic
6+
47
try:
58
from django.template.base import TemplateDoesNotExist
69
except ImportError:
710
from django.template.exceptions import TemplateDoesNotExist # noqa - django 1.9
8-
9-
try:
10-
from django.db.transaction import atomic
11-
except ImportError:
12-
from django.db.transaction import commit_on_success as atomic # noqa

src/concurrency/config.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1+
# coding=utf-8
12
from __future__ import absolute_import, unicode_literals
23

34
from django.core.exceptions import ImproperlyConfigured
45
from django.test.signals import setting_changed
6+
from django.urls import get_callable
57
from django.utils import six
68

7-
try:
8-
from django.urls.utils import get_callable
9-
except ImportError:
10-
from django.core.urlresolvers import get_callable
11-
129
# List Editable Policy
1310
# 0 do not save updated records, save others, show message to the user
1411
# 1 abort whole transaction

src/concurrency/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding=utf-8
12
from __future__ import absolute_import, unicode_literals
23

34
import logging

src/concurrency/fields.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding=utf-8
12
from __future__ import absolute_import, unicode_literals
23

34
import copy
@@ -11,6 +12,7 @@
1112
from django.db import models
1213
from django.db.models import signals
1314
from django.db.models.fields import Field
15+
from django.db.models.signals import class_prepared, post_migrate
1416
from django.utils.encoding import force_text
1517
from django.utils.translation import ugettext_lazy as _
1618

@@ -20,18 +22,6 @@
2022
from concurrency.core import ConcurrencyOptions
2123
from concurrency.utils import fqn, refetch
2224

23-
try:
24-
from django.apps import apps
25-
26-
get_model = apps.get_model
27-
except ImportError:
28-
from django.db.models.loading import get_model
29-
30-
try:
31-
from django.db.models.signals import class_prepared, post_migrate
32-
except:
33-
from django.db.models.signals import class_prepared, post_syncdb as post_migrate
34-
3525
logger = logging.getLogger(__name__)
3626

3727
OFFSET = int(time.mktime((2000, 1, 1, 0, 0, 0, 0, 0, 0)))
@@ -109,14 +99,6 @@ def __init__(self, *args, **kwargs):
10999
db_tablespace=db_tablespace,
110100
db_column=db_column)
111101

112-
def deconstruct(self):
113-
name, path, args, kwargs = super(VersionField, self).deconstruct()
114-
kwargs['default'] = 1
115-
return name, path, args, kwargs
116-
117-
def get_default(self):
118-
return 0
119-
120102
def get_internal_type(self):
121103
return "BigIntegerField"
122104

@@ -131,8 +113,8 @@ def formfield(self, **kwargs):
131113
kwargs['widget'] = forms.VersionField.widget
132114
return super(VersionField, self).formfield(**kwargs)
133115

134-
def contribute_to_class(self, cls, name, virtual_only=False):
135-
super(VersionField, self).contribute_to_class(cls, name, virtual_only)
116+
def contribute_to_class(self, cls, *args, **kwargs):
117+
super(VersionField, self).contribute_to_class(cls, *args, **kwargs)
136118
if hasattr(cls, '_concurrencymeta') or cls._meta.abstract:
137119
return
138120
setattr(cls, '_concurrencymeta', ConcurrencyOptions())
@@ -250,8 +232,8 @@ def __init__(self, *args, **kwargs):
250232
self._trigger_exists = False
251233
super(TriggerVersionField, self).__init__(*args, **kwargs)
252234

253-
def contribute_to_class(self, cls, name, virtual_only=False):
254-
super(TriggerVersionField, self).contribute_to_class(cls, name)
235+
def contribute_to_class(self, cls, *args, **kwargs):
236+
super(TriggerVersionField, self).contribute_to_class(cls, *args, **kwargs)
255237
if not cls._meta.abstract or cls._meta.proxy:
256238
if self not in _TRIGGERS:
257239
_TRIGGERS.append(self)
@@ -332,8 +314,8 @@ def filter_fields(instance, field):
332314

333315

334316
class ConditionalVersionField(AutoIncVersionField):
335-
def contribute_to_class(self, cls, name, virtual_only=False):
336-
super(ConditionalVersionField, self).contribute_to_class(cls, name, virtual_only)
317+
def contribute_to_class(self, cls, *args, **kwargs):
318+
super(ConditionalVersionField, self).contribute_to_class(cls, *args, **kwargs)
337319
signals.post_init.connect(self._load_model,
338320
sender=cls,
339321
dispatch_uid=fqn(cls))

src/concurrency/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding=utf-8
12
from __future__ import absolute_import, unicode_literals
23

34
from importlib import import_module

src/concurrency/management/commands/triggers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from django.core.exceptions import ImproperlyConfigured
33
from django.core.management.base import BaseCommand
44
from django.db import connections
5+
from django.db.transaction import atomic
56

6-
from concurrency.compat import atomic
77
from concurrency.triggers import create_triggers, drop_triggers, get_triggers
88

99

src/concurrency/triggers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
from collections import defaultdict
55

6+
from django.apps import apps
67
from django.db import connections, router
78
from django.db.utils import DatabaseError
89

9-
from concurrency.fields import _TRIGGERS, get_model # noqa
10-
1110

1211
def get_trigger_name(field):
1312
"""
@@ -39,7 +38,7 @@ def drop_triggers(*databases):
3938
global _TRIGGERS
4039
ret = defaultdict(lambda: [])
4140
for app_label, model_name in _TRIGGERS:
42-
model = get_model(app_label, model_name)
41+
model = apps.get_model(app_label, model_name)
4342
field = model._concurrencymeta.field
4443
alias = router.db_for_write(model)
4544
if alias in databases:
@@ -56,7 +55,7 @@ def create_triggers(databases):
5655
ret = defaultdict(lambda: [])
5756

5857
for app_label, model_name in _TRIGGERS:
59-
model = get_model(app_label, model_name)
58+
model = apps.get_model(app_label, model_name)
6059
field = model._concurrencymeta.field
6160
storage = model._concurrencymeta.triggers
6261
alias = router.db_for_write(model)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
envlist = py{27}-d{18,19,110,111}-{pg,sqlite,mysql},
3-
py{34,35,36}-d{18,19,110,111}-{pg,sqlite, mysql}
3+
py{34,35,36}-d{18,19,110,111}-{pg,sqlite,mysql}
44
pypy-d{18,19,110,111}-{pg,sqlite}
55

66
[pytest]

0 commit comments

Comments
 (0)