Compare commits

..

No commits in common. "d719822199ca66c7cd3717532ecba618fbd7bbf9" and "80577d89de49bb0219e98b9528519a209858dd66" have entirely different histories.

5 changed files with 55 additions and 62 deletions

View File

@ -127,7 +127,7 @@ USE_TZ = True
STATIC_URL = 'static/'
STATICFILES_DIRS = [
BASE_DIR / "static"
BASEDIR / "static"
]
# Default primary key field type

View File

@ -1,16 +1,15 @@
from django.urls import path
from .views import person_views
from .views import account_views
from . import views
urlpatterns = [
path('members/', person_views.members, name='members'),
path('members/details/<int:id>', person_views.details, name="details"),
path('members/create/', person_views.create, name="create"),
path('members/edit/<int:id>', person_views.edit, name="edit"),
path('members/delete/<int:id>', person_views.delete, name="delete"),
path('members/account/details/<int:id>', account_views.details_account, name="details_account"),
path('members/account/edit/<int:id>', account_views.edit_account, name="edit_account"),
path('members/account/create/<int:id>', account_views.create_account, name="create_account"),
path('members/account/edit/<int:id>', account_views.edit_account, name="edit_account"),
path('members/account/delete/<int:id>', account_views.delete_account, name="delete_account"),
path('members/', views.members, name='members'),
path('members/details/<int:id>', views.details, name="details"),
path('members/create/', views.create, name="create"),
path('members/edit/<int:id>', views.edit, name="edit"),
path('members/delete/<int:id>', views.delete, name="delete"),
path('members/account/details/<int:id>', views.details_account, name="details_account"),
path('members/account/edit/<int:id>', views.edit_account, name="edit_account"),
path('members/account/create/<int:id>', views.create_account, name="create_account"),
path('members/account/edit/<int:id>', views.edit_account, name="edit_account"),
path('members/account/delete/<int:id>', views.delete_account, name="delete_account"),
]

View File

@ -2,8 +2,8 @@ from django.http import HttpResponse
from django.shortcuts import render, redirect, get_object_or_404
from django.template import loader
from django.db.models import Count
from ..models import Person, UserAccount
from ..forms import PersonForm
from .models import Person, UserAccount
from .forms import PersonForm, AccountForm
def members(request):
mymembers=Person.objects.annotate(accounts=Count('benutzerkonten'))
@ -50,3 +50,44 @@ def delete(request, id):
person.delete()
return redirect('members')
return render(request, 'confirm_delete.html', { 'person': person})
def details_account(request, id):
account = get_object_or_404(Account, id=id)
template = loader.get_template("details_account.html")
context = {
'account': account,
}
return HttpResponse(template.render(context, request))
def create_account(request, id):
person = get_object_or_404(Person, id=id)
if request.method == "POST":
form = AccountForm(request.POST)
if form.is_valid():
account=form.save(commit=False)
account.person = person
account.save()
return redirect("details", person.id)
else:
form = AccountForm()
return render(request, "account_form.html", {'form': form, 'action': 'Erstellen', 'id': id})
def edit_account(request, id):
account = get_object_or_404(UserAccount, id=id)
if request.method == 'POST':
form = AccountForm(request.POST, instance=account)
if form.is_valid():
form.save()
return redirect('details', account.person.id)
else:
form = AccountForm(instance=account)
return render(request, 'account_form.html', {'form': form, 'action': "Bearbeiten" , 'id': account.person.id})
def delete_account(request, id):
account=get_object_or_404(UserAccount, id=id)
person_id=account.person.id
if (request.method=='POST'):
account.delete()
return redirect("details", person_id)
return render(request, "confirm_account_delete.html", {'account': account, 'id': account.person.id})

View File

@ -1,47 +0,0 @@
from django.http import HttpResponse
from django.shortcuts import render, redirect, get_object_or_404
from django.template import loader
from django.db.models import Count
from ..models import Person, UserAccount
from ..forms import PersonForm, AccountForm
def details_account(request, id):
account = get_object_or_404(Account, id=id)
template = loader.get_template("details_account.html")
context = {
'account': account,
}
return HttpResponse(template.render(context, request))
def create_account(request, id):
person = get_object_or_404(Person, id=id)
if request.method == "POST":
form = AccountForm(request.POST)
if form.is_valid():
account=form.save(commit=False)
account.person = person
account.save()
return redirect("details", person.id)
else:
form = AccountForm()
return render(request, "account_form.html", {'form': form, 'action': 'Erstellen', 'id': id})
def edit_account(request, id):
account = get_object_or_404(UserAccount, id=id)
if request.method == 'POST':
form = AccountForm(request.POST, instance=account)
if form.is_valid():
form.save()
return redirect('details', account.person.id)
else:
form = AccountForm(instance=account)
return render(request, 'account_form.html', {'form': form, 'action': "Bearbeiten" , 'id': account.person.id})
def delete_account(request, id):
account=get_object_or_404(UserAccount, id=id)
person_id=account.person.id
if (request.method=='POST'):
account.delete()
return redirect("details", person_id)
return render(request, "confirm_account_delete.html", {'account': account, 'id': account.person.id})