From 3d36f1b8289307cd4500b022fdda43cd41845e23 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 15 Mar 2016 01:44:34 -0400 Subject: [PATCH] Update Document model's uuid field to use Django's native UUIDField class. --- HISTORY.rst | 1 + docs/releases/2.1.rst | 8 +++--- .../migrations/0028_newversionblock.py | 13 ++++++++-- .../migrations/0030_auto_20160309_1837.py | 14 +++++++++-- .../documents/migrations/0031_convert_uuid.py | 25 +++++++++++++++++++ .../migrations/0032_auto_20160315_0537.py | 20 +++++++++++++++ mayan/apps/documents/models.py | 4 +-- 7 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 mayan/apps/documents/migrations/0031_convert_uuid.py create mode 100644 mayan/apps/documents/migrations/0032_auto_20160315_0537.py diff --git a/HISTORY.rst b/HISTORY.rst index 3258059bf9..731cf761f7 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -18,6 +18,7 @@ - Add new permission: checkout details view. - Add HTML5 upload widget. Issue #162. - Add Message of the Day app. Issue #222 +- Update Document model's uuid field to use Django's native UUIDField class. 2.0.2 (2016-02-09) ================== diff --git a/docs/releases/2.1.rst b/docs/releases/2.1.rst index 4e64f09a8e..f04f053a49 100644 --- a/docs/releases/2.1.rst +++ b/docs/releases/2.1.rst @@ -7,7 +7,7 @@ Released: April, 2016 What's new ========== -- Upgrade to use Django 1.8.8. +- Upgrade to use Django 1.8.11. - Remove remaining references to Django's User model. - Remove included login required middleware using django-stronghold instead (http://mikegrouchy.com/django-stronghold/). - Improve generation of success and error messages for class based views. @@ -17,8 +17,8 @@ What's new - Implement per document type document creation permission. - Make document type delete time period optional. - Fixed date locale handling in document properties, checkout and user detail views. -- Add HTML5 upload widget. Issue #162. -- Add Message of the Day app. Issue #222 +- Add HTML5 upload widget. +- Add Message of the Day app. Other changes ============= @@ -30,7 +30,7 @@ Other changes - Add new permission: checkout details view. - Add HTML tags stripping to the browser title generation template. - Folder and Tag creation API calls now return the id of the created instances. - +- Update Document model's uuid field to use Django's native UUIDField class. Removals -------- diff --git a/mayan/apps/documents/migrations/0028_newversionblock.py b/mayan/apps/documents/migrations/0028_newversionblock.py index 8fbc1e35a3..98e809aaa3 100644 --- a/mayan/apps/documents/migrations/0028_newversionblock.py +++ b/mayan/apps/documents/migrations/0028_newversionblock.py @@ -14,8 +14,17 @@ class Migration(migrations.Migration): migrations.CreateModel( name='NewVersionBlock', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('document', models.ForeignKey(verbose_name='Document', to='documents.Document')), + ( + 'id', models.AutoField( + verbose_name='ID', serialize=False, auto_created=True, + primary_key=True + ) + ), + ( + 'document', models.ForeignKey( + verbose_name='Document', to='documents.Document' + ) + ), ], options={ 'verbose_name': 'New version block', diff --git a/mayan/apps/documents/migrations/0030_auto_20160309_1837.py b/mayan/apps/documents/migrations/0030_auto_20160309_1837.py index 9712f700ed..7083daa277 100644 --- a/mayan/apps/documents/migrations/0030_auto_20160309_1837.py +++ b/mayan/apps/documents/migrations/0030_auto_20160309_1837.py @@ -14,11 +14,21 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='documenttype', name='delete_time_period', - field=models.PositiveIntegerField(default=30, help_text='Amount of time after which documents of this type in the trash will be deleted.', null=True, verbose_name='Delete time period', blank=True), + field=models.PositiveIntegerField( + default=30, help_text='Amount of time after which documents ' + 'of this type in the trash will be deleted.', null=True, + verbose_name='Delete time period', blank=True + ), ), migrations.AlterField( model_name='documenttype', name='delete_time_unit', - field=models.CharField(default='days', choices=[('days', 'Days'), ('hours', 'Hours'), ('minutes', 'Minutes')], max_length=8, blank=True, null=True, verbose_name='Delete time unit'), + field=models.CharField( + default='days', choices=[ + ('days', 'Days'), ('hours', 'Hours'), + ('minutes', 'Minutes') + ], max_length=8, blank=True, null=True, + verbose_name='Delete time unit' + ), ), ] diff --git a/mayan/apps/documents/migrations/0031_convert_uuid.py b/mayan/apps/documents/migrations/0031_convert_uuid.py new file mode 100644 index 0000000000..28edb9d746 --- /dev/null +++ b/mayan/apps/documents/migrations/0031_convert_uuid.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +import uuid + +from django.db import migrations, models + + +def convert_uuid_to_hex(apps, schema_editor): + Document = apps.get_model('documents', 'Document') + + for document in Document.objects.all(): + document.uuid = uuid.UUID(document.uuid).hex + document.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('documents', '0030_auto_20160309_1837'), + ] + + operations = [ + migrations.RunPython(convert_uuid_to_hex), + ] diff --git a/mayan/apps/documents/migrations/0032_auto_20160315_0537.py b/mayan/apps/documents/migrations/0032_auto_20160315_0537.py new file mode 100644 index 0000000000..0e413efaca --- /dev/null +++ b/mayan/apps/documents/migrations/0032_auto_20160315_0537.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('documents', '0031_convert_uuid'), + ] + + operations = [ + migrations.AlterField( + model_name='document', + name='uuid', + field=models.UUIDField(default=uuid.uuid4, editable=False), + ), + ] diff --git a/mayan/apps/documents/models.py b/mayan/apps/documents/models.py index ab8b417b17..d3cb6a8cd5 100644 --- a/mayan/apps/documents/models.py +++ b/mayan/apps/documents/models.py @@ -149,9 +149,7 @@ class Document(models.Model): Defines a single document with it's fields and properties """ - uuid = models.CharField( - default=UUID_FUNCTION, editable=False, max_length=48 - ) + uuid = models.UUIDField(default=uuid.uuid4, editable=False) document_type = models.ForeignKey( DocumentType, related_name='documents', verbose_name=_('Document type')