Allow disabling the random primary key test mixin
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
3.2.3 (2019-06-XX)
|
||||
==================
|
||||
* Add support for disabling the random primary key
|
||||
test mixin.
|
||||
|
||||
3.2.2 (2019-06-19)
|
||||
==================
|
||||
* Fix document type change view. Closes GitLab issue #614
|
||||
|
||||
103
docs/releases/3.2.3.rst
Normal file
103
docs/releases/3.2.3.rst
Normal file
@@ -0,0 +1,103 @@
|
||||
Version 3.2.3
|
||||
=============
|
||||
|
||||
Released: June XX, 2019
|
||||
|
||||
|
||||
Changes
|
||||
-------
|
||||
|
||||
- Add support for disabling the random primary key
|
||||
test mixin.
|
||||
|
||||
|
||||
Removals
|
||||
--------
|
||||
|
||||
- None
|
||||
|
||||
|
||||
Upgrading from a previous version
|
||||
---------------------------------
|
||||
|
||||
If installed via Python's PIP
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Remove deprecated requirements::
|
||||
|
||||
$ curl https://gitlab.com/mayan-edms/mayan-edms/raw/master/removals.txt | pip uninstall -r /dev/stdin
|
||||
|
||||
Type in the console::
|
||||
|
||||
$ pip install mayan-edms==3.2.1
|
||||
|
||||
the requirements will also be updated automatically.
|
||||
|
||||
|
||||
Using Git
|
||||
^^^^^^^^^
|
||||
|
||||
If you installed Mayan EDMS by cloning the Git repository issue the commands::
|
||||
|
||||
$ git reset --hard HEAD
|
||||
$ git pull
|
||||
|
||||
otherwise download the compressed archived and uncompress it overriding the
|
||||
existing installation.
|
||||
|
||||
Remove deprecated requirements::
|
||||
|
||||
$ pip uninstall -y -r removals.txt
|
||||
|
||||
Next upgrade/add the new requirements::
|
||||
|
||||
$ pip install --upgrade -r requirements.txt
|
||||
|
||||
|
||||
Common steps
|
||||
^^^^^^^^^^^^
|
||||
|
||||
Perform these steps after updating the code from either step above.
|
||||
|
||||
Make a backup of your supervisord file::
|
||||
|
||||
sudo cp /etc/supervisor/conf.d/mayan.conf /etc/supervisor/conf.d/mayan.conf.bck
|
||||
|
||||
Update the supervisord configuration file. Replace the environment
|
||||
variables values show here with your respective settings. This step will refresh
|
||||
the supervisord configuration file with the new queues and the latest
|
||||
recommended layout::
|
||||
|
||||
MAYAN_DATABASE_ENGINE=django.db.backends.postgresql MAYAN_DATABASE_NAME=mayan \
|
||||
MAYAN_DATABASE_PASSWORD=mayanuserpass MAYAN_DATABASE_USER=mayan \
|
||||
MAYAN_DATABASE_HOST=127.0.0.1 MAYAN_MEDIA_ROOT=/opt/mayan-edms/media \
|
||||
/opt/mayan-edms/bin/mayan-edms.py platformtemplate supervisord > /etc/supervisor/conf.d/mayan.conf
|
||||
|
||||
Edit the supervisord configuration file and update any setting the template
|
||||
generator missed::
|
||||
|
||||
vi /etc/supervisor/conf.d/mayan.conf
|
||||
|
||||
Migrate existing database schema with::
|
||||
|
||||
$ mayan-edms.py performupgrade
|
||||
|
||||
Add new static media::
|
||||
|
||||
$ mayan-edms.py preparestatic --noinput
|
||||
|
||||
The upgrade procedure is now complete.
|
||||
|
||||
|
||||
Backward incompatible changes
|
||||
-----------------------------
|
||||
|
||||
- None
|
||||
|
||||
|
||||
Bugs fixed or issues closed
|
||||
---------------------------
|
||||
|
||||
- :gitlab-issue:`615`
|
||||
|
||||
.. _PyPI: https://pypi.python.org/pypi/mayan-edms/
|
||||
@@ -20,6 +20,7 @@ versions of the documentation contain the release notes for any later releases.
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
3.2.3
|
||||
3.2.2
|
||||
3.2.1
|
||||
3.2
|
||||
|
||||
@@ -144,6 +144,7 @@ class RandomPrimaryKeyModelMonkeyPatchMixin(object):
|
||||
random_primary_key_random_floor = 100
|
||||
random_primary_key_random_ceiling = 10000
|
||||
random_primary_key_maximum_attempts = 100
|
||||
random_primary_key_enable = True
|
||||
|
||||
@staticmethod
|
||||
def get_unique_primary_key(model):
|
||||
@@ -170,47 +171,49 @@ class RandomPrimaryKeyModelMonkeyPatchMixin(object):
|
||||
return primary_key
|
||||
|
||||
def setUp(self):
|
||||
self.method_save_original = models.Model.save
|
||||
if self.random_primary_key_enable:
|
||||
self.method_save_original = models.Model.save
|
||||
|
||||
def method_save_new(instance, *args, **kwargs):
|
||||
if instance.pk:
|
||||
return self.method_save_original(instance, *args, **kwargs)
|
||||
else:
|
||||
# Set meta.auto_created to True to have the original save_base
|
||||
# not send the pre_save signal which would normally send
|
||||
# the instance without a primary key. Since we assign a random
|
||||
# primary key any pre_save signal handler that relies on an
|
||||
# empty primary key will fail.
|
||||
# The meta.auto_created and manual pre_save sending emulates
|
||||
# the original behavior. Since meta.auto_created also disables
|
||||
# the post_save signal we must also send it ourselves.
|
||||
# This hack work with Django 1.11 .save_base() but can break
|
||||
# in future versions if that method is updated.
|
||||
pre_save.send(
|
||||
sender=instance.__class__, instance=instance, raw=False,
|
||||
update_fields=None,
|
||||
)
|
||||
instance._meta.auto_created = True
|
||||
instance.pk = RandomPrimaryKeyModelMonkeyPatchMixin.get_unique_primary_key(
|
||||
model=instance._meta.model
|
||||
)
|
||||
instance.id = instance.pk
|
||||
def method_save_new(instance, *args, **kwargs):
|
||||
if instance.pk:
|
||||
return self.method_save_original(instance, *args, **kwargs)
|
||||
else:
|
||||
# Set meta.auto_created to True to have the original save_base
|
||||
# not send the pre_save signal which would normally send
|
||||
# the instance without a primary key. Since we assign a random
|
||||
# primary key any pre_save signal handler that relies on an
|
||||
# empty primary key will fail.
|
||||
# The meta.auto_created and manual pre_save sending emulates
|
||||
# the original behavior. Since meta.auto_created also disables
|
||||
# the post_save signal we must also send it ourselves.
|
||||
# This hack work with Django 1.11 .save_base() but can break
|
||||
# in future versions if that method is updated.
|
||||
pre_save.send(
|
||||
sender=instance.__class__, instance=instance, raw=False,
|
||||
update_fields=None,
|
||||
)
|
||||
instance._meta.auto_created = True
|
||||
instance.pk = RandomPrimaryKeyModelMonkeyPatchMixin.get_unique_primary_key(
|
||||
model=instance._meta.model
|
||||
)
|
||||
instance.id = instance.pk
|
||||
|
||||
result = instance.save_base(force_insert=True)
|
||||
instance._meta.auto_created = False
|
||||
result = instance.save_base(force_insert=True)
|
||||
instance._meta.auto_created = False
|
||||
|
||||
post_save.send(
|
||||
sender=instance.__class__, instance=instance, created=True,
|
||||
update_fields=None, raw=False
|
||||
)
|
||||
post_save.send(
|
||||
sender=instance.__class__, instance=instance, created=True,
|
||||
update_fields=None, raw=False
|
||||
)
|
||||
|
||||
return result
|
||||
return result
|
||||
|
||||
setattr(models.Model, 'save', method_save_new)
|
||||
setattr(models.Model, 'save', method_save_new)
|
||||
super(RandomPrimaryKeyModelMonkeyPatchMixin, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
models.Model.save = self.method_save_original
|
||||
if self.random_primary_key_enable:
|
||||
models.Model.save = self.method_save_original
|
||||
super(RandomPrimaryKeyModelMonkeyPatchMixin, self).tearDown()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user