Skip to content

Commit

Permalink
Merge pull request #227 from saxix/modern
Browse files Browse the repository at this point in the history
Create main.yml
  • Loading branch information
domdinicola committed Oct 6, 2021
2 parents ff8eecf + 42acb6c commit ed57718
Show file tree
Hide file tree
Showing 42 changed files with 88 additions and 161 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ __pycache__
Pipfile.lock
poetry.lock
pyproject.toml
.venv/
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: python
sudo: true
python:
- 3.6
- 3.7
- 3.8
- 3.9

addons:
postgresql: "9.4"
Expand All @@ -20,7 +19,10 @@ services:
env:
- DJANGO=3.0 DB=pg
- DJANGO=3.0 DB=mysql

- DJANGO=3.1 DB=pg
- DJANGO=3.1 DB=mysql
- DJANGO=3.2 DB=pg
- DJANGO=3.2 DB=mysql

install:
- pip install tox "coverage<=4.0" codecov
Expand Down
6 changes: 0 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ Django Concurrency

django-concurrency is an optimistic lock [1]_ implementation for Django.

Supported Django versions:

- <=2.1.1 supports 1.11.x, 2.1.x, 2.2.x, 3.x
- >=2.2 supports 3.x


It prevents users from doing concurrent editing in Django both from UI and from a
django command.

Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import os
import sys

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,CONCURRENCY,LOCALFOLDER
max-complexity = 12
max-line-length = 160
exclude = .tox,migrations,.git,docs,diff_match_patch.py, deploy/**,settings
ignore = E501,E401,W391,E128,E261,E731
ignore = E501,E401,W391,E128,E261,E731,W504

[aliases]
test=pytest
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def run_tests(self):
'Programming Language :: Python',
'Framework :: Django :: 3.0',
'Framework :: Django :: 3.1',
'Framework :: Django :: 3.2',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Topic :: Software Development :: Libraries :: Python Modules',
],
Expand Down
8 changes: 4 additions & 4 deletions src/concurrency/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import operator
import re
from functools import reduce

from django.contrib import admin, messages
from django.contrib.admin import helpers
from django.core.checks import Error
Expand All @@ -16,6 +12,10 @@
from django.utils.safestring import mark_safe
from django.utils.translation import ungettext

import operator
import re
from functools import reduce

from concurrency import core, forms
from concurrency.api import get_revision_of_object
from concurrency.config import CONCURRENCY_LIST_EDITABLE_POLICY_ABORT_ALL, conf
Expand Down
4 changes: 2 additions & 2 deletions src/concurrency/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from django.db.models import Model

import logging

from concurrency.config import conf
from concurrency.core import get_version_fieldname # _wrap_model_save
from concurrency.exceptions import RecordModifiedError
Expand Down
15 changes: 8 additions & 7 deletions src/concurrency/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import warnings

from django.core.exceptions import ImproperlyConfigured
from django.test.signals import setting_changed
from django.utils.module_loading import import_string

import warnings

from .compat import get_callable

# List Editable Policy
Expand All @@ -27,11 +27,12 @@ class AppSettings(object):
'CALLBACK': 'concurrency.views.callback',
'HANDLER409': 'concurrency.views.conflict',
'VERSION_FIELD_REQUIRED': True,
'TRIGGERS_FACTORY': {'postgresql': "concurrency.triggers.PostgreSQL",
'mysql': "concurrency.triggers.MySQL",
'sqlite3': "concurrency.triggers.Sqlite3",
'sqlite': "concurrency.triggers.Sqlite3",
}
'TRIGGERS_FACTORY': {
'postgresql': "concurrency.triggers.PostgreSQL",
'mysql': "concurrency.triggers.MySQL",
'sqlite3': "concurrency.triggers.Sqlite3",
'sqlite': "concurrency.triggers.Sqlite3",
}
}

def __init__(self, prefix):
Expand Down
27 changes: 15 additions & 12 deletions src/concurrency/fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
from django.db import models
from django.db.models import signals
from django.db.models.fields import Field
from django.db.models.signals import class_prepared, post_migrate
from django.utils.encoding import force_str
from django.utils.translation import gettext_lazy as _

import copy
import functools
import hashlib
Expand All @@ -6,19 +13,14 @@
from collections import OrderedDict
from functools import update_wrapper

from django.db import models
from django.db.models import signals
from django.db.models.fields import Field
from django.db.models.signals import class_prepared, post_migrate
from django.utils.encoding import force_text
from django.utils.translation import gettext_lazy as _

from concurrency import forms
from concurrency.api import get_revision_of_object
from concurrency.config import conf
from concurrency.core import ConcurrencyOptions
from concurrency.utils import fqn, refetch

from .triggers import _TRIGGERS

logger = logging.getLogger(__name__)

OFFSET = int(time.mktime((2000, 1, 1, 0, 0, 0, 0, 0, 0)))
Expand Down Expand Up @@ -50,9 +52,10 @@ def class_prepared_concurrency_handler(sender, **kwargs):


def post_syncdb_concurrency_handler(sender, **kwargs):
from concurrency.triggers import create_triggers
from django.db import connections

from concurrency.triggers import create_triggers

databases = [alias for alias in connections]
create_triggers(databases)

Expand Down Expand Up @@ -202,7 +205,6 @@ class AutoIncVersionField(VersionField):
def _get_next_version(self, model_instance):
return int(getattr(model_instance, self.attname, 0)) + 1

from .triggers import _TRIGGERS

class TriggerVersionField(VersionField):
"""
Expand All @@ -225,9 +227,10 @@ def contribute_to_class(self, cls, *args, **kwargs):
def check(self, **kwargs):
errors = []
model = self.model
from django.db import router, connections
from concurrency.triggers import factory
from django.core.checks import Warning
from django.db import connections, router

from concurrency.triggers import factory

alias = router.db_for_write(model)
connection = connections[alias]
Expand Down Expand Up @@ -338,7 +341,7 @@ def _get_hash(self, instance):
values[field_name] = getattr(instance, field_name).values_list('pk', flat=True)
else:
values[field_name] = field.value_from_object(instance)
return hashlib.sha1(force_text(values).encode('utf-8')).hexdigest()
return hashlib.sha1(force_str(values).encode('utf-8')).hexdigest()

def _get_next_version(self, model_instance):
if not model_instance.pk:
Expand Down
6 changes: 3 additions & 3 deletions src/concurrency/forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from importlib import import_module

from django import forms
from django.core.exceptions import NON_FIELD_ERRORS, ImproperlyConfigured, ValidationError
from django.core.signing import BadSignature, Signer
from django.forms import HiddenInput, ModelForm
from django.utils.safestring import mark_safe
from django.utils.translation import gettext as _

from importlib import import_module

from concurrency.config import conf
from concurrency.core import _select_lock
from concurrency.exceptions import RecordModifiedError, VersionError
Expand All @@ -25,7 +25,7 @@ def clean(self):
_select_lock(self.instance, self.cleaned_data[self.instance._concurrencymeta.field.name])

except RecordModifiedError:
self._update_errors(ValidationError({NON_FIELD_ERRORS: self.error_class([_('Record Modified')])}))
self._update_errors(ValidationError({NON_FIELD_ERRORS: self.error_class([_('Record Modified')])}))

return super(ConcurrentForm, self).clean()

Expand Down
4 changes: 2 additions & 2 deletions src/concurrency/management/commands/triggers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from functools import partial

import django
from django.core.exceptions import ImproperlyConfigured
from django.core.management.base import BaseCommand
from django.db import connections
from django.db.transaction import atomic

from functools import partial

from concurrency.triggers import create_triggers, drop_triggers, get_triggers


Expand Down
5 changes: 3 additions & 2 deletions src/concurrency/triggers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from collections import defaultdict

from django.apps import apps
from django.db import connections, router
from django.db.utils import DatabaseError

from collections import defaultdict

# from .fields import _TRIGGERS # noqa


Expand All @@ -23,6 +23,7 @@ def __contains__(self, field):

_TRIGGERS = TriggerRegistry()


def get_trigger_name(field):
"""
Expand Down
6 changes: 1 addition & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import os
import platform
import sys

import django

import pytest
import sys

py_impl = getattr(platform, 'python_implementation', lambda: None)
PYPY = py_impl() == 'PyPy'
Expand All @@ -21,7 +18,6 @@


def pytest_configure():
from django.contrib.auth.models import Group
from django.conf import settings

settings.SILENCED_SYSTEM_CHECKS = ['concurrency.W001']
Expand Down
6 changes: 1 addition & 5 deletions tests/demoapp/demo/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.contrib import admin
from django.contrib.admin.sites import NotRegistered

Expand Down Expand Up @@ -39,9 +37,7 @@ class ReversionConcurrentModelAdmin(VersionAdmin, ConcurrentModelAdmin):

@disable_concurrency()
def recover_view(self, request, version_id, extra_context=None):
return super(ReversionConcurrentModelAdmin, self).recover_view(request,
version_id,
extra_context)
return super().recover_view(request, version_id, extra_context)


class ActionsModelAdmin(ConcurrentModelAdmin):
Expand Down
3 changes: 0 additions & 3 deletions tests/demoapp/demo/auth_migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-09-09 15:22
from __future__ import unicode_literals

import django.contrib.auth.models
import django.core.validators
import django.db.models.deletion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations

from concurrency.fields import IntegerVersionField
Expand Down
8 changes: 3 additions & 5 deletions tests/demoapp/demo/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import django
from django.contrib.auth.models import Group, User
from django.test import TransactionTestCase
Expand All @@ -23,7 +21,7 @@ class AdminTestCase(WebTestMixin, TransactionTestCase):
urls = 'demo.urls'

def setUp(self):
super(AdminTestCase, self).setUp()
super().setUp()

self.user, __ = User.objects.get_or_create(is_superuser=True,
is_staff=True,
Expand All @@ -42,7 +40,7 @@ def setUp(self):
# AUTHENTICATION_BACKENDS = global_settings.AUTHENTICATION_BACKENDS
#
# def setUp(self):
# super(DjangoAdminTestCase, self).setUp()
# super().setUp()
# self.sett = self.settings(
# #INSTALLED_APPS=INSTALLED_APPS,
# MIDDLEWARE_CLASSES=self.MIDDLEWARE_CLASSES,
Expand All @@ -69,6 +67,6 @@ def setUp(self):
# # self.target1, __ = TestModel1.objects.get_or_create(username='bbb')
#
# def tearDown(self):
# super(DjangoAdminTestCase, self).tearDown()
# super().tearDown()
# self.sett.disable()
# # admin_unregister(TestModel0, TestModel1)
3 changes: 0 additions & 3 deletions tests/demoapp/demo/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-09-09 15:41
from __future__ import unicode_literals

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
Expand Down
3 changes: 0 additions & 3 deletions tests/demoapp/demo/migrations/0002_auto_20160909_1544.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-09-09 15:44
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models

Expand Down
3 changes: 0 additions & 3 deletions tests/demoapp/demo/migrations/0003_auto_20171207_1254.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
7 changes: 2 additions & 5 deletions tests/demoapp/demo/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib.auth.models import Group, User
from django.db import models

Expand Down Expand Up @@ -91,7 +88,7 @@ class CustomSaveModel(SimpleConcurrentModel):
extra_field = models.CharField(max_length=30, blank=True, null=True, unique=True)

def save(self, *args, **kwargs):
super(CustomSaveModel, self).save(*args, **kwargs)
super().save(*args, **kwargs)

class Meta:
app_label = 'demo'
Expand Down Expand Up @@ -139,7 +136,7 @@ class Meta:
# app_label = 'demo'
#
# def save(self, *args, **kwargs):
# super(TestModelGroupWithCustomSave, self).save(*args, **kwargs)
# super().save(*args, **kwargs)
# return 222


Expand Down

0 comments on commit ed57718

Please sign in to comment.