Refactor account views
This commit is contained in:
parent
a32e65925c
commit
07f7011a68
2 changed files with 27 additions and 25 deletions
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
|
@ -38,6 +38,7 @@
|
||||||
"hitronhub",
|
"hitronhub",
|
||||||
"homerouter",
|
"homerouter",
|
||||||
"hotspot",
|
"hotspot",
|
||||||
|
"htmx",
|
||||||
"huaweimobilewifi",
|
"huaweimobilewifi",
|
||||||
"isready",
|
"isready",
|
||||||
"Itune",
|
"Itune",
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
import logging
|
import logging
|
||||||
from mimetypes import guess_type
|
from mimetypes import guess_type
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any, ClassVar
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
|
@ -301,6 +301,7 @@ class CustomLoginView(LoginView):
|
||||||
"""Custom login view."""
|
"""Custom login view."""
|
||||||
|
|
||||||
template_name = "accounts/login.html"
|
template_name = "accounts/login.html"
|
||||||
|
next_page = reverse_lazy("index")
|
||||||
|
|
||||||
def form_valid(self, form: AuthenticationForm) -> HttpResponse:
|
def form_valid(self, form: AuthenticationForm) -> HttpResponse:
|
||||||
"""Check if the form is valid."""
|
"""Check if the form is valid."""
|
||||||
|
|
@ -314,24 +315,27 @@ class RegisterView(CreateView):
|
||||||
|
|
||||||
template_name = "accounts/register.html"
|
template_name = "accounts/register.html"
|
||||||
form_class = UserCreationForm
|
form_class = UserCreationForm
|
||||||
success_url = reverse_lazy("login")
|
success_url: str = reverse_lazy("login")
|
||||||
|
extra_context: ClassVar[dict[str, str]] = {
|
||||||
# Add context data to the view
|
"title": "Register",
|
||||||
def get_context_data(self, **kwargs) -> dict: # noqa: ANN003
|
"description": "Register a new account",
|
||||||
"""Get the context data."""
|
"keywords": "register, account",
|
||||||
context: dict[str, Any] = super().get_context_data(**kwargs)
|
"author": "TheLovinator",
|
||||||
context["description"] = "Register a new account"
|
"canonical": "https://feedvault.se/accounts/register/",
|
||||||
context["keywords"] = "register, account, feed, rss, atom, archive, rss list"
|
}
|
||||||
context["author"] = "TheLovinator"
|
|
||||||
context["canonical"] = "https://feedvault.se/accounts/register/"
|
|
||||||
context["title"] = "Register"
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
|
||||||
class CustomLogoutView(LogoutView):
|
class CustomLogoutView(LogoutView):
|
||||||
"""Logout view."""
|
"""Logout view."""
|
||||||
|
|
||||||
next_page = "index" # Redirect to index after logout
|
next_page = reverse_lazy("login")
|
||||||
|
extra_context: ClassVar[dict[str, str]] = {
|
||||||
|
"title": "Logout",
|
||||||
|
"description": "Logout of your account",
|
||||||
|
"keywords": "logout, account",
|
||||||
|
"author": "TheLovinator",
|
||||||
|
"canonical": "https://feedvault.se/accounts/logout/",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class CustomPasswordChangeView(SuccessMessageMixin, PasswordChangeView):
|
class CustomPasswordChangeView(SuccessMessageMixin, PasswordChangeView):
|
||||||
|
|
@ -340,17 +344,13 @@ class CustomPasswordChangeView(SuccessMessageMixin, PasswordChangeView):
|
||||||
template_name = "accounts/change_password.html"
|
template_name = "accounts/change_password.html"
|
||||||
success_url = reverse_lazy("index")
|
success_url = reverse_lazy("index")
|
||||||
success_message = "Your password was successfully updated!"
|
success_message = "Your password was successfully updated!"
|
||||||
|
extra_context: ClassVar[dict[str, str]] = {
|
||||||
# Add context data to the view
|
"title": "Change password",
|
||||||
def get_context_data(self, **kwargs) -> dict: # noqa: ANN003
|
"description": "Change your password",
|
||||||
"""Get the context data."""
|
"keywords": "change, password, account",
|
||||||
context = super().get_context_data(**kwargs)
|
"author": "TheLovinator",
|
||||||
context["description"] = "Change your password"
|
"canonical": "https://feedvault.se/accounts/change-password/",
|
||||||
context["keywords"] = "change, password, account, feed, rss, atom, archive, rss list"
|
}
|
||||||
context["author"] = "TheLovinator"
|
|
||||||
context["canonical"] = "https://feedvault.se/accounts/change-password/"
|
|
||||||
context["title"] = "Change password"
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
|
||||||
class ProfileView(LoginRequiredMixin, View):
|
class ProfileView(LoginRequiredMixin, View):
|
||||||
|
|
@ -360,6 +360,7 @@ class ProfileView(LoginRequiredMixin, View):
|
||||||
"""Load the profile page."""
|
"""Load the profile page."""
|
||||||
template = loader.get_template(template_name="accounts/profile.html")
|
template = loader.get_template(template_name="accounts/profile.html")
|
||||||
|
|
||||||
|
# TODO(TheLovinator): Use htmx to load the feeds and uploads # noqa: TD003
|
||||||
user_feeds: BaseManager[Feed] = Feed.objects.filter(user=request.user).order_by("-created_at")[:100]
|
user_feeds: BaseManager[Feed] = Feed.objects.filter(user=request.user).order_by("-created_at")[:100]
|
||||||
user_uploads: BaseManager[UserUploadedFile] = UserUploadedFile.objects.filter(user=request.user).order_by(
|
user_uploads: BaseManager[UserUploadedFile] = UserUploadedFile.objects.filter(user=request.user).order_by(
|
||||||
"-created_at",
|
"-created_at",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue