frontend views
This commit is contained in:
parent
5b268e4d35
commit
067a2fc729
4 changed files with 113 additions and 5 deletions
|
@ -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"
|
||||
urlpatterns = [
|
||||
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",
|
||||
),
|
||||
]
|
||||
|
|
|
@ -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,
|
||||
TemplateView, UpdateView)
|
||||
|
||||
|
@ -6,3 +15,64 @@ from django.views.generic import (CreateView, DeleteView, DetailView, ListView,
|
|||
class BudgetListView(ListView):
|
||||
model = BudgetGroup
|
||||
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")
|
||||
|
|
|
@ -27,7 +27,6 @@ DEBUG = True
|
|||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
|
@ -37,6 +36,7 @@ INSTALLED_APPS = [
|
|||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"authens",
|
||||
"rest_framework",
|
||||
# "django_extensions",
|
||||
"budget",
|
||||
|
@ -76,6 +76,22 @@ TEMPLATES = [
|
|||
|
||||
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
|
||||
# https://www.django-rest-framework.org/
|
||||
|
||||
|
|
|
@ -17,10 +17,11 @@ from django.contrib import admin
|
|||
from django.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
path("authens/", include("authens.urls")),
|
||||
path("admin/", admin.site.urls),
|
||||
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
|
||||
path("api/budget/", include("budget.urls")),
|
||||
path("api/agent/", include("agent.urls")),
|
||||
path("api/wishlist/", include("wishlist.urls")),
|
||||
# path("api/wishlist/", include("wishlist.urls")),
|
||||
path("", include("frontend.urls")),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue