diff --git a/backend/forms.py b/backend/forms.py
new file mode 100644
index 0000000..b07e2e2
--- /dev/null
+++ b/backend/forms.py
@@ -0,0 +1,12 @@
+from django import forms
+from django.utils.translation import gettext_lazy as _
+
+
+class ConfigurationForm(forms.Form):
+ """Form instance that holds configuration values for the application."""
+
+ club_name = forms.CharField(label=_("Club name"), max_length=250)
+ club_location = forms.CharField(label=_("Club location"), max_length=250, help_text=_("Changing this setting will set a new home game location and will update already existing games"))
+ club_logo = forms.ImageField(label=_("Club logo"), required=False)
+ enable_teams = forms.BooleanField(label=_("Enable teams"), required=False)
+ enable_activities = forms.BooleanField(label=_("Enable activities"), required=False)
diff --git a/backend/urls.py b/backend/urls.py
index 8a6f503..2f7a005 100644
--- a/backend/urls.py
+++ b/backend/urls.py
@@ -1,9 +1,10 @@
from django.urls import include, path
-from .views import index
+from .views import configuration, index
app_name = "backend"
urlpatterns = [
path("", index, name="index"),
path("members/", include("backend.members.urls")),
+ path("configuration", configuration, name="configuration")
]
diff --git a/backend/views.py b/backend/views.py
index 91e8035..0df8408 100644
--- a/backend/views.py
+++ b/backend/views.py
@@ -1,6 +1,59 @@
+from pathlib import Path
+
+from constance import config
+from django.conf import settings
+from django.contrib import messages
+from django.contrib.auth.decorators import login_required, user_passes_test
+from django.core.cache import cache
+from django.core.files.storage import default_storage
+from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
+from django.utils.translation import gettext_lazy as _
+from waffle.models import Switch
+
+from backend.forms import ConfigurationForm
# Create your views here.
def index(request):
return render(request, "backend/index.html")
+
+
+@login_required
+@user_passes_test(lambda u: u.is_superuser)
+def configuration(request: HttpRequest) -> HttpResponse:
+ switches = {
+ "enable_teams": Switch.objects.get_or_create(name="TF_TEAMS", defaults={"active": False})[0],
+ "enable_activities": Switch.objects.get_or_create(name="TF_ACTIVITIES", defaults={"active": False})[0],
+ }
+
+ initial_data = {
+ "club_name": config.TF_CLUB_NAME,
+ "club_location": config.TF_CLUB_HOME,
+ "club_logo": config.TF_CLUB_LOGO,
+ "enable_teams": switches["enable_teams"].active,
+ "enable_activities": switches["enable_activities"].active,
+ }
+
+ form = ConfigurationForm(initial=initial_data)
+
+ if request.method == "POST":
+ form = ConfigurationForm(request.POST, request.FILES)
+ if form.is_valid():
+ config.TF_CLUB_NAME = form.cleaned_data["club_name"]
+ config.TF_CLUB_HOME = form.cleaned_data["club_location"]
+
+ if form.cleaned_data["club_logo"] is not None:
+ default_storage.save(str(Path(settings.STATIC_ROOT) / form.cleaned_data["club_logo"].name), form.cleaned_data["club_logo"])
+ config.TF_CLUB_LOGO = form.cleaned_data["club_logo"].name
+
+ for switch_key in switches.keys():
+ if switches[switch_key].active != form.cleaned_data[switch_key]:
+ switches[switch_key].active = form.cleaned_data[switch_key]
+
+ Switch.objects.bulk_update(switches.values(), ["active"])
+ cache.clear()
+
+ messages.success(request=request, message=_("Settings have been saved successfully"))
+
+ return render(request, "backend/configuration.html", {"form": form})
diff --git a/templates/backend/base.html b/templates/backend/base.html
index 1f7de1a..711c2b8 100644
--- a/templates/backend/base.html
+++ b/templates/backend/base.html
@@ -4,17 +4,18 @@
{% block sidebar %}
{% url "backend:members:list" as members_list %}
+ {% url "backend:configuration" as configuration %}
{% has_perm "members.member_manager" request.user as is_member_manager %}
{% if is_member_manager %}
-
+
+
{% endif %}
-
- Dashboard
- Calendar
- Members
- Settings
+ {% if request.user.is_superuser %}
+
+
+ {% endif %}
{% endblock sidebar %}
\ No newline at end of file
diff --git a/templates/backend/configuration.html b/templates/backend/configuration.html
new file mode 100644
index 0000000..b1a2e36
--- /dev/null
+++ b/templates/backend/configuration.html
@@ -0,0 +1,76 @@
+{% extends "backend/base.html" %}
+
+{% load i18n %}
+{% load form_field %}
+{% load avatar %}
+{% load waffle_tags %}
+
+{% block content %}
+ {% partialdef content inline %}
+ {% translate "Configuration" %}
+
+ {% blocktranslate %}
+
+ Use the below options to configure your TeamForge instance. Options marked as required will need to be set in order for TeamForge to function properly.
+ You can also use this form to enable or disable certain pieces of functionality for your users.
+
+ {% endblocktranslate %}
+
+ {% if form.errors %}
+
+
+
+
+
{% translate "Error" %}
+
{% translate "Please correct the errors below before saving again." %}
+
+
+ {% endif %}
+
+
+
+
+ {% endpartialdef content %}
+{% endblock content %}
\ No newline at end of file
diff --git a/templates/members/member_form.html b/templates/members/member_form.html
index a30c402..2fe6f76 100644
--- a/templates/members/member_form.html
+++ b/templates/members/member_form.html
@@ -52,7 +52,7 @@
{% endif %}
- {% switch "TF_ENABLE_TEAMS" %}
+ {% switch "TF_TEAMS" %}
{% translate "View team memberships" %}
@@ -76,7 +76,7 @@
{{ member.emergency_phone_number }}
{% endif %}
- {% switch "TF_ENABLE_TEAMS" %}
+ {% switch "TF_TEAMS" %}
{% translate "Team Memberships" %}