Initial commit from ZIP
This commit is contained in:
commit
378d4692a9
454 files changed
+40367
No files matched your search
+63
@@ -0,0 +1,63 @@
|
||||
import os
|
||||
|
||||
from django.db import models
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from rules.contrib.models import RulesModel
|
||||
|
||||
from outbo.apps.core.models import TimestampableDeletableMixin
|
||||
from outbo.apps.final_photobriefing import rules
|
||||
from outbo.apps.final_photobriefing.enums import PhotoType
|
||||
|
||||
|
||||
@deconstructible
|
||||
class FormatFinalPhotoBriefPhotoFilename:
|
||||
def __call__(self, instance, filename):
|
||||
obj = instance.brief.brief
|
||||
return "/".join(
|
||||
("projects", obj.product.project.slug[1:], "final-photobriefing", filename)
|
||||
)
|
||||
|
||||
|
||||
class FinalBrief(TimestampableDeletableMixin, RulesModel):
|
||||
class Meta:
|
||||
rules_permissions = {
|
||||
"add": rules.can_create_final_brief,
|
||||
"view": rules.can_read_final_brief,
|
||||
"change": rules.can_update_final_brief,
|
||||
"delete": rules.can_delete_final_brief,
|
||||
}
|
||||
|
||||
brief = models.OneToOneField(
|
||||
to="photobriefing.Brief",
|
||||
on_delete=models.CASCADE,
|
||||
related_name="final",
|
||||
related_query_name="final",
|
||||
primary_key=True,
|
||||
)
|
||||
|
||||
|
||||
class FinalBriefPhoto(TimestampableDeletableMixin, RulesModel):
|
||||
class Meta:
|
||||
rules_permissions = {
|
||||
"add": rules.can_create_final_brief_photo,
|
||||
"view": rules.can_read_final_brief_photo,
|
||||
"change": rules.can_update_final_brief_photo,
|
||||
"delete": rules.can_delete_final_brief_photo,
|
||||
}
|
||||
|
||||
brief = models.ForeignKey(
|
||||
to=FinalBrief,
|
||||
on_delete=models.CASCADE,
|
||||
related_query_name="photo",
|
||||
related_name="photos",
|
||||
)
|
||||
file = models.FileField(upload_to=FormatFinalPhotoBriefPhotoFilename())
|
||||
type = models.CharField(
|
||||
max_length=30,
|
||||
choices=[(type, type.value) for type in PhotoType],
|
||||
default=PhotoType.INVALID,
|
||||
)
|
||||
|
||||
@property
|
||||
def filename(self):
|
||||
return os.path.basename(self.file.name)
|
||||
Reference in new issue
Block a user