Adds themes

This commit is contained in:
Mouse Reeve
2022-02-26 12:43:27 -08:00
parent ab1c7c6d0a
commit e15193e100
7 changed files with 133 additions and 17 deletions

View File

@ -3,6 +3,7 @@ import datetime
from urllib.parse import urljoin
import uuid
from django.core.validators import FileExtensionValidator
from django.db import models, IntegrityError
from django.dispatch import receiver
from django.utils import timezone
@ -24,6 +25,9 @@ class SiteSettings(models.Model):
)
instance_description = models.TextField(default="This instance has no description.")
instance_short_description = models.CharField(max_length=255, blank=True, null=True)
default_theme = models.ForeignKey(
"Theme", null=True, blank=True, on_delete=models.SET_NULL
)
# admin setup options
install_mode = models.BooleanField(default=False)
@ -104,6 +108,29 @@ class SiteSettings(models.Model):
super().save(*args, **kwargs)
class Theme(models.Model):
"""Theme files"""
created_date = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=10, unique=True)
theme_file = models.FileField(
upload_to="css/",
validators=[FileExtensionValidator(["scss", "sass"])],
null=True,
)
path = models.CharField(max_length=50, blank=True, null=True)
@classmethod
def get_theme(cls, user):
"""get the theme given the user/site"""
if user and user.theme:
return user.theme.path
site = SiteSettings.objects.get()
if site.theme:
return site.theme.path
return "light.scss"
class SiteInvite(models.Model):
"""gives someone access to create an account on the instance"""