Skip to content

Commit

Permalink
Add Option to specify tenant logo
Browse files Browse the repository at this point in the history
  • Loading branch information
pehala committed Jan 12, 2024
1 parent dd835bd commit 7cdf259
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 26 deletions.
6 changes: 3 additions & 3 deletions backend/locale/cs/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-12-29 14:14+0000\n"
"POT-Creation-Date: 2024-01-12 15:11+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -136,11 +136,11 @@ msgstr "Smazat"
msgid "Transpose"
msgstr "Transponovat"

#: backend/templates/songs/index.html:91
#: backend/templates/songs/index.html:97
msgid "Search"
msgstr "Vyhledávání"

#: backend/templates/songs/index.html:93
#: backend/templates/songs/index.html:99
msgid "Number, text or author"
msgstr "Číslo, text nebo autor"

Expand Down
19 changes: 19 additions & 0 deletions category/migrations/0012_alter_category_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0 on 2024-01-12 14:46

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("category", "0011_alter_category_options"),
]

operations = [
migrations.AlterField(
model_name="category",
name="link",
field=models.CharField(
blank=True, help_text="Link to include in the PDF", max_length=300, verbose_name="Link"
),
),
]
18 changes: 11 additions & 7 deletions frontend/locale/cs/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-12-29 14:14+0000\n"
"POT-Creation-Date: 2024-01-12 15:11+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -73,27 +73,31 @@ msgstr ""
msgid "Submit"
msgstr "Odeslat"

#: frontend/templates/base/index.html:58
#: frontend/templates/base/index.html:35
msgid "Logo"
msgstr ""

#: frontend/templates/base/index.html:64
msgid "Options"
msgstr "Možnosti"

#: frontend/templates/base/index.html:68
#: frontend/templates/base/index.html:74
msgid "Language"
msgstr "Jazyk"

#: frontend/templates/base/index.html:82
#: frontend/templates/base/index.html:88
msgid "Version"
msgstr "Verze"

#: frontend/templates/base/index.html:83
#: frontend/templates/base/index.html:89
msgid "Git"
msgstr ""

#: frontend/templates/base/index.html:91
#: frontend/templates/base/index.html:97
msgid "Logged as"
msgstr "Přihlášen jako"

#: frontend/templates/base/index.html:93
#: frontend/templates/base/index.html:99
msgid "Log in"
msgstr "Přihlásit se"

Expand Down
Binary file removed frontend/static/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion frontend/templates/base/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load django_bootstrap5 %}

{% block framed_body %}
<form method="post">
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{% bootstrap_form form layout='horizontal' %}
{% bootstrap_button _("Submit") button_type="submit" %}
Expand Down
10 changes: 8 additions & 2 deletions frontend/templates/base/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<html lang="en">
<head>
<title>{% block title %} {{ request.tenant.display_name }} {% endblock %}</title>
<link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}"/>
{% if request.tenant.icon %}
<link rel="shortcut icon" type="image/png" href="{{ request.tenant.icon.url }}"/>
{% endif %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
Expand All @@ -28,7 +30,11 @@
<body>
<div>
<nav class="navbar navbar-expand-lg">
<a class="navbar-brand ms-3" href="{{ request.tenant.index_redirect }}">{{ request.tenant.display_name }}</a>
<a class="navbar-brand ms-3" href="{{ request.tenant.index_redirect }}">
{% if request.tenant.icon %}
<img src="{{ request.tenant.icon.url }}" alt="{{ _("Logo") }}" width="30" height="30"/>
{% endif %}
{{ request.tenant.display_name }}</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
Expand Down
1 change: 0 additions & 1 deletion pdf/locale/cs/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,3 @@ msgstr "Musíte vybrat alespoň jednu písničku"
#, python-format
msgid "PDF Request with id %(id)s was successfully created"
msgstr "PDF požadavek se id %(id)s byl úspěšně vytvořen"

19 changes: 19 additions & 0 deletions pdf/migrations/0024_alter_pdfrequest_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0 on 2024-01-12 14:46

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("pdf", "0023_alter_pdfrequest_file"),
]

operations = [
migrations.AlterField(
model_name="pdfrequest",
name="link",
field=models.CharField(
blank=True, help_text="Link to include in the PDF", max_length=300, verbose_name="Link"
),
),
]
36 changes: 25 additions & 11 deletions tenants/locale/cs/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-12-01 13:46+0000\n"
"POT-Creation-Date: 2024-01-12 15:18+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -23,7 +23,7 @@ msgstr ""
msgid "Tenant"
msgstr "Zpěvník"

#: tenants/menus.py:27 tenants/models.py:24
#: tenants/menus.py:27 tenants/models.py:30
msgid "All Songs"
msgstr "Všechno"

Expand All @@ -35,44 +35,58 @@ msgstr "Soubory"
msgid "Categories"
msgstr "Kategorie"

#: tenants/models.py:13
#: tenants/models.py:12
msgid "Only PNG images are allowed"
msgstr "Jen PNG obrázky jsou podporovány"

#: tenants/models.py:19
msgid "Hostname"
msgstr "Doménové jméno"

#: tenants/models.py:13
#: tenants/models.py:19
msgid "The exact hostname for this Tenant"
msgstr "Přesné doménové jméno pod kterým bude Zpěvník dostupný"

#: tenants/models.py:15
#: tenants/models.py:21
msgid "Name"
msgstr "Jméno"

#: tenants/models.py:15
#: tenants/models.py:21
msgid "Internal name for this Tenant"
msgstr "Interní název tohoto Zpevníku"

#: tenants/models.py:16
#: tenants/models.py:22
msgid "Title"
msgstr "Titulek"

#: tenants/models.py:16
#: tenants/models.py:22
msgid "Title on the Main site"
msgstr "Titulek na hlavní stránce"

#: tenants/models.py:18
#: tenants/models.py:24
msgid "Index redirect path"
msgstr "Cíl přesměrování úvodní stránky"

#: tenants/models.py:19
#: tenants/models.py:25
msgid ""
"Where should new tenant redirect from index page, usually a category slug"
msgstr ""
"Kam by měla úvodní stránka přesměrovat uživatele, většinou URL kategorie"

#: tenants/models.py:25
#: tenants/models.py:31
msgid "True, if all songs category should be added to navigation"
msgstr "Pokud je zaškrknuto tak se do navigace přidá odkaz na všechny písničky"

#: tenants/models.py:34
msgid "Logo"
msgstr ""

#: tenants/models.py:35
msgid "Optional Site logo, should be around 50x50 and in PNG format"
msgstr ""
"Logo zpěvníčku, nepovinné, mělo by mít rozměry kolem 50x50 a být v PNG "
"formátu"

#: tenants/templates/tenant/add.html:4 tenants/templates/tenant/add.html:5
msgid "Tenant Editor"
msgstr "Uprava Zpěvníku"
Expand Down
25 changes: 25 additions & 0 deletions tenants/migrations/0003_tenant_icon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.0 on 2024-01-12 14:46

import tenants.models
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("tenants", "0002_tenant_all_songs_category"),
]

operations = [
migrations.AddField(
model_name="tenant",
name="icon",
field=models.ImageField(
blank=True,
help_text="Optional Site Icon, needs to be a PNG",
null=True,
upload_to="uploads/",
validators=[tenants.models.only_png],
verbose_name="Site Icon",
),
),
]
18 changes: 17 additions & 1 deletion tenants/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
"""Tenant models"""
from django.contrib.auth import get_user_model
from django.db.models import Model, CharField, ManyToManyField, BooleanField
from django.core.exceptions import ValidationError
from django.db.models import Model, CharField, ManyToManyField, BooleanField, ImageField
from django.utils.translation import gettext_lazy as _

# Create your models here.


def only_png(value):
"""Raises validation error if the file is not a PNG image"""
if not value.url and value.file.content_type != "image/png":
raise ValidationError(_("Only PNG images are allowed"))


class Tenant(Model):
"""Represents a Tenant, who has own Categories and is determined by a Host Header"""

Expand All @@ -24,6 +31,15 @@ class Tenant(Model):
verbose_name=_("All Songs"),
help_text=_("True, if all songs category should be added to navigation"),
)
icon = ImageField(
verbose_name=_("Logo"),
help_text=_("Optional Site logo, should be around 50x50 and in PNG format"),
null=True,
blank=True,
upload_to="uploads/",
validators=[only_png],
)

admins = ManyToManyField(get_user_model())

def __str__(self):
Expand Down

0 comments on commit 7cdf259

Please sign in to comment.