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

@ -0,0 +1,73 @@
# Generated by Django 3.2.12 on 2022-02-26 20:24
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
def add_default_themes(apps, schema_editor):
"""add light and dark themes"""
db_alias = schema_editor.connection.alias
theme_model = apps.get_model("bookwyrm", "Theme")
theme_model.objects.using(db_alias).bulk_create(
[
theme_model.objects.using(db_alias)(
name="BookWyrm Light",
path="bookwyrm-light.scss",
),
theme_model.objects.using(db_alias)(
name="BookWyrm Dark",
path="bookwyrm-dark.scss",
),
]
)
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0141_alter_report_status"),
]
operations = [
migrations.CreateModel(
name="Theme",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_date", models.DateTimeField(auto_now_add=True)),
("name", models.CharField(max_length=10, unique=True)),
(
"theme_file",
models.FileField(
upload_to="css/",
validators=[
django.core.validators.FileExtensionValidator(
["scss", "sass"]
)
],
),
),
],
),
migrations.AddField(
model_name="sitesettings",
name="default_theme",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="bookwyrm.theme",
),
),
migrations.RunPython(
add_default_themes, reversed_code=migrations.RunPython.noop
),
]

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"""

View file

@ -1,4 +1,4 @@
@import "../vendor/bulma/sass/utilities/derived-variables.sass";
@import "vendor/bulma/sass/utilities/derived-variables.sass";
/* Colors
******************************************************************************/
@ -51,3 +51,5 @@ $menu-item-active-background-color: $link-background;
******************************************************************************/
$family-primary: $family-sans-serif;
$family-secondary: $family-sans-serif;
@import "bookwyrm.scss";

View file

@ -1,7 +1,6 @@
@charset "utf-8";
@import "instance-settings";
@import "themes/light.scss";
@import "vendor/bulma/bulma.sass";
@import "vendor/icons.css";
@import "bookwyrm/all.scss";

View file

@ -8,7 +8,7 @@
<head>
<title>{% block title %}BookWyrm{% endblock %} - {{ site.name }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="{% sass_src 'css/bookwyrm.scss' %}" rel="stylesheet" type="text/css" />
<link href="{% sass_src 'css/light.scss' %}" rel="stylesheet" type="text/css" />
<link rel="search" type="application/opensearchdescription+xml" href="{% url 'opensearch' %}" title="{% blocktrans with site_name=site.name %}{{ site_name }} search{% endblocktrans %}" />

View file

@ -8,7 +8,7 @@
{% block site-subtabs %}
<ul class="menu-list">
<li><a href="#instance-info">{% trans "Instance Info" %}</a></li>
<li><a href="#images">{% trans "Images" %}</a></li>
<li><a href="#display">{% trans "Display" %}</a></li>
<li><a href="#footer">{% trans "Footer Content" %}</a></li>
<li><a href="#registration">{% trans "Registration" %}</a></li>
</ul>
@ -68,20 +68,35 @@
<hr aria-hidden="true">
<section class="block" id="images">
<h2 class="title is-4">{% trans "Images" %}</h2>
<div class="box is-flex">
<div>
<label class="label" for="id_logo">{% trans "Logo:" %}</label>
{{ site_form.logo }}
<section class="block" id="display">
<h2 class="title is-4">{% trans "Display" %}</h2>
<div class="box">
<h3 class="title is-5">{% trans "Images" %}</h3>
<div class="block is-flex">
<div>
<label class="label" for="id_logo">{% trans "Logo:" %}</label>
{{ site_form.logo }}
</div>
<div>
<label class="label" for="id_logo_small">{% trans "Logo small:" %}</label>
{{ site_form.logo_small }}
</div>
<div>
<label class="label" for="id_favicon">{% trans "Favicon:" %}</label>
{{ site_form.favicon }}
</div>
</div>
<div>
<label class="label" for="id_logo_small">{% trans "Logo small:" %}</label>
{{ site_form.logo_small }}
</div>
<div>
<label class="label" for="id_favicon">{% trans "Favicon:" %}</label>
{{ site_form.favicon }}
<h3 class="title is-5">{% trans "Themes" %}</h3>
<div class="block">
<label class="label" for="id_default_theme">
{% trans "Default theme:" %}
</label>
<div class="select">
{{ site_form.default_theme }}
</div>
<button type="button" class="button">{% trans "Upload theme" %}</button>
</div>
</div>
</section>