themes/models.py

43 lines
1.3 KiB
Python
Raw Normal View History

2020-01-26 21:01:31 +01:00
from django.db import models
from . import available_themes, default_theme
from PIL import Image
class Setting(models.Model):
page_image = models.ImageField(
upload_to='theme',
default='theme/logo.png'
)
page_theme = models.CharField(
max_length=64,
choices=available_themes,
default=default_theme
)
page_title = models.CharField(max_length=32, default='MyApp', blank=True)
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
img = Image.open(self.page_image.path)
if img.height > 50:
output_size = (int(img.width * 50 / img.height), 50)
img.thumbnail(output_size)
img.save(self.page_image.path)
class BottomBar(models.Model):
name = models.CharField(max_length=64, blank=True)
icon = models.ImageField(upload_to='theme', blank=True)
url = models.URLField()
left = models.BooleanField()
sequence_number = models.SmallIntegerField(choices=[(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5')])
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
if self.icon:
img = Image.open(self.icon.path)
if img.height > 40:
output_size = (int(img.width * 40 / img.height), 40)
img.thumbnail(output_size)
img.save(self.icon.path)