diff --git a/backend/donations/views/account_management.py b/backend/donations/views/account_management.py index cda881ad..6ace015f 100644 --- a/backend/donations/views/account_management.py +++ b/backend/donations/views/account_management.py @@ -14,7 +14,7 @@ from redirectioneaza.common.messaging import send_email from ..forms.account import ForgotPasswordForm, LoginForm, RegisterForm, ResetPasswordForm -from .base import BaseTemplateView +from .base import BaseVisibleTemplateView logger = logging.getLogger(__name__) @@ -25,9 +25,9 @@ def django_login(request, user) -> None: login(request, user, backend="django.contrib.auth.backends.ModelBackend") -class ForgotPasswordView(BaseTemplateView): +class ForgotPasswordView(BaseVisibleTemplateView): template_name = "resetare-parola.html" - title = "Resetare parola" + title = _("Reset password") def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) @@ -79,7 +79,7 @@ def _send_password_reset_email(self, user: UserModel): ) -class LoginView(BaseTemplateView): +class LoginView(BaseVisibleTemplateView): template_name = "account/login.html" title = _("Sign In") @@ -144,14 +144,17 @@ def post(self, request: HttpRequest, **kwargs): return render(request, self.template_name, context) -class LogoutView(BaseTemplateView): +class LogoutView(BaseVisibleTemplateView): + title = _("Sign Out") + def get(self, request, *args, **kwargs): logout(request) return redirect("/") -class SetPasswordView(BaseTemplateView): +class SetPasswordView(BaseVisibleTemplateView): template_name = "parola-noua.html" + title = _("Set New Password") def post(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) @@ -176,7 +179,7 @@ def post(self, request, *args, **kwargs): return redirect(reverse("contul-meu")) -class SignupView(BaseTemplateView): +class SignupView(BaseVisibleTemplateView): template_name = "account/register.html" title = _("New account") @@ -258,7 +261,7 @@ def post(self, request, *args, **kwargs): return redirect(reverse("contul-meu")) -class VerificationView(BaseTemplateView): +class VerificationView(BaseVisibleTemplateView): """ handler used to: v - verify new account @@ -266,6 +269,7 @@ class VerificationView(BaseTemplateView): """ template_name = "parola-noua.html" + title = _("Verification") def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) diff --git a/backend/donations/views/api.py b/backend/donations/views/api.py index d84c8445..2b3c9097 100644 --- a/backend/donations/views/api.py +++ b/backend/donations/views/api.py @@ -11,6 +11,7 @@ from django.urls import reverse, reverse_lazy from django.utils import timezone from django.utils.decorators import method_decorator +from django.utils.translation import gettext as _ from django.views.decorators.csrf import csrf_exempt from django.views.generic import TemplateView @@ -26,6 +27,8 @@ class UpdateFromNgohub(BaseTemplateView): + title = _("Update from ") + def post(self, request, *args, **kwargs): redirect_success = redirect(reverse("organization")) redirect_error = redirect(reverse("organization")) diff --git a/backend/donations/views/base.py b/backend/donations/views/base.py index 29bf4c86..a3074ec8 100644 --- a/backend/donations/views/base.py +++ b/backend/donations/views/base.py @@ -7,7 +7,6 @@ class BaseTemplateView(TemplateView): user_model = get_user_model() - title: str = "" def _get_checked_property(self, property_name: str, default_value: str) -> Any: is_production: bool = settings.ENVIRONMENT == "development" @@ -20,6 +19,14 @@ def _get_checked_property(self, property_name: str, default_value: str) -> Any: return property_value or default_value + def get_context_data(self, **kwargs): + return super().get_context_data(**kwargs) + + +class BaseVisibleTemplateView(BaseTemplateView): + user_model = get_user_model() + title: str = "" + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) diff --git a/backend/donations/views/my_account.py b/backend/donations/views/my_account.py index 2639a479..b07a4203 100644 --- a/backend/donations/views/my_account.py +++ b/backend/donations/views/my_account.py @@ -22,13 +22,14 @@ from ..models.jobs import Job, JobStatusChoices from ..models.main import Donor, Ngo, ngo_id_number_validator from .api import CheckNgoUrl -from .base import BaseTemplateView +from .base import BaseVisibleTemplateView UserModel = get_user_model() -class MyAccountDetailsView(BaseTemplateView): +class MyAccountDetailsView(BaseVisibleTemplateView): template_name = "ngo/my-account-details.html" + title = _("My Account Details") @method_decorator(login_required(login_url=reverse_lazy("login"))) def get(self, request, *args, **kwargs): @@ -53,7 +54,9 @@ def post(self, request, *args, **kwargs): return render(request, self.template_name, context) -class ArchiveDownloadLinkView(BaseTemplateView): +class ArchiveDownloadLinkView(BaseVisibleTemplateView): + title = _("Download archive") + @method_decorator(login_required(login_url=reverse_lazy("login"))) def get(self, request: HttpRequest, job_id, *args, **kwargs): user: User = request.user @@ -87,8 +90,9 @@ def get(self, request: HttpRequest, job_id, *args, **kwargs): return redirect(job.zip.url) -class MyAccountView(BaseTemplateView): +class MyAccountView(BaseVisibleTemplateView): template_name = "ngo/my-account.html" + title = _("My Account") @staticmethod @cache_decorator(timeout=settings.TIMEOUT_CACHE_SHORT, cache_key_prefix="DONORS_BY_DONATION_YEAR") @@ -181,8 +185,9 @@ def delete_prefilled_form(ngo_id): return Ngo.delete_prefilled_form(ngo_id) -class NgoDetailsView(BaseTemplateView): +class NgoDetailsView(BaseVisibleTemplateView): template_name = "ngo/ngo-details.html" + title = _("Organization details") def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs)