import logging import json from django.conf import settings from django.contrib.auth import get_user_model from django.db import models import ox logger = logging.getLogger(__name__) User = get_user_model() class Film(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) slug = models.SlugField() public = models.BooleanField(default=False) position = models.IntegerField(default=0) padma_id = models.CharField(max_length=255) vimeo_id = models.CharField(max_length=255, default=None, blank=True) data = models.JSONField(default=dict, blank=True) def __str__(self): return self.data.get('title', self.slug) def get_absolute_url(self): return '/' + settings.URL_PREFIX + 'film/' + self.slug def related_texts(self): from ..text.models import Text return Text.objects.filter(data__item=self.padma_id) def duration(self): return ox.format_timecode(self.data['duration'])[:-4] def color(self): hue = self.data['hue'] saturation = self.data['saturation'] * 100 saturation = 70 lightness = self.data['lightness'] * 100 return "hsl({}, {}%, {}%)".format(hue, saturation, lightness) def json(self): data = {} data['id'] = self.padma_id #data.update(self.data) return json.dumps(data) class Edit(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) slug = models.SlugField() public = models.BooleanField(default=False) padma_id = models.CharField(max_length=1024) annotation_user = models.CharField(max_length=1024) vimeo_id = models.CharField(max_length=255, default=None, null=True) data = models.JSONField(default=dict, blank=True) def __str__(self): return self.data.get('title', self.slug)