loko/streetup/documents/migrations/0001_initial.py
2026-07-22 14:48:40 +02:00

251 lines
18 KiB
Python

# Generated by Django 5.2.8 on 2026-05-21 13:51
import common.storages
import django.db.models.deletion
import documents.models
import uuid
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('common', '0002_initial'),
('contenttypes', '0002_remove_content_type_name'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='DocumentType',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.SlugField(max_length=64, unique=True, verbose_name='Code')),
('label', models.CharField(max_length=255, verbose_name='Label')),
],
options={
'verbose_name': 'Document type',
'verbose_name_plural': 'Document types',
'ordering': ['label'],
},
),
migrations.CreateModel(
name='DocumentFolder',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('name', models.CharField(max_length=255, verbose_name='Name')),
('slug', models.SlugField(max_length=150, unique=True, verbose_name='Slug')),
('description', models.TextField(blank=True, verbose_name='Description')),
('is_predefined', models.BooleanField(default=False, verbose_name='Predefined')),
('application_label', models.CharField(blank=True, max_length=100, verbose_name='Application label')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated at')),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_folders', to=settings.AUTH_USER_MODEL, verbose_name='Created by')),
('parent_folders', models.ManyToManyField(blank=True, related_name='child_folders', to='documents.documentfolder', verbose_name='Parent folders')),
('thematics', models.ManyToManyField(blank=True, related_name='document_folders', to='common.thematic', verbose_name='Thematics')),
],
options={
'verbose_name': 'Document folder',
'verbose_name_plural': 'Document folders',
'ordering': ['name'],
},
),
migrations.CreateModel(
name='DocumentFolderAccessLink',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('token', models.CharField(editable=False, max_length=64, unique=True)),
('permission', models.CharField(choices=[('view', 'View'), ('comment', 'Comment'), ('edit', 'Edit'), ('approve', 'Approve')], default='view', max_length=20)),
('created_at', models.DateTimeField(auto_now_add=True)),
('expires_at', models.DateTimeField(blank=True, null=True)),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_document_folder_links', to=settings.AUTH_USER_MODEL)),
('folder', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='access_links', to='documents.documentfolder', verbose_name='Folder')),
],
options={
'verbose_name': 'Folder access link',
'verbose_name_plural': 'Folder access links',
},
),
migrations.CreateModel(
name='DocumentTag',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name_fr', models.CharField(max_length=100, unique=True, verbose_name='Name')),
('name_nl', models.CharField(blank=True, max_length=100, null=True, unique=True, verbose_name='Name (NL)')),
('slug', models.SlugField(max_length=120, unique=True, verbose_name='Slug')),
('order', models.PositiveSmallIntegerField(default=0, help_text='Lower values appear first in the document viewer. Tags with the same value are sorted alphabetically.', verbose_name='Display order')),
('is_unique', models.BooleanField(default=False, help_text='If checked, uploading a document with this tag will create a new version of the existing document instead of a new document.', verbose_name='Unique tag')),
('show_in_asset_detail', models.BooleanField(default=False, help_text='If checked, documents with this tag will be displayed in the asset detail page.', verbose_name='Show in asset detail')),
('extra_params_schema', models.JSONField(blank=True, default=list, help_text='JSON list of extra parameter definitions shown in the upload modal when this tag is selected. Supported types: "text", "number", "textarea", "select" (requires "options" list). Example: [{"key": "cables", "label_fr": "Câbles concernés", "label_nl": "Betrokken kabels", "type": "text", "required": false, "placeholder_fr": "Ex: C1, C2"}]', verbose_name='Extra parameters schema')),
('related_content_types', models.ManyToManyField(blank=True, help_text='When set, this tag will only appear for uploads on the selected model types. Leave empty to make it available for all models of the selected thematics.', related_name='document_tags', to='contenttypes.contenttype', verbose_name='Related models')),
('thematics', models.ManyToManyField(blank=True, help_text='Thematics where this tag is available.', related_name='document_tags', to='common.thematic', verbose_name='Thematics')),
],
options={
'verbose_name': 'Tag',
'verbose_name_plural': 'Tags',
'ordering': ['order', 'name_fr'],
},
),
migrations.CreateModel(
name='DocumentVersion',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('upload_date', models.DateTimeField(auto_now=True, verbose_name='Date de téléversement')),
('version_number', models.PositiveIntegerField(verbose_name='Version')),
('file', models.FileField(max_length=255, storage=common.storages.PrivateMediaStorage(), upload_to=documents.models.document_version_upload_to)),
('thumbnail', models.ImageField(blank=True, max_length=255, null=True, storage=common.storages.PrivateMediaStorage(), upload_to=documents.models.document_thumbnail_upload_to)),
('description', models.TextField(blank=True, null=True, verbose_name='Description')),
('uploaded_at', models.DateTimeField(auto_now_add=True, verbose_name='Uploaded at')),
('comment', models.TextField(blank=True, verbose_name='Comment')),
('status', models.CharField(choices=[('draft', 'Draft'), ('pending', 'Pending validation'), ('approved', 'Approved'), ('rejected', 'Rejected')], default='pending', max_length=20)),
('validated_at', models.DateTimeField(blank=True, null=True, verbose_name='Validated at')),
('uploaded_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Document version',
'verbose_name_plural': 'Document versions',
'ordering': ['-version_number'],
},
),
migrations.CreateModel(
name='ManagedDocument',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('title', models.CharField(max_length=255, verbose_name='Title')),
('description', models.TextField(blank=True, verbose_name='Description')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated at')),
('is_archived', models.BooleanField(default=False, verbose_name='Archived')),
('unique_params', models.JSONField(blank=True, default=dict, help_text="Additional parameters to determine uniqueness for documents with unique tags (e.g., {'format': 'pdf', 'cables': 'C1,C2'})", verbose_name='Unique parameters')),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_documents', to=settings.AUTH_USER_MODEL, verbose_name='Created by')),
('current_version', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='current_for_documents', to='documents.documentversion', verbose_name='Current version')),
('folders', models.ManyToManyField(blank=True, related_name='documents', to='documents.documentfolder', verbose_name='Folders')),
('tags', models.ManyToManyField(blank=True, related_name='documents', to='documents.documenttag')),
('types', models.ManyToManyField(blank=True, related_name='documents', to='documents.documenttype')),
],
options={
'verbose_name': 'Managed document',
'verbose_name_plural': 'Managed documents',
'ordering': ['-updated_at', 'title'],
},
),
migrations.AddField(
model_name='documentversion',
name='document',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='versions', to='documents.manageddocument', verbose_name='Document'),
),
migrations.AddField(
model_name='documentversion',
name='managed_document',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(app_label)s_%(class)s_sources', to='documents.manageddocument'),
),
migrations.CreateModel(
name='DocumentAccessLink',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('token', models.CharField(editable=False, max_length=64, unique=True)),
('permission', models.CharField(choices=[('view', 'View'), ('comment', 'Comment'), ('edit', 'Edit'), ('approve', 'Approve')], default='view', max_length=20)),
('created_at', models.DateTimeField(auto_now_add=True)),
('expires_at', models.DateTimeField(blank=True, null=True)),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_document_links', to=settings.AUTH_USER_MODEL)),
('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='access_links', to='documents.manageddocument')),
],
options={
'verbose_name': 'Access link',
'verbose_name_plural': 'Access links',
},
),
migrations.CreateModel(
name='DocumentFolderAttachment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('object_id', models.PositiveIntegerField()),
('is_default', models.BooleanField(default=False, verbose_name='Default folder')),
('attached_at', models.DateTimeField(auto_now_add=True)),
('attached_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='document_folder_attachments', to=settings.AUTH_USER_MODEL)),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
('folder', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='documents.documentfolder')),
],
options={
'verbose_name': 'Folder attachment',
'verbose_name_plural': 'Folder attachments',
'constraints': [models.UniqueConstraint(condition=models.Q(('is_default', True)), fields=('content_type', 'object_id'), name='documents_unique_default_folder_per_object')],
'unique_together': {('folder', 'content_type', 'object_id')},
},
),
migrations.CreateModel(
name='DocumentFolderShare',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('permission', models.CharField(choices=[('view', 'View'), ('comment', 'Comment'), ('edit', 'Edit'), ('approve', 'Approve')], default='view', max_length=20)),
('created_at', models.DateTimeField(auto_now_add=True)),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_document_folder_shares', to=settings.AUTH_USER_MODEL)),
('folder', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='shares', to='documents.documentfolder')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='document_folder_shares', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Folder share',
'verbose_name_plural': 'Folder shares',
'unique_together': {('folder', 'user')},
},
),
migrations.CreateModel(
name='DocumentValidation',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('status', models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected')], default='pending', max_length=20)),
('validated_at', models.DateTimeField(blank=True, null=True)),
('comment', models.TextField(blank=True)),
('role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='document_validations', to='common.role')),
('validated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='document_validations', to=settings.AUTH_USER_MODEL)),
('version', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='validations', to='documents.documentversion')),
],
options={
'verbose_name': 'Validation',
'verbose_name_plural': 'Validations',
'unique_together': {('version', 'role')},
},
),
migrations.AlterUniqueTogether(
name='documentversion',
unique_together={('document', 'version_number')},
),
migrations.CreateModel(
name='DocumentShare',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('permission', models.CharField(choices=[('view', 'View'), ('comment', 'Comment'), ('edit', 'Edit'), ('approve', 'Approve')], default='view', max_length=20)),
('created_at', models.DateTimeField(auto_now_add=True)),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_document_shares', to=settings.AUTH_USER_MODEL)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='document_shares', to=settings.AUTH_USER_MODEL)),
('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='shares', to='documents.manageddocument')),
],
options={
'verbose_name': 'Share',
'verbose_name_plural': 'Shares',
'unique_together': {('document', 'user')},
},
),
migrations.CreateModel(
name='DocumentAttachment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('object_id', models.PositiveIntegerField()),
('attached_at', models.DateTimeField(auto_now_add=True)),
('note', models.CharField(blank=True, max_length=255)),
('attached_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='document_attachments', to=settings.AUTH_USER_MODEL)),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='documents.manageddocument')),
],
options={
'verbose_name': 'Attachment',
'verbose_name_plural': 'Attachments',
'unique_together': {('document', 'content_type', 'object_id')},
},
),
]