frontend views

This commit is contained in:
sinavir 2023-02-16 19:11:33 +01:00
parent 5b268e4d35
commit 067a2fc729
4 changed files with 113 additions and 5 deletions

View file

@ -1,8 +1,29 @@
from django.urls import path from django.urls import include, path
from .views import BudgetListView from .views import (BudgetGroupCreateView, BudgetGroupUpdateView,
BudgetLineCreateView, BudgetLineUpdateView, BudgetListView)
app_name = "frontend" app_name = "frontend"
urlpatterns = [ urlpatterns = [
path("", BudgetListView.as_view(), name="budget"), path("", BudgetListView.as_view(), name="budget"),
path(
"budget-group/create",
BudgetGroupCreateView.as_view(),
name="budget-group-create",
),
path(
"budget-group/<int:pk>/update",
BudgetGroupUpdateView.as_view(),
name="budget-group-update",
),
path(
"budget-line/create",
BudgetLineCreateView.as_view(),
name="budget-line-create",
),
path(
"budget-line/<int:pk>/update",
BudgetLineUpdateView.as_view(),
name="budget-line-update",
),
] ]

View file

@ -1,4 +1,13 @@
from budget.models import BudgetGroup """
Frontend views for the app
"""
from agent.model import Agent
from budget.models import BudgetGroup, BudgetLine
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.messages.views import SuccessMessageMixin
from django.db.models import Model
from django.urls import reverse
from django.views.generic import (CreateView, DeleteView, DetailView, ListView, from django.views.generic import (CreateView, DeleteView, DetailView, ListView,
TemplateView, UpdateView) TemplateView, UpdateView)
@ -6,3 +15,64 @@ from django.views.generic import (CreateView, DeleteView, DetailView, ListView,
class BudgetListView(ListView): class BudgetListView(ListView):
model = BudgetGroup model = BudgetGroup
template_name = "frontend/budget_list.html" template_name = "frontend/budget_list.html"
ordering = "-name"
class BudgetGroupCreateView(SuccessMessageMixin, PermissionRequiredMixin, CreateView):
model = BudgetGroup
fields = ["name", "description"]
template_name = "frontend/budgetgroup_create.html"
success_message = "Le budget %(name)s a été créé avec succès"
permission_required = "budget.add_budgetgroup"
def get_success_url(self):
return reverse("frontend:budget")
class BudgetGroupUpdateView(SuccessMessageMixin, PermissionRequiredMixin, UpdateView):
model = BudgetGroup
fields = ["name", "description"]
template_name = "frontend/budgetgroup_create.html"
success_message = "Le budget %(name)s a été mis à jour avec succès"
permission_required = "budget.change_budgetgroup"
def get_success_url(self):
return reverse("frontend:budget")
class BudgetLineCreateView(SuccessMessageMixin, PermissionRequiredMixin, CreateView):
model = BudgetLine
fields = ["title", "comment", "amount", "author", "date", "group", "facture"]
template_name = "frontend/budgetline_create.html"
success_message = 'La dépense/recette "%(title)s" a été créée avec succès'
permission_required = "budget.add_budgetline"
def get_initial(self):
if "groupid" in self.request.GET:
try:
gid = int(self.request.GET["groupid"])
except ValueError:
gid = None
if gid is not None:
try:
grp = BudgetGroup.objects.get(pk=gid)
except Model.DoesNotExist:
grp = None
else:
grp = None
agents = Agent.objects.filter(user=self.user)
return {"author": agent, "group": grp}
def get_success_url(self):
return reverse("frontend:budget")
class BudgetLineUpdateView(SuccessMessageMixin, UpdateView, PermissionRequiredMixin):
model = BudgetLine
fields = ["title", "comment", "amount", "author", "date", "group", "facture"]
template_name = "frontend/budgetline_update.html"
success_message = 'La dépense/recette "%(title)s" a été mise à jour avec succès'
permission_required = "budget.change_budgetline"
def get_success_url(self):
return reverse("frontend:budget")

View file

@ -27,7 +27,6 @@ DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
@ -37,6 +36,7 @@ INSTALLED_APPS = [
"django.contrib.sessions", "django.contrib.sessions",
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
"authens",
"rest_framework", "rest_framework",
# "django_extensions", # "django_extensions",
"budget", "budget",
@ -76,6 +76,22 @@ TEMPLATES = [
WSGI_APPLICATION = "hackens_orga.wsgi.application" WSGI_APPLICATION = "hackens_orga.wsgi.application"
# AuthENS
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"authens.backends.ENSCASBackend",
]
from django.urls import reverse_lazy
LOGIN_URL = reverse_lazy("authens:login")
LOGOUT_REDIRECT_URL = "/"
LOGIN_REDIRECT_URL = "/"
AUTHENS_USE_OLDCAS = False
# Django-rest-framework # Django-rest-framework
# https://www.django-rest-framework.org/ # https://www.django-rest-framework.org/

View file

@ -17,10 +17,11 @@ from django.contrib import admin
from django.urls import include, path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path("authens/", include("authens.urls")),
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")), path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
path("api/budget/", include("budget.urls")), path("api/budget/", include("budget.urls")),
path("api/agent/", include("agent.urls")), path("api/agent/", include("agent.urls")),
path("api/wishlist/", include("wishlist.urls")), # path("api/wishlist/", include("wishlist.urls")),
path("", include("frontend.urls")), path("", include("frontend.urls")),
] ]