Skip to content

Commit cf7e9f1

Browse files
committed
- code clean and typos
- removed no-API ConcurrentModelAdmin - 0.4c4
1 parent b4c9d64 commit cf7e9f1

File tree

10 files changed

+30
-175
lines changed

10 files changed

+30
-175
lines changed

concurrency/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import datetime
33
import os
44

5-
VERSION = __version__ = (0, 4, 0, 'rc', 3)
5+
VERSION = __version__ = (0, 4, 0, 'rc', 4)
66
__author__ = 'sax'
77

88

concurrency/admin.py

Lines changed: 0 additions & 150 deletions
This file was deleted.

concurrency/forms.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ def __init__(self, value):
5858
self.value = value
5959

6060
def __repr__(self):
61-
return str(self.value)
61+
if self.value:
62+
return str(self.value)
63+
else:
64+
return ''
6265

6366

6467
class VersionField(forms.IntegerField):
@@ -87,7 +90,7 @@ def to_python(self, value):
8790
if value not in (None, '', 'None'):
8891
return int(self._signer.unsign(value))
8992
return 0
90-
except (BadSignature, ValueError) as e:
93+
except (BadSignature, ValueError):
9194
raise SuspiciousOperation(_('Version number seems tampered'))
9295

9396
def widget_attrs(self, widget):

concurrency/middleware.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from concurrency.views import handler409
66

77

8-
9-
# This middleware is still alpha and should not be used.
108
class ConcurrencyMiddleware(object):
119
def process_exception(self, request, exception):
1210
if isinstance(exception, RecordModifiedError):

concurrency/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.db.models.signals import class_prepared
22
from concurrency.core import class_prepared_concurrency_handler
33

4+
45
class_prepared.connect(class_prepared_concurrency_handler, dispatch_uid='class_prepared_concurrency_handler')

concurrency/tests/conf.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
3-
from django.utils.translation import gettext as _
42
from concurrency.core import InconsistencyError
53
from concurrency.tests import DjangoAdminTestCase, TestModel0, TestModelWithCustomSave
64

75

86
class SettingsTest(DjangoAdminTestCase):
97

10-
118
def test_concurrecy_sanity_check(self):
129
"""
1310
Tests CONCURRECY_SANITY_CHECK settings

concurrency/tests/contrib_admin.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from django.core.urlresolvers import reverse
99
from django.forms.models import modelform_factory
1010
from django.test import TestCase
11-
# from concurrency.tests.models import *
1211
from concurrency import forms
1312
from concurrency.forms import ConcurrentForm, VersionWidget, VersionFieldSigner
1413
from concurrency.tests import TestModel0, TestModel1
@@ -27,28 +26,26 @@
2726

2827
class TestModel1Admin(admin.ModelAdmin):
2928
formfield_overrides = {
30-
# VersionField: {'widget': VersionWidget},
3129
forms.VersionField: {'widget': VersionWidget()},
32-
# IntegerVersionField: {'widget': VersionWidget},
33-
# AutoIncVersionField: {'widget': VersionWidget},
3430
}
3531
form = modelform_factory(TestModel1, ConcurrentForm,
3632
widgets={'version': VersionWidget()})
3733

3834

3935
class DjangoAdminTestCase(TestCase):
4036
urls = 'concurrency.tests.urls'
37+
MIDDLEWARE_CLASSES = global_settings.MIDDLEWARE_CLASSES
38+
AUTHENTICATION_BACKENDS = global_settings.AUTHENTICATION_BACKENDS
4139

4240
def setUp(self):
4341
super(DjangoAdminTestCase, self).setUp()
4442
self.sett = self.settings(INSTALLED_APPS=INSTALLED_APPS,
45-
MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES,
46-
AUTHENTICATION_BACKENDS=global_settings.AUTHENTICATION_BACKENDS,
43+
MIDDLEWARE_CLASSES=self.MIDDLEWARE_CLASSES,
44+
AUTHENTICATION_BACKENDS=self.AUTHENTICATION_BACKENDS,
4745
PASSWORD_HASHERS=('django.contrib.auth.hashers.MD5PasswordHasher',), # fastest hasher
4846
STATIC_URL='/static/',
4947
SOUTH_TESTS_MIGRATE=False,
5048
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),),
51-
# TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader',)
5249
)
5350
self.sett.enable()
5451
django.core.management._commands = None # reset commands cache

concurrency/tests/forms.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test(self):
2727
u'<input name="ver" type="hidden" value="100"/><div>100</div>')
2828

2929

30-
class FieldTest(SimpleTestCase):
30+
class FormFieldTest(SimpleTestCase):
3131

3232
def setUp(self):
3333
self.save_warnings_state()
@@ -84,6 +84,18 @@ def test_signer(self):
8484
form = Form({'username': 'aaa'})
8585
self.assertTrue(form.is_valid(), form.non_field_errors())
8686

87+
def test_initial_value(self):
88+
Form = modelform_factory(TestModel0, type('xxx', (ConcurrentForm,), {}))
89+
form = Form({'username': 'aaa'})
90+
self.assertHTMLEqual(str(form['version']), '<input type="hidden" value="" name="version" id="id_version" />')
91+
self.assertTrue(form.is_valid(), form.non_field_errors())
92+
93+
def test_initial_value_with_custom_signer(self):
94+
Form = modelform_factory(TestIssue3Model, type('xxx', (ConcurrentForm,), {'version': VersionField(signer=DummySigner())}))
95+
form = Form({'username': 'aaa'})
96+
self.assertHTMLEqual(str(form['version']), '<input type="hidden" value="" name="version" id="id_version" />')
97+
self.assertTrue(form.is_valid(), form.non_field_errors())
98+
8799
def test_tamperig(self):
88100
obj, __ = TestIssue3Model.objects.get_or_create(username='aaa')
89101
Form = modelform_factory(TestIssue3Model, ConcurrentForm)

concurrency/tests/middleware.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
from django.conf import global_settings
2+
import mock
33
from django.core.urlresolvers import reverse
44
from django.http import HttpRequest
55
from django.test import TestCase
@@ -40,13 +40,12 @@ def test_process_exception(self):
4040

4141

4242
class CT(DjangoAdminTestCase):
43+
MIDDLEWARE_CLASSES = ('django.middleware.common.CommonMiddleware',
44+
'django.contrib.sessions.middleware.SessionMiddleware',
45+
'django.contrib.auth.middleware.AuthenticationMiddleware',
46+
'concurrency.middleware.ConcurrencyMiddleware',)
4347

44-
def setUp(self):
45-
DjangoAdminTestCase.setUp(self)
46-
m = ['concurrency.middleware.ConcurrencyMiddleware'] + list(global_settings.MIDDLEWARE_CLASSES)
47-
self.sett = self.settings(MIDDLEWARE_CLASSES= m)
48-
self.sett.enable()
49-
48+
@mock.patch('django.core.signals.got_request_exception.send', mock.Mock())
5049
def test_stack(self):
5150
m, __ = TestModel0.objects.get_or_create(username="New", last_name="1")
5251
copy = TestModel0.objects.get(pk=m.pk)

concurrency/views.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from django.template.context import RequestContext
66

77

8-
# This module is still alpha and should not be used.
9-
108
class ConflictResponse(HttpResponse):
119
status_code = 409
1210

0 commit comments

Comments
 (0)