Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 1fbec550 authored by Robin Tissot's avatar Robin Tissot
Browse files

Cleanup migration files and fix document form.

parent 18e190f4
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
# 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'),
),
]
# 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,
),
]
# 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),
]
# 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),
),
]
# 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'),
),
]
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment