Skip to content

Commit 20ad224

Browse files
authored
Merge pull request #1428 from opengisch/QF-6414-enable-whitelabelling-on-auth-pages
feat: add whitelabelling
2 parents 7352d97 + 89842e5 commit 20ad224

File tree

4 files changed

+85
-6
lines changed

4 files changed

+85
-6
lines changed

docker-app/qfieldcloud/core/staticfiles/css/qfieldcloud.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ h1, h2, h3, h4, h5, h6 {
3737

3838
.qfc-header-logo {
3939
height: 1.5rem;
40+
margin-left: 1rem;
41+
}
42+
43+
.qfc-logo-wrapper {
44+
display: flex;
45+
justify-content: center;
46+
align-items: center;
47+
min-height: 15rem;
48+
padding: 1rem 0;
49+
}
50+
51+
.qfc-main-logo {
52+
max-width: 100%;
53+
max-height: 15rem;
54+
width: auto;
55+
height: auto;
4056
}
4157

4258
.ml-5rem {

docker-app/qfieldcloud/core/templates/account/base.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
{% sri_static 'css/vendor.css' %}
1111
{% sri_static 'css/qfieldcloud.css' %}
12-
<link rel="shortcut icon" type="image/x-icon" href="{% static 'favicon.ico' %}" />
12+
<link rel="shortcut icon" type="image/x-icon" href="{% static whitelabel.favicon %}" />
1313

1414
<title>
1515
{% block title %}
16-
{% block title_contents %}{{ title }}{% endblock title_contents %} | {{ site_title|default:_('QFieldCloud') }}
16+
{% block title_contents %}{{ title }}{% endblock title_contents %} | {{ whitelabel.site_title }}
1717
{% endblock title %}
1818
</title>
1919

@@ -25,7 +25,7 @@
2525
<!-- Navbar -->
2626
<nav class="navbar navbar-expand-md navbar-dark nav-fill w-100 bg-primary">
2727
<a href="{% url 'index' %}">
28-
<img src="{% static 'logo_sidetext_white.svg' %}" alt="QFieldCloud" class="logo-nav qfc-header-logo ml-1">
28+
<img src="{% static whitelabel.logo_navbar %}" alt="{{ whitelabel.logo_alt }}" class="qfc-header-logo">
2929
</a>
3030

3131

@@ -37,9 +37,9 @@
3737
<div class="flex-shrink-0 col-12">
3838
<div class="row">
3939
<div class="col-lg-6 offset-lg-3">
40-
<p class="text-center">
41-
<img src="{% static 'logo_undertext.svg' %}" alt="QFieldCloud" class="logo-nav" style="height: 15rem">
42-
</p>
40+
<div class="qfc-logo-wrapper">
41+
<img src="{% static whitelabel.logo_main %}" alt="{{ whitelabel.logo_alt }}" class="qfc-main-logo">
42+
</div>
4343

4444
{% block content %}{% endblock content %}
4545

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import copy
2+
from typing import Any
3+
4+
from django.conf import settings
5+
from django.http import HttpRequest
6+
from django.utils.translation import gettext as _
7+
8+
# Default whitelabel configuration
9+
DEFAULT_WHITELABEL = {
10+
# Branding
11+
"site_title": _("QFieldCloud"),
12+
# Logos (paths relative to static directory)
13+
"logo_navbar": "logo_sidetext_white.svg",
14+
"logo_main": "logo_undertext.svg",
15+
"favicon": "favicon.ico",
16+
}
17+
18+
19+
def get_whitelabel_settings() -> dict[str, Any]:
20+
"""
21+
Get whitelabel settings by merging user settings with defaults.
22+
Filters out None values from user settings to preserve defaults.
23+
"""
24+
# Start with a deep copy of defaults
25+
whitelabel_settings = copy.deepcopy(DEFAULT_WHITELABEL)
26+
27+
user_settings = {}
28+
for k, v in getattr(settings, "WHITELABEL", {}).items():
29+
if v is None:
30+
continue
31+
32+
user_settings[k] = v
33+
34+
# Update defaults with user settings
35+
whitelabel_settings.update(user_settings)
36+
37+
# Post-processing: Add any computed defaults or normalization here
38+
# Example: favicon could default to logo_navbar if not set
39+
# whitelabel_settings["favicon"] = whitelabel_settings["favicon"] or "default.ico"
40+
41+
return whitelabel_settings
42+
43+
44+
def whitelabel(request: HttpRequest) -> dict[str, Any]:
45+
"""Make whitelabel configuration available to all templates with translations."""
46+
47+
whitelabel_config = get_whitelabel_settings()
48+
49+
return {
50+
"whitelabel": whitelabel_config,
51+
}

docker-app/qfieldcloud/settings.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
"django.contrib.auth.context_processors.auth",
191191
"django.contrib.messages.context_processors.messages",
192192
"qfieldcloud.core.context_processors.signup_open",
193+
"qfieldcloud.core.whitelabel.whitelabel",
193194
],
194195
},
195196
},
@@ -887,3 +888,14 @@ def before_send(event, hint):
887888
# Additional custom CSS file for the Django Admin pages.
888889
"custom_css": "css/admin.css",
889890
}
891+
892+
# Whitelabel configuration
893+
# Uncomment and customize to override default branding
894+
# See qfieldcloud/core/whitelabel.py for all available options and defaults
895+
# WHITELABEL = {
896+
# "site_title": "Your Custom Title",
897+
# "logo_navbar": "path/to/logo_navbar.svg",
898+
# "logo_main": "path/to/logo_main.svg",
899+
# "logo_alt": "Your logo description",
900+
# "favicon": "path/to/favicon.ico",
901+
# }

0 commit comments

Comments
 (0)