-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
backend/backend_api/migrations/0060_presentationparticipation_certificate_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Generated by Django 4.2.4 on 2024-01-11 13:39 | ||
|
||
from django.db import migrations, models | ||
import utils.image_uploader | ||
import uuid | ||
|
||
|
||
def set_default_uuid(apps, schema_editor): | ||
workshop_participation = apps.get_model('backend_api', 'workshopregistration') | ||
presentation_participation = apps.get_model('backend_api', 'presentationparticipation') | ||
for instance in presentation_participation.objects.filter(certificate_uuid__isnull=True): | ||
instance.certificate_uuid = uuid.uuid4() | ||
instance.save() | ||
for instance in workshop_participation.objects.filter(certificate_uuid__isnull=True): | ||
instance.certificate_uuid = uuid.uuid4() | ||
instance.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('backend_api', '0059_alter_discount_code_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='presentationparticipation', | ||
name='certificate', | ||
field=models.FileField(default=None, null=True, upload_to=utils.image_uploader.update_certificate_filename), | ||
), | ||
migrations.AddField( | ||
model_name='presentationparticipation', | ||
name='certificate_uuid', | ||
field=models.UUIDField(default=None, editable=False, unique=False, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='workshopregistration', | ||
name='certificate', | ||
field=models.FileField(default=None, null=True, upload_to=utils.image_uploader.update_certificate_filename), | ||
), | ||
migrations.AddField( | ||
model_name='workshopregistration', | ||
name='certificate_uuid', | ||
field=models.UUIDField(default=None, editable=False, unique=False, null=True), | ||
), | ||
migrations.RunPython(set_default_uuid), | ||
migrations.AlterField('presentationparticipation', 'certificate_uuid', | ||
models.UUIDField(default=uuid.uuid4, editable=False, unique=True, null=False)), | ||
migrations.AlterField('workshopregistration', 'certificate_uuid', | ||
models.UUIDField(default=uuid.uuid4, editable=False, unique=True, null=False)), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import os | ||
|
||
|
||
def update_certificate_filename(instance, filename): | ||
path = "certificates/" | ||
if hasattr(instance, "presentation"): | ||
path += "presentation/" | ||
else: | ||
path += "workshop/" | ||
format = instance.certificate_uuid | ||
_, file_extension = os.path.splitext(filename) | ||
return os.path.join(path, str(format) + file_extension) |