Zuständigkeiten fertig
This commit is contained in:
parent
b6f493c3a5
commit
566ce3d68c
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -188,7 +188,7 @@
|
|||
<!-- Topbar Search -->
|
||||
<form class="d-none d-sm-inline-block form-inline mr-auto ml-md-3 my-2 my-md-0 mw-100 navbar-search">
|
||||
<div class="input-group">
|
||||
<input list="searchres" placeholder="Suche..." id="search_string" onchange="javascript:checkValue()" onkeyup="javascript:startSearch(this.value)" class="form-control bg-light border-0 small" >
|
||||
<input list="searchres" placeholder="Suche..." id="search_string" onchange="javascript:checkValueSearchStringGlobal()" onkeyup="javascript:startSearch(this.value)" class="form-control bg-light border-0 small" >
|
||||
<datalist id="searchres" >
|
||||
</datalist>
|
||||
|
||||
|
|
@ -337,7 +337,7 @@
|
|||
}
|
||||
|
||||
//Check valid input and go to standard by click
|
||||
function checkValue(){
|
||||
function checkValueSearchStringGlobal(){
|
||||
for(i = 0; i < document.getElementById("searchres").options.length; i++){
|
||||
var value = $("#search_string").val();
|
||||
var choosen = document.getElementById("searchres").options[i].value;
|
||||
|
|
|
|||
|
|
@ -5,13 +5,14 @@
|
|||
<h3>Bereiche und Aufgaben von {{ user_first_name }} {{ user_last_name }} bearbeiten</h3>
|
||||
<hr>
|
||||
<div class="col-12">
|
||||
{% for key in finaldata %}
|
||||
{{key}}
|
||||
{% endfor %}
|
||||
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
{{form|crispy}}
|
||||
</div>
|
||||
<a href="{% url 'users-dashboard' %}" class="btn btn-success">Speichern</a>
|
||||
<a href="{% url 'users-dashboard' %}" class="btn">Abbrechen</a>
|
||||
<button type="submit" href="{% url 'users-areataskupdate' user_id %}" class="btn btn-success">Speichern</button>
|
||||
<a href="{% url 'users-management' %}" class="btn">Abbrechen</a>
|
||||
</div>
|
||||
</form>
|
||||
</script>
|
||||
{% endblock content %}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ from django.contrib.auth.models import User
|
|||
from django.contrib.auth.forms import UserCreationForm
|
||||
from .models import Profile, Agency
|
||||
from django.contrib.auth.models import Permission
|
||||
from areas.models import Areas
|
||||
from tasks.models import Tasks
|
||||
|
||||
# Standard-User-Formular - NUR Username und Password wird hier genutzt
|
||||
class UsersAddNewUser(UserCreationForm):
|
||||
|
|
@ -75,3 +77,23 @@ class UsersPermForm(forms.Form):
|
|||
else:
|
||||
self.fields[ele[0]] = forms.BooleanField(required=False, initial=False, help_text=(ele[1]))
|
||||
|
||||
class UserAreaTaskForm(forms.Form):
|
||||
def __init__(self, user, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
areas = Areas.objects.filter(agency__pk=user.profile.agency.pk)
|
||||
tasks = Tasks.objects.filter(agency__pk=user.profile.agency.pk)
|
||||
|
||||
for area in areas:
|
||||
if user in area.usersfield.all():
|
||||
self.fields['area_'+str(area.pk)] = forms.BooleanField(required=False, initial=True, label="<h3>Bereich "+area.name+"</h3>")
|
||||
else:
|
||||
self.fields['area_'+str(area.pk)] = forms.BooleanField(required=False, initial=False, label="<h3>Bereich "+area.name+"</h3>")
|
||||
|
||||
for task in tasks:
|
||||
if task.area == area:
|
||||
if user in task.usersfield.all():
|
||||
self.fields['task_'+str(task.pk)] = forms.BooleanField(required=False, initial=True, label="<h5>"+task.name+"</h5>")
|
||||
else:
|
||||
self.fields['task_'+str(task.pk)] = forms.BooleanField(required=False, initial=False, label="<h5>"+task.name+"</h5>")
|
||||
|
|
@ -2,7 +2,7 @@ from django.shortcuts import render, redirect, reverse
|
|||
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.conf import settings
|
||||
from .usersforms import UsersAddNewUser, UsersAddProfileForm, UsersChangeProfil, AgencyUpdateForm, UsersPermForm
|
||||
from .usersforms import UsersAddNewUser, UsersAddProfileForm, UsersChangeProfil, AgencyUpdateForm, UsersPermForm, UserAreaTaskForm
|
||||
from django.views.generic import CreateView, ListView, UpdateView, DetailView, DeleteView, View
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.models import User
|
||||
|
|
@ -328,41 +328,70 @@ def searchStandardRouter(request):
|
|||
|
||||
def UsersAreaTaskUpdate(request, pk):
|
||||
|
||||
|
||||
user = User.objects.get(pk=pk)
|
||||
|
||||
finaldata = {}
|
||||
|
||||
if(user.profile.agency.pk != request.user.profile.agency.pk):
|
||||
return HttpResponseRedirect('users-dashboard')
|
||||
if request.user.profile.agency.pk != user.profile.agency.pk:
|
||||
return redirect('dashboard')
|
||||
else:
|
||||
areas = list(Areas.objects.filter(agency__pk=request.user.profile.agency.pk))
|
||||
tasks = list(Tasks.objects.filter(agency__pk=request.user.profile.agency.pk))
|
||||
finaldata = {}
|
||||
context = {
|
||||
'active_link' : 'usersmanagement',
|
||||
'user_id' : user.pk,
|
||||
}
|
||||
|
||||
if request.method == 'POST':
|
||||
form = request.POST
|
||||
areatask_formdata = list(form)
|
||||
# CRSF-Token löschen
|
||||
del areatask_formdata[0]
|
||||
|
||||
area_ids = []
|
||||
task_ids = []
|
||||
|
||||
for ar in areatask_formdata:
|
||||
tempdata = ar.split("_")
|
||||
if(tempdata[0] == 'area'):
|
||||
area_ids.append(int(tempdata[1]))
|
||||
elif(tempdata[0] == 'task'):
|
||||
task_ids.append(int(tempdata[1]))
|
||||
print(area_ids)
|
||||
print(task_ids)
|
||||
|
||||
areas = Areas.objects.filter(agency__pk=user.profile.agency.pk)
|
||||
tasks = Tasks.objects.filter(agency__pk=user.profile.agency.pk)
|
||||
|
||||
# Build final JSON-Form-Input
|
||||
# User in area/task 1, User NOT in area/task 0
|
||||
for area in areas:
|
||||
finaldata.update({'areapk': area.pk, 'areaname' : area.name, 'areauserstat' : 0, 'tasks' : {}})
|
||||
if(user in area.usersfield.all()):
|
||||
print(finaldata['areapk'])
|
||||
# finaldata['areapk'][len(finaldata)]['areauserstat'] = 1
|
||||
#for task in tasks:
|
||||
# if(task.area == area):
|
||||
# finaldata['areapk'][len(finaldata)]['tasks'].update({task.pk : {}})
|
||||
# finaldata['areapk'][len(finaldata)]['tasks'][task.pk].update({'taskname' : task.name, 'userstat' : 0})
|
||||
# if(user in task.usersfield.all()):
|
||||
# finaldata['areapk'][len(finaldata)]['tasks'][task.pk]['userstat'] = 1
|
||||
if area.pk in area_ids:
|
||||
area.usersfield.add(user)
|
||||
else:
|
||||
area.usersfield.remove(user)
|
||||
area.save()
|
||||
|
||||
print(finaldata)
|
||||
for task in tasks:
|
||||
if task.pk in task_ids:
|
||||
prio = Prio(user=User.objects.get(pk=pk), task=task)
|
||||
prio.save()
|
||||
task.usersfield.add(user)
|
||||
else:
|
||||
task.usersfield.remove(user)
|
||||
Prio.objects.filter(user__pk=pk).filter(task__pk=task.pk).delete()
|
||||
task.save()
|
||||
|
||||
|
||||
username_message = user.first_name + " " + user.last_name
|
||||
messages.success(request, f'Zuständigkeiten für {username_message} aktualisiert!')
|
||||
return redirect('users-management')
|
||||
else:
|
||||
form = UserAreaTaskForm(user)
|
||||
user_first_name = user.first_name
|
||||
user_last_name = user.last_name
|
||||
user_id = user.pk
|
||||
context = {
|
||||
'active_link' : '',
|
||||
'finaldata' : finaldata,
|
||||
'user_first_name' : user_first_name,
|
||||
'user_last_name' : user_last_name,
|
||||
'user_id' : user_id
|
||||
'user_id' : user_id,
|
||||
'form' : form
|
||||
}
|
||||
|
||||
return render(request, 'users/users_areatasks.html', context)
|
||||
|
|
|
|||
Loading…
Reference in New Issue