2021-09-28 13:10:22 +00:00
|
|
|
import logging
|
2021-10-11 14:38:22 +00:00
|
|
|
import json
|
2021-09-28 13:10:22 +00:00
|
|
|
|
2021-10-11 12:55:45 +00:00
|
|
|
from django.conf import settings
|
2021-09-28 13:10:22 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.db import models
|
2021-10-22 16:15:06 +00:00
|
|
|
from django.db.models import Q
|
2021-09-28 13:10:22 +00:00
|
|
|
|
2021-10-11 14:33:24 +00:00
|
|
|
import ox
|
|
|
|
|
2021-09-28 13:10:22 +00:00
|
|
|
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)
|
2021-11-22 12:59:43 +00:00
|
|
|
featured = models.BooleanField(default=False)
|
2021-10-11 12:55:45 +00:00
|
|
|
position = models.IntegerField(default=0)
|
2021-09-28 13:10:22 +00:00
|
|
|
|
2021-11-12 10:21:00 +00:00
|
|
|
pandora_url = models.CharField(max_length=1024)
|
2021-09-28 13:10:22 +00:00
|
|
|
|
|
|
|
data = models.JSONField(default=dict, blank=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.data.get('title', self.slug)
|
|
|
|
|
2021-10-10 15:06:43 +00:00
|
|
|
def get_absolute_url(self):
|
2021-11-21 09:40:52 +00:00
|
|
|
return '/' + settings.URL_PREFIX + 'video/' + self.slug
|
2021-10-10 15:06:43 +00:00
|
|
|
|
|
|
|
def related_texts(self):
|
|
|
|
from ..text.models import Text
|
2021-11-12 10:21:00 +00:00
|
|
|
folder = self.data.get('title')
|
|
|
|
if folder:
|
|
|
|
return Text.objects.filter(Q(data__folder=folder) | Q(data__related=folder))
|
2021-10-10 15:06:43 +00:00
|
|
|
|
2021-10-11 14:33:24 +00:00
|
|
|
def duration(self):
|
2021-10-21 13:21:06 +00:00
|
|
|
return ox.format_duration(self.data['duration'] * 1000, verbosity=1, milliseconds=False)
|
2021-09-28 13:10:22 +00:00
|
|
|
|
2021-10-13 15:54:25 +00:00
|
|
|
def color_1(self):
|
2021-10-13 15:35:47 +00:00
|
|
|
hue = self.data['hue']
|
|
|
|
saturation = self.data['saturation'] * 100
|
|
|
|
saturation = 70
|
|
|
|
lightness = self.data['lightness'] * 100
|
|
|
|
return "hsl({}, {}%, {}%)".format(hue, saturation, lightness)
|
2021-10-11 14:38:22 +00:00
|
|
|
|
2021-10-13 15:54:25 +00:00
|
|
|
def color_2(self):
|
|
|
|
hue = self.data['hue']
|
|
|
|
saturation = self.data['saturation'] * 100
|
|
|
|
saturation = 70
|
|
|
|
lightness = self.data['lightness'] * 50
|
|
|
|
return "hsl({}, {}%, {}%)".format(hue, saturation, lightness)
|
|
|
|
|
|
|
|
def color_3(self):
|
|
|
|
hue = self.data['hue']
|
|
|
|
saturation = self.data['saturation'] * 100
|
|
|
|
saturation = 70
|
|
|
|
lightness = self.data['lightness'] * 110
|
|
|
|
return "hsl({}, {}%, {}%)".format(hue, saturation, lightness)
|
|
|
|
|
|
|
|
def color_4(self):
|
|
|
|
hue = self.data['hue']
|
|
|
|
saturation = self.data['saturation'] * 100
|
|
|
|
saturation = 70
|
|
|
|
lightness = self.data['lightness'] * 80
|
|
|
|
return "hsl({}, {}%, {}%)".format(hue, saturation, lightness)
|
|
|
|
|
2021-10-11 14:38:22 +00:00
|
|
|
def json(self):
|
|
|
|
data = {}
|
2021-11-12 10:21:00 +00:00
|
|
|
data['url'] = self.pandora_url
|
2021-10-13 15:35:47 +00:00
|
|
|
#data.update(self.data)
|
2021-10-11 14:38:22 +00:00
|
|
|
return json.dumps(data)
|
|
|
|
|
|
|
|
|