Skip to content

Commit

Permalink
Domain banners, branding updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dcwatson committed Apr 30, 2024
1 parent 6984749 commit 9e8821d
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
def config_context(request):
return {
"config": Config.system,
"config_domain": request.domain.config_domain if request.domain else None,
"allow_migration": settings.SETUP.ALLOW_USER_MIGRATION,
"top_section": request.path.strip("/").split("/")[0],
"opengraph_defaults": {
Expand Down
7 changes: 5 additions & 2 deletions core/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,16 @@ def set_domain(cls, domain, key, value):
)

class SystemOptions(pydantic.BaseModel):
system_name: str = "Incarnator"
system_link: str = "https://github.com/avaraline/incarnator"
version: str = __version__

system_actor_public_key: str = ""
system_actor_private_key: str = ""

site_name: str = "Takahē"
site_name: str = "Incarnator"
highlight_color: str = "#449c8c"
site_about: str = "<h2>Welcome!</h2>\n\nThis is a community running Takahē."
site_about: str = "<h2>Welcome!</h2>\n\nThis is a community running Incarnator."
site_frontpage_posts: bool = True
site_icon: UploadedImage = StaticAbsoluteUrl("img/icon-128.png").relative # type: ignore
site_banner: UploadedImage = StaticAbsoluteUrl(
Expand Down Expand Up @@ -251,6 +253,7 @@ class IdentityOptions(pydantic.BaseModel):
class DomainOptions(pydantic.BaseModel):
site_name: str = ""
site_icon: UploadedImage | None = None
site_banner: UploadedImage | None = None
hide_login: bool = False
custom_css: str = ""
single_user: str = ""
2 changes: 1 addition & 1 deletion docs/_templates/sidebar/brand.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% block brand_content %}
{%- if logo_url %}
<div class="sidebar-logo-container">
<img class="sidebar-logo" src="{{ logo_url }}" alt="Takahē"/>
<img class="sidebar-logo" src="{{ logo_url }}" alt="{{ config.system_name }}"/>
</div>
{%- endif %}
{%- if theme_light_logo and theme_dark_logo %}
Expand Down
2 changes: 1 addition & 1 deletion takahe/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.11.0"
__version__ = "0.12.0"
2 changes: 1 addition & 1 deletion templates/_footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
{% if config.policy_terms %}<a href="{% url "policy_terms" %}">Terms&nbsp;of&nbsp;Service</a>{% endif %}
{% if config.policy_privacy %}<a href="{% url "policy_privacy" %}">Privacy&nbsp;Policy</a>{% endif %}
{% if config.policy_issues %}<a href="{% url "policy_issues" %}">Report a Problem</a>{% endif %}
<a href="https://jointakahe.org">Takahē&nbsp;{{ config.version }}</a>
<a href="{{ config.system_link }}">{{ config.system_name }}&nbsp;{{ config.version }}</a>
</footer>
2 changes: 1 addition & 1 deletion templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block content %}
<section class="markdown">
<img class="banner" src="{{ config.site_banner }}">
<img class="banner" src="{{ config_domain.site_banner|default_if_none:config.site_banner }}">
{{ content }}
</section>

Expand Down
2 changes: 1 addition & 1 deletion templates/admin/domain_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1>Add A Domain</h1>
on.
</p>
<p>
Takahē supports multiple domains per server, but note that when
Multiple domains per server are supported, but note that when
identities are created they are <b>fixed to their chosen domain</b>,
and you will <b>not be able to delete a domain with identities on it</b>.
</p>
Expand Down
1 change: 1 addition & 0 deletions templates/admin/domain_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<legend>Appearance</legend>
{% include "forms/_field.html" with field=form.site_name %}
{% include "forms/_field.html" with field=form.site_icon %}
{% include "forms/_field.html" with field=form.site_banner %}
{% include "forms/_field.html" with field=form.hide_login %}
{% include "forms/_field.html" with field=form.single_user %}
{% include "forms/_field.html" with field=form.custom_css %}
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{% endblock %} - {{ config.site_name }}</title>
<title>{% block title %}{% endblock %} - {{ config_domain.site_name }}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
{% load static %}
Expand Down
22 changes: 18 additions & 4 deletions users/views/admin/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class DomainValidator(RegexValidator):
r"(?<!-)" # can't end with a dash
r"\.?" # may have a trailing dot
)
regex = "^" + hostname_re + domain_re + tld_re + "$"
port_re = r"(?:\:\d+)"
regex = "^" + hostname_re + domain_re + tld_re + port_re + "$"
message = "This does not look like a domain name"


Expand Down Expand Up @@ -168,6 +169,11 @@ class form_class(DomainCreate.form_class):
help_text="Override the site icon for this domain",
)

site_banner = forms.ImageField(
required=False,
help_text="Override the site banner for this domain",
)

hide_login = forms.BooleanField(
help_text="If the login button should appear in the header for this domain",
widget=forms.Select(choices=[(False, "Show"), (True, "Hide")]),
Expand Down Expand Up @@ -222,10 +228,19 @@ def form_valid(self, form):
Domain.objects.exclude(pk=self.domain.pk).update(default=False)
Config.set_domain(self.domain, "hide_login", form.cleaned_data["hide_login"])
Config.set_domain(self.domain, "site_name", form.cleaned_data["site_name"])

if self.request.POST.get("site_icon__clear"):
Config.set_domain(self.domain, "site_icon", None)
if isinstance(form.cleaned_data["site_icon"], File):
Config.set_domain(self.domain, "site_icon", form.cleaned_data["site_icon"])

if self.request.POST.get("site_banner__clear"):
Config.set_domain(self.domain, "site_banner", None)
if isinstance(form.cleaned_data["site_banner"], File):
Config.set_domain(
self.domain, "site_banner", form.cleaned_data["site_banner"]
)

Config.set_domain(self.domain, "custom_css", form.cleaned_data["custom_css"])
Config.set_domain(self.domain, "single_user", form.cleaned_data["single_user"])
messages.success(self.request, f"Domain {self.domain} saved.")
Expand All @@ -241,6 +256,7 @@ def get_initial(self):
"users": "\n".join(sorted(user.email for user in self.domain.users.all())),
"site_name": self.domain.config_domain.site_name,
"site_icon": self.domain.config_domain.site_icon,
"site_banner": self.domain.config_domain.site_banner,
"hide_login": self.domain.config_domain.hide_login,
"custom_css": self.domain.config_domain.custom_css,
"single_user": self.domain.config_domain.single_user,
Expand All @@ -252,9 +268,7 @@ class DomainDelete(TemplateView):
template_name = "admin/domain_delete.html"

def dispatch(self, request, domain):
self.domain = get_object_or_404(
Domain.objects.filter(public=True), domain=domain
)
self.domain = get_object_or_404(Domain, domain=domain, local=True)
return super().dispatch(request)

def get_context_data(self):
Expand Down

0 comments on commit 9e8821d

Please sign in to comment.