Skip to content

Commit

Permalink
Update behavior on admin entering account
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Jan 27, 2024
1 parent a3c83ea commit 80afb50
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
6 changes: 0 additions & 6 deletions backend/donations/models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,6 @@ class Meta:
def __str__(self):
return f"{self.name}"

def save(self, *args, **kwargs):
# Force the form_url (which acts as an NGO identifier) to lowercase
if self.form_url:
self.form_url = self.form_url.lower().strip()
return super().save(*args, **kwargs)

def get_full_form_url(self):
if self.form_url:
return "https://{}/{}".format(settings.APEX_DOMAIN, self.form_url)
Expand Down
2 changes: 2 additions & 0 deletions backend/donations/views/account_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def get(self, request, *args, **kwargs):

# if the user is logged in just redirect
if request.user.is_authenticated:
if request.user.is_superuser:
return redirect(reverse("admin-index"))
return redirect(reverse("contul-meu"))

return render(request, self.template_name, context)
Expand Down
28 changes: 19 additions & 9 deletions backend/donations/views/my_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.db.models import Q, QuerySet
from django.shortcuts import render
from django.urls import reverse_lazy
from django.shortcuts import redirect, render
from django.urls import reverse, reverse_lazy
from django.utils import timezone
from django.utils.decorators import method_decorator

Expand Down Expand Up @@ -67,9 +67,14 @@ class NgoDetailsHandler(AccountHandler):

@method_decorator(login_required(login_url=reverse_lazy("login")))
def get(self, request, *args, **kwargs):
user = request.user

if user.is_superuser:
return redirect(reverse("admin-ngos"))

context = {
"user": request.user,
"ngo": request.user.ngo if request.user.ngo else None,
"user": user,
"ngo": user.ngo if user.ngo else None,
"counties": settings.FORM_COUNTIES,
}

Expand All @@ -79,7 +84,12 @@ def get(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs):
post = request.POST

ngo: Ngo = request.user.ngo
user = request.user

if user.is_superuser:
return redirect(reverse("admin-ngos"))

ngo: Ngo = user.ngo

is_new_ngo = False
if not ngo:
Expand Down Expand Up @@ -113,12 +123,12 @@ def post(self, request, *args, **kwargs):
ngo.save()

if is_new_ngo:
request.user.ngo = ngo
request.user.save()
user.ngo = ngo
user.save()

context = {
"user": request.user,
"ngo": request.user.ngo if request.user.ngo else None,
"user": user,
"ngo": user.ngo if user.ngo else None,
"counties": settings.FORM_COUNTIES,
}

Expand Down
18 changes: 9 additions & 9 deletions backend/redirectioneaza/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
path("ong/", ForNgoHandler.as_view(), name="ngo"),
path("pentru-ong-uri/", RedirectView.as_view(pattern_name="ngo", permanent=True)),
# backup in case of old urls. to be removed
path("asociatii/", NgoListHandler.as_view()),
path("asociatii/", NgoListHandler.as_view(), name="associations"),
path("termeni/", TermsHandler.as_view(), name="terms"),
path("TERMENI/", RedirectView.as_view(pattern_name="terms", permanent=True)),
path("nota-de-informare/", NoteHandler.as_view(), name="note"),
path("politica/", PolicyHandler.as_view()),
path("despre/", AboutHandler.as_view()),
path("politica/", PolicyHandler.as_view(), name="policy"),
path("despre/", AboutHandler.as_view(), name="about"),
# account management
path("cont-nou/", SignupHandler.as_view()),
path("login/", LoginHandler.as_view(), name="login"),
Expand All @@ -79,10 +79,10 @@
VerificationHandler.as_view(),
name="verification",
),
path("password/", SetPasswordHandler.as_view()),
path("password/", SetPasswordHandler.as_view(), name="password"),
# my account
path("contul-meu/", MyAccountHandler.as_view(), name="contul-meu"),
path("asociatia/", NgoDetailsHandler.as_view(), name="asociatia"),
path("asociatia/", NgoDetailsHandler.as_view(), name="association"),
path("date-cont/", MyAccountDetailsHandler.as_view(), name="date-contul-meu"),
# APIs
path("api/ngo/check-url/<ngo_url>/", CheckNgoUrl.as_view(), name="api-ngo-check-url"),
Expand All @@ -96,10 +96,10 @@
path("api/ngo/form/<ngo_url>/", GetNgoForm.as_view(), name="api-ngo-form-url"),
path("api/ngo/forms/download/", GetNgoForms.as_view(), name="api-ngo-forms"),
# Cron routes
path("cron/stats/", Stats.as_view()),
path("cron/ngos/remove-form/", NgoRemoveForms.as_view(), name="ngo-remove-form"),
path("cron/ngos/export/", NgoExport.as_view()),
path("cron/export/custom/", CustomExport.as_view()),
path("cron/stats/", Stats.as_view(), name="cron-stats"),
path("cron/ngos/remove-form/", NgoRemoveForms.as_view(), name="cron-ngo-remove-form"),
path("cron/ngos/export/", NgoExport.as_view(), name="cron-ngo-export"),
path("cron/export/custom/", CustomExport.as_view(), name="cron-custom-export"),
#
# END_OF_TODO
#
Expand Down

0 comments on commit 80afb50

Please sign in to comment.