167 lines
4.9 KiB
Python
167 lines
4.9 KiB
Python
from django import forms
|
|
from django.contrib import admin
|
|
from django.http import HttpResponseRedirect
|
|
from django.urls import reverse
|
|
|
|
from .models import SiteBranding, SiteContact
|
|
|
|
|
|
class SiteBrandingForm(forms.ModelForm):
|
|
class Meta:
|
|
model = SiteBranding
|
|
fields = "__all__"
|
|
widgets = {
|
|
field: forms.TextInput(attrs={"type": "color"})
|
|
for field in (
|
|
"border_color",
|
|
"background_color",
|
|
"surface_color",
|
|
"primary_color",
|
|
"secondary_color",
|
|
"accent_color",
|
|
"text_color",
|
|
"muted_text_color",
|
|
)
|
|
}
|
|
|
|
|
|
@admin.register(SiteBranding)
|
|
class SiteBrandingAdmin(admin.ModelAdmin):
|
|
form = SiteBrandingForm
|
|
fieldsets = (
|
|
(
|
|
"Site identity",
|
|
{
|
|
"fields": ("site_name", "short_name", "tagline", "meta_description"),
|
|
"description": "Names and text used throughout the public website.",
|
|
},
|
|
),
|
|
(
|
|
"Article people section",
|
|
{
|
|
"fields": ("article_people_eyebrow", "article_people_title"),
|
|
"description": "These headings are shared by blog articles and project articles that have people cards.",
|
|
},
|
|
),
|
|
(
|
|
"Project people section",
|
|
{
|
|
"fields": ("project_people_eyebrow", "project_people_title"),
|
|
"description": "These headings are shared by main projects and sub-projects that have people cards.",
|
|
},
|
|
),
|
|
(
|
|
"Brand assets",
|
|
{
|
|
"fields": (
|
|
"icon",
|
|
"icon_alt",
|
|
"website_icon",
|
|
"hero_logo",
|
|
"hero_logo_alt",
|
|
),
|
|
"description": (
|
|
"Manage each placement independently. Removing an upload restores "
|
|
"the existing Communication to Care asset for that placement."
|
|
),
|
|
},
|
|
),
|
|
(
|
|
"Sizes",
|
|
{
|
|
"fields": ("navbar_icon_size", "footer_icon_size"),
|
|
"description": (
|
|
"Set the logo height for each placement. Its width is calculated "
|
|
"automatically so the uploaded image is never cropped or stretched."
|
|
),
|
|
},
|
|
),
|
|
(
|
|
"Appearance",
|
|
{
|
|
"fields": (
|
|
"show_border",
|
|
"border_width",
|
|
"border_color",
|
|
),
|
|
},
|
|
),
|
|
(
|
|
"Site colours",
|
|
{
|
|
"fields": (
|
|
"background_color",
|
|
"surface_color",
|
|
"primary_color",
|
|
"secondary_color",
|
|
"accent_color",
|
|
"text_color",
|
|
"muted_text_color",
|
|
),
|
|
"description": "Use six-digit hex colours. Changes apply across the public site.",
|
|
},
|
|
),
|
|
)
|
|
|
|
def has_add_permission(self, request):
|
|
return not SiteBranding.objects.exists()
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
return False
|
|
|
|
def changelist_view(self, request, extra_context=None):
|
|
branding = SiteBranding.objects.first()
|
|
if branding:
|
|
return HttpResponseRedirect(
|
|
reverse("admin:core_sitebranding_change", args=[branding.pk])
|
|
)
|
|
return super().changelist_view(request, extra_context)
|
|
|
|
|
|
@admin.register(SiteContact)
|
|
class SiteContactAdmin(admin.ModelAdmin):
|
|
fieldsets = (
|
|
(
|
|
"Email",
|
|
{
|
|
"fields": (
|
|
"support_email",
|
|
"email_card_title",
|
|
"email_card_description",
|
|
),
|
|
},
|
|
),
|
|
(
|
|
"Discord",
|
|
{
|
|
"fields": (
|
|
"discord_url",
|
|
"discord_label",
|
|
"discord_card_title",
|
|
"discord_card_description",
|
|
),
|
|
},
|
|
),
|
|
(
|
|
"Office address",
|
|
{
|
|
"fields": ("office_address", "office_card_title"),
|
|
"description": "Enter one address line per row.",
|
|
},
|
|
),
|
|
)
|
|
|
|
def has_add_permission(self, request):
|
|
return not SiteContact.objects.exists()
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
return False
|
|
|
|
def changelist_view(self, request, extra_context=None):
|
|
contact = SiteContact.objects.first()
|
|
if contact:
|
|
return HttpResponseRedirect(
|
|
reverse("admin:core_sitecontact_change", args=[contact.pk])
|
|
)
|
|
return super().changelist_view(request, extra_context)
|