Added settings value MOTION_IDENTIFIER_MIN_DIGITS. Solved #2696.
This commit is contained in:
parent
9440842e6a
commit
ad651300d9
@ -1,5 +1,6 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes.fields import GenericRelation
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Max
|
from django.db.models import Max
|
||||||
from django.utils import formats
|
from django.utils import formats
|
||||||
@ -330,14 +331,27 @@ class Motion(RESTModelMixin, models.Model):
|
|||||||
prefix = '%s ' % self.category.prefix
|
prefix = '%s ' % self.category.prefix
|
||||||
|
|
||||||
number += 1
|
number += 1
|
||||||
identifier = '%s%d' % (prefix, number)
|
identifier = '%s%s' % (prefix, self.extend_identifier_number(number))
|
||||||
while Motion.objects.filter(identifier=identifier).exists():
|
while Motion.objects.filter(identifier=identifier).exists():
|
||||||
number += 1
|
number += 1
|
||||||
identifier = '%s%d' % (prefix, number)
|
identifier = '%s%s' % (prefix, self.extend_identifier_number(number))
|
||||||
|
|
||||||
self.identifier = identifier
|
self.identifier = identifier
|
||||||
self.identifier_number = number
|
self.identifier_number = number
|
||||||
|
|
||||||
|
def extend_identifier_number(self, number):
|
||||||
|
"""
|
||||||
|
Returns the number used in the set_identifier method with leading
|
||||||
|
zero charaters according to the settings value
|
||||||
|
MOTION_IDENTIFIER_MIN_DIGITS.
|
||||||
|
"""
|
||||||
|
result = str(number)
|
||||||
|
if hasattr(settings, 'MOTION_IDENTIFIER_MIN_DIGITS') and settings.MOTION_IDENTIFIER_MIN_DIGITS:
|
||||||
|
if not isinstance(settings.MOTION_IDENTIFIER_MIN_DIGITS, int):
|
||||||
|
raise ImproperlyConfigured('Settings value MOTION_IDENTIFIER_MIN_DIGITS must be an integer.')
|
||||||
|
result = '0' * (settings.MOTION_IDENTIFIER_MIN_DIGITS - len(str(number))) + result
|
||||||
|
return result
|
||||||
|
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
"""
|
"""
|
||||||
Get the title of the motion.
|
Get the title of the motion.
|
||||||
|
@ -431,7 +431,7 @@ class CategoryViewSet(ModelViewSet):
|
|||||||
parent_identifier = motion.parent.identifier or ''
|
parent_identifier = motion.parent.identifier or ''
|
||||||
prefix = '%s %s ' % (parent_identifier, config['motions_amendments_prefix'])
|
prefix = '%s %s ' % (parent_identifier, config['motions_amendments_prefix'])
|
||||||
number += 1
|
number += 1
|
||||||
identifier = '%s%d' % (prefix, number)
|
identifier = '%s%s' % (prefix, motion.extend_identifier_number(number))
|
||||||
motion.identifier = identifier
|
motion.identifier = identifier
|
||||||
motion.identifier_number = number
|
motion.identifier_number = number
|
||||||
motion.save()
|
motion.save()
|
||||||
|
@ -115,3 +115,8 @@ MEDIA_ROOT = os.path.join(OPENSLIDES_USER_DATA_PATH, 'media', '')
|
|||||||
# https://whoosh.readthedocs.io/en/latest/
|
# https://whoosh.readthedocs.io/en/latest/
|
||||||
|
|
||||||
SEARCH_INDEX = os.path.join(OPENSLIDES_USER_DATA_PATH, 'search_index')
|
SEARCH_INDEX = os.path.join(OPENSLIDES_USER_DATA_PATH, 'search_index')
|
||||||
|
|
||||||
|
|
||||||
|
# Customization of OpenSlides apps
|
||||||
|
|
||||||
|
MOTION_IDENTIFIER_MIN_DIGITS = 1
|
||||||
|
@ -66,6 +66,11 @@ MEDIA_ROOT = os.path.join(OPENSLIDES_USER_DATA_PATH, '')
|
|||||||
SEARCH_INDEX = 'ram'
|
SEARCH_INDEX = 'ram'
|
||||||
|
|
||||||
|
|
||||||
|
# Customization of OpenSlides apps
|
||||||
|
|
||||||
|
MOTION_IDENTIFIER_MIN_DIGITS = 1
|
||||||
|
|
||||||
|
|
||||||
# Special settings only for testing
|
# Special settings only for testing
|
||||||
|
|
||||||
TEST_RUNNER = 'openslides.utils.test.OpenSlidesDiscoverRunner'
|
TEST_RUNNER = 'openslides.utils.test.OpenSlidesDiscoverRunner'
|
||||||
|
@ -66,6 +66,11 @@ MEDIA_ROOT = os.path.join(OPENSLIDES_USER_DATA_PATH, '')
|
|||||||
SEARCH_INDEX = 'ram'
|
SEARCH_INDEX = 'ram'
|
||||||
|
|
||||||
|
|
||||||
|
# Customization of OpenSlides apps
|
||||||
|
|
||||||
|
MOTION_IDENTIFIER_MIN_DIGITS = 1
|
||||||
|
|
||||||
|
|
||||||
# Special settings only for testing
|
# Special settings only for testing
|
||||||
|
|
||||||
TEST_RUNNER = 'openslides.utils.test.OpenSlidesDiscoverRunner'
|
TEST_RUNNER = 'openslides.utils.test.OpenSlidesDiscoverRunner'
|
||||||
|
Loading…
Reference in New Issue
Block a user