diff --git a/app/apps/core/forms.py b/app/apps/core/forms.py index 26a65f8c6cfb9ff3773c77ead6ceb5aec02c6952..fe2297165a55961d4cd1425e5b6f17615e6037e5 100644 --- a/app/apps/core/forms.py +++ b/app/apps/core/forms.py @@ -47,6 +47,7 @@ class DocumentForm(BootstrapFormMixin, forms.ModelForm): self.initial['valid_line_types'] = LineType.objects.filter(default=True) self.fields['project'].queryset = Project.objects.for_user(self.request.user) + self.fields['project'].empty_label = None if self.instance.pk and self.instance.owner != self.request.user: self.fields['project'].disabled = True diff --git a/app/apps/core/migrations/0044_auto_20210427_0946.py b/app/apps/core/migrations/0044_auto_20210427_0946.py deleted file mode 100644 index d68d7b4f7142fb5649ccc26392e1d1eef6506bc5..0000000000000000000000000000000000000000 --- a/app/apps/core/migrations/0044_auto_20210427_0946.py +++ /dev/null @@ -1,39 +0,0 @@ -# Generated by Django 2.2.20 on 2021-04-27 09:46 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('auth', '0011_update_proxy_permissions'), - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('core', '0043_auto_20210324_1016'), - ] - - operations = [ - migrations.AlterField( - model_name='document', - name='read_direction', - field=models.CharField(choices=[('ltr', 'Left to right'), ('rtl', 'Right to left')], default='ltr', help_text='The read direction describes the order of the elements in the document, in opposition with the text direction which describes the order of the words in a line and is set by the script.', max_length=3), - ), - migrations.CreateModel( - name='Project', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=512)), - ('created_at', models.DateTimeField(auto_now_add=True)), - ('updated_at', models.DateTimeField(auto_now=True)), - ('owner', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), - ('shared_with_groups', models.ManyToManyField(blank=True, related_name='shared_projects', to='auth.Group', verbose_name='Share with teams')), - ('shared_with_users', models.ManyToManyField(blank=True, related_name='shared_projects', to=settings.AUTH_USER_MODEL, verbose_name='Share with users')), - ], - ), - migrations.AddField( - model_name='document', - name='project', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Project'), - ), - ] diff --git a/app/apps/core/migrations/0045_project_slug.py b/app/apps/core/migrations/0045_project_slug.py deleted file mode 100644 index 817618e77d1b00a5dfcead4491f762d789faadf3..0000000000000000000000000000000000000000 --- a/app/apps/core/migrations/0045_project_slug.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 2.2.20 on 2021-04-27 10:22 - -import datetime -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0044_auto_20210427_0946'), - ] - - operations = [ - migrations.AddField( - model_name='project', - name='slug', - field=models.SlugField(default=datetime.datetime(2021, 4, 27, 10, 22, 51, 880783)), - preserve_default=False, - ), - ] diff --git a/app/apps/core/migrations/0046_data_share_doc_to_proj.py b/app/apps/core/migrations/0046_data_share_doc_to_proj.py deleted file mode 100644 index 5007decefb9efcc6eb7b0ebcb04f618855399483..0000000000000000000000000000000000000000 --- a/app/apps/core/migrations/0046_data_share_doc_to_proj.py +++ /dev/null @@ -1,81 +0,0 @@ -# Generated by Django 2.2.20 on 2021-05-10 13:06 -import time - -from django.db import migrations -from django.template.defaultfilters import slugify - - -def make_slug(proj, Project): - # models in migrations don't have access to models methods ;( - slug = slugify(proj.name) - # check unicity - exists = Project.objects.filter(slug=slug).count() - if not exists: - proj.slug = slug - else: - proj.slug = slug[:40] + hex(int(time.time()))[2:] - - proj.save() - - -def forwards(apps, schema_editor): - User = apps.get_model('users', 'User') - Project = apps.get_model('core', 'Project') - Document = apps.get_model('core', 'Document') - # create user projects - for user in User.objects.all(): - proj, created = Project.objects.get_or_create(name=user.username+"'s Project", - owner=user) - if not proj.slug: - make_slug(proj, Project) - # move documents into projects - user.document_set.update(project=proj) - # move share from docs to created projects - for doc in user.document_set.all(): - for share in doc.shared_with_users.all(): - proj.shared_with_users.add(share) - for share in doc.shared_with_groups.all(): - proj.shared_with_groups.add(share) - - # shared to draft - user.document_set.filter(workflow_state=1).update(workflow_state=0) - - # deal with documents without owner (shouldn't be any but let's be safe) - # move them to admin's - user = User.objects.filter(is_superuser=True).first() - proj, dummy = Project.objects.get_or_create(name=user.username+"'s Project", - owner=user) - if not proj.slug: - make_slug(proj, Project) - for doc in Document.objects.filter(owner=None): - doc.project = proj - doc.save() - # move share from docs to created projects - for doc in user.document_set.all(): - for share in doc.shared_with_users.all(): - proj.shared_with_users.add(share) - for share in doc.shared_with_groups.all(): - proj.shared_with_groups.add(share) - - -def backwards(apps, schema_editor): - Document = apps.get_model('core', 'Document') - for doc in Document.objects.all(): - if doc.project: - for share in doc.project.shared_with_users.all(): - doc.shared_with_users.add(share) - for share in doc.project.shared_with_groups.all(): - doc.shared_with_groups.add(share) - - Document.objects.update(project=None) - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0045_project_slug'), - ] - - operations = [ - migrations.RunPython(forwards, backwards), - ] diff --git a/app/apps/core/migrations/0047_auto_20210510_1512.py b/app/apps/core/migrations/0047_auto_20210510_1512.py deleted file mode 100644 index e0b7560b07481f384ba4f2565cbb48015ab1e706..0000000000000000000000000000000000000000 --- a/app/apps/core/migrations/0047_auto_20210510_1512.py +++ /dev/null @@ -1,36 +0,0 @@ -# Generated by Django 2.2.20 on 2021-05-10 15:12 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0046_data_share_doc_to_proj'), - ] - - operations = [ - migrations.AlterModelOptions( - name='project', - options={'ordering': ('-updated_at',)}, - ), - migrations.RemoveField( - model_name='document', - name='shared_with_groups', - ), - migrations.RemoveField( - model_name='document', - name='shared_with_users', - ), - migrations.AlterField( - model_name='document', - name='project', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='documents', to='core.Project'), - ), - migrations.AlterField( - model_name='document', - name='workflow_state', - field=models.PositiveSmallIntegerField(choices=[(0, 'Draft'), (2, 'Published'), (3, 'Archived')], default=0), - ), - ] diff --git a/app/apps/core/migrations/0048_auto_20210520_1308.py b/app/apps/core/migrations/0048_auto_20210520_1308.py deleted file mode 100644 index 31bfc70455cc2db516958f3134cf2ceb29e8f11c..0000000000000000000000000000000000000000 --- a/app/apps/core/migrations/0048_auto_20210520_1308.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.2.20 on 2021-05-20 13:08 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0047_auto_20210510_1512'), - ] - - operations = [ - migrations.AlterField( - model_name='document', - name='project', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='documents', to='core.Project'), - ), - ] diff --git a/app/apps/core/models.py b/app/apps/core/models.py index a9fb102b2b42ee563a1b0402b2654604d38f8348..c51b2f073ed21ee367da032543af810469df22c9 100644 --- a/app/apps/core/models.py +++ b/app/apps/core/models.py @@ -149,7 +149,7 @@ class ProjectManager(models.Manager): class Project(models.Model): name = models.CharField(max_length=512) - slug = models.SlugField() + slug = models.SlugField(unique=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True)