Theme selector

This commit is contained in:
Mouse Reeve
2022-02-27 10:00:50 -08:00
parent 6e96c1eee7
commit 3dfbb3272e
11 changed files with 184 additions and 34 deletions

View File

@ -3,7 +3,6 @@ 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
@ -113,22 +112,12 @@ class Theme(models.Model):
created_date = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=50, 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)
path = models.CharField(max_length=50, unique=True)
def __str__(self):
# pylint: disable=invalid-str-returned
return self.name
@property
def theme_path(self):
"""get the theme given the user/site"""
return self.theme_file.path if self.theme_file else self.path
class SiteInvite(models.Model):
"""gives someone access to create an account on the instance"""

View File

@ -176,14 +176,14 @@ class User(OrderedCollectionPageMixin, AbstractUser):
@property
def get_theme(self):
"""get the theme given the user/site"""
path = "bookwyrm-light.scss"
if self.theme:
path = self.theme.theme_path
path = self.theme.path
else:
site_model = apps.get_model("bookwyrm", "SiteSettings", require_ready=True)
site = site_model.objects.get()
if site.default_theme:
path = site.default_theme.theme_path
path = path or "light.scss"
path = site.default_theme.path
return f"css/{path}"
@property