Use selected theme
This commit is contained in:
@ -26,7 +26,7 @@ from .group import Group, GroupMember, GroupMemberInvitation
|
||||
|
||||
from .import_job import ImportJob, ImportItem
|
||||
|
||||
from .site import SiteSettings, SiteInvite
|
||||
from .site import SiteSettings, Theme, SiteInvite
|
||||
from .site import PasswordReset, InviteRequest
|
||||
from .announcement import Announcement
|
||||
from .antispam import EmailBlocklist, IPBlocklist, AutoMod, automod_task
|
||||
|
@ -112,7 +112,7 @@ class Theme(models.Model):
|
||||
"""Theme files"""
|
||||
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
name = models.CharField(max_length=10, unique=True)
|
||||
name = models.CharField(max_length=50, unique=True)
|
||||
theme_file = models.FileField(
|
||||
upload_to="css/",
|
||||
validators=[FileExtensionValidator(["scss", "sass"])],
|
||||
@ -120,15 +120,13 @@ class Theme(models.Model):
|
||||
)
|
||||
path = models.CharField(max_length=50, blank=True, null=True)
|
||||
|
||||
@classmethod
|
||||
def get_theme(cls, user):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@property
|
||||
def theme_path(self):
|
||||
"""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"
|
||||
return self.theme_file.path if self.theme_file else self.path
|
||||
|
||||
|
||||
class SiteInvite(models.Model):
|
||||
|
@ -136,6 +136,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
||||
updated_date = models.DateTimeField(auto_now=True)
|
||||
last_active_date = models.DateTimeField(default=timezone.now)
|
||||
manually_approves_followers = fields.BooleanField(default=False)
|
||||
theme = models.ForeignKey("Theme", null=True, blank=True, on_delete=models.SET_NULL)
|
||||
|
||||
# options to turn features on and off
|
||||
show_goal = models.BooleanField(default=True)
|
||||
@ -172,6 +173,19 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
||||
property_fields = [("following_link", "following")]
|
||||
field_tracker = FieldTracker(fields=["name", "avatar"])
|
||||
|
||||
@property
|
||||
def get_theme(self):
|
||||
"""get the theme given the user/site"""
|
||||
if self.theme:
|
||||
path = self.theme.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"
|
||||
return f"css/{path}"
|
||||
|
||||
@property
|
||||
def confirmation_link(self):
|
||||
"""helper for generating confirmation links"""
|
||||
|
Reference in New Issue
Block a user