From 93c16d80ecff4cd1663cf9ec40fbe6d8f58c3e44 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Sun, 23 Feb 2025 22:49:18 -0500 Subject: [PATCH] [profiles] Add settings form --- vrobbler/apps/profiles/forms.py | 28 ++++++++++ vrobbler/apps/profiles/urls.py | 11 ++++ vrobbler/apps/profiles/views.py | 17 ++++++ .../templates/profiles/settings_form.html | 54 +++++++++++++++++++ vrobbler/urls.py | 4 +- 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 vrobbler/apps/profiles/forms.py create mode 100644 vrobbler/apps/profiles/urls.py create mode 100644 vrobbler/apps/profiles/views.py create mode 100644 vrobbler/templates/profiles/settings_form.html diff --git a/vrobbler/apps/profiles/forms.py b/vrobbler/apps/profiles/forms.py new file mode 100644 index 0000000..89ef44b --- /dev/null +++ b/vrobbler/apps/profiles/forms.py @@ -0,0 +1,28 @@ +from django import forms + +from profiles.models import UserProfile + + +class UserProfileForm(forms.ModelForm): + class Meta: + model = UserProfile + fields = [ + "timezone", + "lastfm_username", + "lastfm_password", + "lastfm_auto_import", + "retroarch_path", + "retroarch_auto_import", + "archivebox_username", + "archivebox_password", + "archivebox_url", + "bgg_username", + "lichess_username", + "webdav_url", + "webdav_user", + "webdav_pass", + "webdav_auto_import", + "ntfy_url", + "ntfy_enabled", + "redirect_to_webpage", + ] diff --git a/vrobbler/apps/profiles/urls.py b/vrobbler/apps/profiles/urls.py new file mode 100644 index 0000000..7df3a2d --- /dev/null +++ b/vrobbler/apps/profiles/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from profiles import views + +app_name = "profiles" + + +urlpatterns = [ + path( + "settings/", views.ProfileDetailView.as_view(), name="profile_settings" + ), +] diff --git a/vrobbler/apps/profiles/views.py b/vrobbler/apps/profiles/views.py new file mode 100644 index 0000000..70d7e8b --- /dev/null +++ b/vrobbler/apps/profiles/views.py @@ -0,0 +1,17 @@ +from django.urls import reverse_lazy +from django.http.response import HttpResponseBadRequest +from django.views.generic import FormView + +from profiles.forms import UserProfileForm + + +class ProfileDetailView(FormView): + form_class = UserProfileForm + template_name = "profiles/settings_form.html" + success_url = reverse_lazy("profiles:profile_settings") + + def get_context_data(self, **kwargs): + context_data = super().get_context_data(**kwargs) + if self.request.user.is_anonymous: + return HttpResponseBadRequest + return context_data diff --git a/vrobbler/templates/profiles/settings_form.html b/vrobbler/templates/profiles/settings_form.html new file mode 100644 index 0000000..4153be1 --- /dev/null +++ b/vrobbler/templates/profiles/settings_form.html @@ -0,0 +1,54 @@ +{% extends "base_detail.html" %} +{% load mathfilters %} +{% load static %} +{% load naturalduration %} + +{% block head_extra %} + + + + +{% endblock %} + +{% block title %}Settings{% endblock %} +{% block details %} +
+{% csrf_token %} +{{form.as_p}} + +
+{% endblock %} diff --git a/vrobbler/urls.py b/vrobbler/urls.py index b07fba9..4e75ada 100644 --- a/vrobbler/urls.py +++ b/vrobbler/urls.py @@ -36,6 +36,7 @@ from vrobbler.apps.sports.api.views import ( TeamViewSet, ) from vrobbler.apps.tasks import urls as tasks_urls +from vrobbler.apps.profiles import urls as profiles_urls from vrobbler.apps.trails import urls as trails_urls from vrobbler.apps.beers import urls as beers_urls from vrobbler.apps.foods import urls as foods_urls @@ -63,7 +64,7 @@ router.register(r"players", PlayerViewSet) router.register(r"sport-events", SportEventViewSet) router.register(r"teams", TeamViewSet) router.register(r"users", UserViewSet) -router.register(r"user_profiles", UserProfileViewSet) +router.register(r"profiles", UserProfileViewSet) urlpatterns = [ path("api/v1/", include(router.urls)), @@ -88,6 +89,7 @@ urlpatterns = [ path("", include(lifeevents_urls, namespace="life-events")), path("", include(moods_urls, namespace="moods")), path("", include(scrobble_urls, namespace="scrobbles")), + path("", include(profiles_urls, namespace="profiles")), path( "", scrobbles_views.RecentScrobbleList.as_view(), name="vrobbler-home" ),