diff options
author | Christian Pointner <equinox@helsinki.at> | 2021-06-15 20:52:55 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2021-06-15 20:52:55 (GMT) |
commit | 09276cc47736785e7a2784172a2cf3663de4e57e (patch) | |
tree | 202b46bfc67595a64bda7aa4ac359e0957b09189 /program/models.py | |
parent | b2415eb92622563f567106e2c4951ed498273e53 (diff) | |
parent | 88fb9a1d5bc7dc5f22d96fcee970f4ec9f88b289 (diff) |
Merge branch 'topic/new-show-and-note-images' into stable
Diffstat (limited to 'program/models.py')
-rw-r--r-- | program/models.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/program/models.py b/program/models.py index b5123cb..ecebda8 100644 --- a/program/models.py +++ b/program/models.py @@ -1,3 +1,4 @@ +import os from django.contrib.auth.models import User from django.core.exceptions import ObjectDoesNotExist, ValidationError, MultipleObjectsReturned from django.core.urlresolvers import reverse @@ -11,7 +12,7 @@ from datetime import date, datetime, time, timedelta from dateutil.relativedelta import relativedelta from dateutil.rrule import rrule -from utils import get_automation_id_choices +from utils import get_automation_id_choices, hash_file class BroadcastFormat(models.Model): @@ -243,6 +244,12 @@ class Host(models.Model): return self.shows.filter(programslots__until__gt=datetime.today).distinct() +def show_image_filename(instance, filename): + instance.image.open() + filename_base, filename_ext = os.path.splitext(filename) + return "shows/%s/%s%s" % (instance.slug, hash_file(instance.image.file), filename_ext) + + class Show(models.Model): predecessor = models.ForeignKey('self', blank=True, null=True, related_name='successors', verbose_name=_("Predecessor")) hosts = models.ManyToManyField(Host, blank=True, related_name='shows', verbose_name=_("Hosts")) @@ -254,8 +261,7 @@ class Show(models.Model): musicfocus = models.ManyToManyField(MusicFocus, blank=True, related_name='shows', verbose_name=_("Music focus")) name = models.CharField(_("Name"), max_length=255) slug = models.CharField(_("Slug"), max_length=255, unique=True) - image = models.ImageField(_("Image"), blank=True, null=True, upload_to='show_images') - image_enabled = models.BooleanField(_("show Image"), default=True) + image = models.ImageField(_("Image"), max_length=350, blank=True, null=True, upload_to=show_image_filename) short_description = models.CharField(_("Short description"), max_length=64) description = tinymce_models.HTMLField(_("Description"), blank=True, null=True) email = models.EmailField(_("E-Mail"), blank=True, null=True) @@ -492,7 +498,14 @@ class TimeSlot(models.Model): return reverse('timeslot-detail', args=[str(self.id)]) +def note_image_filename(instance, filename): + instance.image.open() + filename_base, filename_ext = os.path.splitext(filename) + return "notes/%s/%s%s" % (instance.show.slug, hash_file(instance.image.file), filename_ext) + + class Note(models.Model): + STATUS_CHOICES = ( (0, _("Cancellation")), (1, _("Recommendation")), @@ -500,6 +513,7 @@ class Note(models.Model): ) timeslot = models.OneToOneField(TimeSlot, verbose_name=_("Time slot")) title = models.CharField(_("Title"), max_length=128) + image = models.ImageField(_("Image"), max_length=350, blank=True, null=True, upload_to=note_image_filename) content = tinymce_models.HTMLField(_("Content")) status = models.IntegerField(_("Status"), choices=STATUS_CHOICES, default=1) start = models.DateTimeField(editable=False) |