phantasma/app/video/models.py
2022-01-27 14:42:48 +00:00

83 lines
2.4 KiB
Python

import logging
import json
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models import Q
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)
featured = models.BooleanField(default=False)
position = models.IntegerField(default=0)
pandora_url = models.CharField(max_length=1024)
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 + 'video/' + self.slug
def related_texts(self):
from ..text.models import Text
folder = self.data.get('title')
if folder:
return Text.objects.filter(Q(data__folder=folder) | Q(data__related=folder))
def duration_seconds(self):
duration = 0
for item in self.data.get('items', []):
duration += item['duration']
return duration
def duration(self):
return ox.format_duration(self.data['duration'] * 1000, verbosity=1, milliseconds=False)
def color_1(self):
hue = self.data['hue']
saturation = self.data['saturation'] * 100
saturation = 70
lightness = self.data['lightness'] * 100
return "hsl({}, {}%, {}%)".format(hue, saturation, lightness)
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)
def json(self):
data = {}
data['url'] = self.pandora_url
#data.update(self.data)
return json.dumps(data)