diff --git a/areas/__pycache__/__init__.cpython-38.pyc b/areas/__pycache__/__init__.cpython-38.pyc index 3ff9165..3fed716 100644 Binary files a/areas/__pycache__/__init__.cpython-38.pyc and b/areas/__pycache__/__init__.cpython-38.pyc differ diff --git a/areas/__pycache__/admin.cpython-38.pyc b/areas/__pycache__/admin.cpython-38.pyc index c67ec55..f4e758a 100644 Binary files a/areas/__pycache__/admin.cpython-38.pyc and b/areas/__pycache__/admin.cpython-38.pyc differ diff --git a/areas/__pycache__/apps.cpython-38.pyc b/areas/__pycache__/apps.cpython-38.pyc index e7a6b78..9290f60 100644 Binary files a/areas/__pycache__/apps.cpython-38.pyc and b/areas/__pycache__/apps.cpython-38.pyc differ diff --git a/areas/__pycache__/forms.cpython-38.pyc b/areas/__pycache__/forms.cpython-38.pyc index c9f46ac..b1a2c81 100644 Binary files a/areas/__pycache__/forms.cpython-38.pyc and b/areas/__pycache__/forms.cpython-38.pyc differ diff --git a/areas/__pycache__/models.cpython-38.pyc b/areas/__pycache__/models.cpython-38.pyc index 83d08a8..04f8d72 100644 Binary files a/areas/__pycache__/models.cpython-38.pyc and b/areas/__pycache__/models.cpython-38.pyc differ diff --git a/areas/__pycache__/urls.cpython-38.pyc b/areas/__pycache__/urls.cpython-38.pyc index ddff2d1..7683456 100644 Binary files a/areas/__pycache__/urls.cpython-38.pyc and b/areas/__pycache__/urls.cpython-38.pyc differ diff --git a/areas/__pycache__/views.cpython-38.pyc b/areas/__pycache__/views.cpython-38.pyc index aae0ee2..0d77c06 100644 Binary files a/areas/__pycache__/views.cpython-38.pyc and b/areas/__pycache__/views.cpython-38.pyc differ diff --git a/digitaleagentur/__pycache__/__init__.cpython-38.pyc b/digitaleagentur/__pycache__/__init__.cpython-38.pyc index f932871..1ffa496 100644 Binary files a/digitaleagentur/__pycache__/__init__.cpython-38.pyc and b/digitaleagentur/__pycache__/__init__.cpython-38.pyc differ diff --git a/digitaleagentur/__pycache__/settings.cpython-38.pyc b/digitaleagentur/__pycache__/settings.cpython-38.pyc index 0ba5f30..c904e7a 100644 Binary files a/digitaleagentur/__pycache__/settings.cpython-38.pyc and b/digitaleagentur/__pycache__/settings.cpython-38.pyc differ diff --git a/digitaleagentur/__pycache__/urls.cpython-38.pyc b/digitaleagentur/__pycache__/urls.cpython-38.pyc index d5dc7f2..797d3e8 100644 Binary files a/digitaleagentur/__pycache__/urls.cpython-38.pyc and b/digitaleagentur/__pycache__/urls.cpython-38.pyc differ diff --git a/digitaleagentur/__pycache__/views.cpython-38.pyc b/digitaleagentur/__pycache__/views.cpython-38.pyc index ecd32fe..268c51d 100644 Binary files a/digitaleagentur/__pycache__/views.cpython-38.pyc and b/digitaleagentur/__pycache__/views.cpython-38.pyc differ diff --git a/digitaleagentur/__pycache__/wsgi.cpython-38.pyc b/digitaleagentur/__pycache__/wsgi.cpython-38.pyc index 3e8074e..c66704f 100644 Binary files a/digitaleagentur/__pycache__/wsgi.cpython-38.pyc and b/digitaleagentur/__pycache__/wsgi.cpython-38.pyc differ diff --git a/news/__pycache__/__init__.cpython-38.pyc b/news/__pycache__/__init__.cpython-38.pyc index fe38ad1..50d4891 100644 Binary files a/news/__pycache__/__init__.cpython-38.pyc and b/news/__pycache__/__init__.cpython-38.pyc differ diff --git a/news/__pycache__/admin.cpython-38.pyc b/news/__pycache__/admin.cpython-38.pyc index 144b68c..8692976 100644 Binary files a/news/__pycache__/admin.cpython-38.pyc and b/news/__pycache__/admin.cpython-38.pyc differ diff --git a/news/__pycache__/apps.cpython-38.pyc b/news/__pycache__/apps.cpython-38.pyc index c643216..45a5cfe 100644 Binary files a/news/__pycache__/apps.cpython-38.pyc and b/news/__pycache__/apps.cpython-38.pyc differ diff --git a/news/__pycache__/forms.cpython-38.pyc b/news/__pycache__/forms.cpython-38.pyc index 2903330..4f2a036 100644 Binary files a/news/__pycache__/forms.cpython-38.pyc and b/news/__pycache__/forms.cpython-38.pyc differ diff --git a/news/__pycache__/models.cpython-38.pyc b/news/__pycache__/models.cpython-38.pyc index b32eaa5..bd27abd 100644 Binary files a/news/__pycache__/models.cpython-38.pyc and b/news/__pycache__/models.cpython-38.pyc differ diff --git a/news/__pycache__/urls.cpython-38.pyc b/news/__pycache__/urls.cpython-38.pyc index 329ef64..4f0ef46 100644 Binary files a/news/__pycache__/urls.cpython-38.pyc and b/news/__pycache__/urls.cpython-38.pyc differ diff --git a/news/__pycache__/views.cpython-38.pyc b/news/__pycache__/views.cpython-38.pyc index 069e8d5..f23ea34 100644 Binary files a/news/__pycache__/views.cpython-38.pyc and b/news/__pycache__/views.cpython-38.pyc differ diff --git a/orga/__pycache__/__init__.cpython-38.pyc b/orga/__pycache__/__init__.cpython-38.pyc index 496d807..5fbb46a 100644 Binary files a/orga/__pycache__/__init__.cpython-38.pyc and b/orga/__pycache__/__init__.cpython-38.pyc differ diff --git a/orga/__pycache__/admin.cpython-38.pyc b/orga/__pycache__/admin.cpython-38.pyc index 6513846..52eca0c 100644 Binary files a/orga/__pycache__/admin.cpython-38.pyc and b/orga/__pycache__/admin.cpython-38.pyc differ diff --git a/orga/__pycache__/apps.cpython-38.pyc b/orga/__pycache__/apps.cpython-38.pyc index 52f5b45..bad2d21 100644 Binary files a/orga/__pycache__/apps.cpython-38.pyc and b/orga/__pycache__/apps.cpython-38.pyc differ diff --git a/orga/__pycache__/models.cpython-38.pyc b/orga/__pycache__/models.cpython-38.pyc index 96f69e5..0ceedb8 100644 Binary files a/orga/__pycache__/models.cpython-38.pyc and b/orga/__pycache__/models.cpython-38.pyc differ diff --git a/orga/__pycache__/urls.cpython-38.pyc b/orga/__pycache__/urls.cpython-38.pyc index 442122f..dbd2557 100644 Binary files a/orga/__pycache__/urls.cpython-38.pyc and b/orga/__pycache__/urls.cpython-38.pyc differ diff --git a/orga/__pycache__/views.cpython-38.pyc b/orga/__pycache__/views.cpython-38.pyc index bdc046f..8f8bb8b 100644 Binary files a/orga/__pycache__/views.cpython-38.pyc and b/orga/__pycache__/views.cpython-38.pyc differ diff --git a/standards/__pycache__/__init__.cpython-38.pyc b/standards/__pycache__/__init__.cpython-38.pyc index 3efa48c..10c9914 100644 Binary files a/standards/__pycache__/__init__.cpython-38.pyc and b/standards/__pycache__/__init__.cpython-38.pyc differ diff --git a/standards/__pycache__/admin.cpython-38.pyc b/standards/__pycache__/admin.cpython-38.pyc index a4a2637..636f01b 100644 Binary files a/standards/__pycache__/admin.cpython-38.pyc and b/standards/__pycache__/admin.cpython-38.pyc differ diff --git a/standards/__pycache__/apps.cpython-38.pyc b/standards/__pycache__/apps.cpython-38.pyc index 4552384..4506211 100644 Binary files a/standards/__pycache__/apps.cpython-38.pyc and b/standards/__pycache__/apps.cpython-38.pyc differ diff --git a/standards/__pycache__/forms.cpython-38.pyc b/standards/__pycache__/forms.cpython-38.pyc index 26a019c..a2f4a40 100644 Binary files a/standards/__pycache__/forms.cpython-38.pyc and b/standards/__pycache__/forms.cpython-38.pyc differ diff --git a/standards/__pycache__/models.cpython-38.pyc b/standards/__pycache__/models.cpython-38.pyc index 49f2123..fdd798a 100644 Binary files a/standards/__pycache__/models.cpython-38.pyc and b/standards/__pycache__/models.cpython-38.pyc differ diff --git a/standards/__pycache__/urls.cpython-38.pyc b/standards/__pycache__/urls.cpython-38.pyc index 29e42d3..67f12f1 100644 Binary files a/standards/__pycache__/urls.cpython-38.pyc and b/standards/__pycache__/urls.cpython-38.pyc differ diff --git a/standards/__pycache__/views.cpython-38.pyc b/standards/__pycache__/views.cpython-38.pyc index c6ad04a..09985db 100644 Binary files a/standards/__pycache__/views.cpython-38.pyc and b/standards/__pycache__/views.cpython-38.pyc differ diff --git a/tasks/__pycache__/__init__.cpython-38.pyc b/tasks/__pycache__/__init__.cpython-38.pyc index 5761d3d..ba2b443 100644 Binary files a/tasks/__pycache__/__init__.cpython-38.pyc and b/tasks/__pycache__/__init__.cpython-38.pyc differ diff --git a/tasks/__pycache__/admin.cpython-38.pyc b/tasks/__pycache__/admin.cpython-38.pyc index 64cf5df..4785bcc 100644 Binary files a/tasks/__pycache__/admin.cpython-38.pyc and b/tasks/__pycache__/admin.cpython-38.pyc differ diff --git a/tasks/__pycache__/apps.cpython-38.pyc b/tasks/__pycache__/apps.cpython-38.pyc index 1b8289c..acb7215 100644 Binary files a/tasks/__pycache__/apps.cpython-38.pyc and b/tasks/__pycache__/apps.cpython-38.pyc differ diff --git a/tasks/__pycache__/forms.cpython-38.pyc b/tasks/__pycache__/forms.cpython-38.pyc index bfae0d8..7d05cbf 100644 Binary files a/tasks/__pycache__/forms.cpython-38.pyc and b/tasks/__pycache__/forms.cpython-38.pyc differ diff --git a/tasks/__pycache__/models.cpython-38.pyc b/tasks/__pycache__/models.cpython-38.pyc index 45cdb3b..d012e57 100644 Binary files a/tasks/__pycache__/models.cpython-38.pyc and b/tasks/__pycache__/models.cpython-38.pyc differ diff --git a/tasks/__pycache__/urls.cpython-38.pyc b/tasks/__pycache__/urls.cpython-38.pyc index fbe82ce..065fae8 100644 Binary files a/tasks/__pycache__/urls.cpython-38.pyc and b/tasks/__pycache__/urls.cpython-38.pyc differ diff --git a/tasks/__pycache__/views.cpython-38.pyc b/tasks/__pycache__/views.cpython-38.pyc index c25b548..2d837b9 100644 Binary files a/tasks/__pycache__/views.cpython-38.pyc and b/tasks/__pycache__/views.cpython-38.pyc differ diff --git a/users/__pycache__/__init__.cpython-38.pyc b/users/__pycache__/__init__.cpython-38.pyc index 1988400..09287f9 100644 Binary files a/users/__pycache__/__init__.cpython-38.pyc and b/users/__pycache__/__init__.cpython-38.pyc differ diff --git a/users/__pycache__/admin.cpython-38.pyc b/users/__pycache__/admin.cpython-38.pyc index 407ba3c..131dcf0 100644 Binary files a/users/__pycache__/admin.cpython-38.pyc and b/users/__pycache__/admin.cpython-38.pyc differ diff --git a/users/__pycache__/apps.cpython-38.pyc b/users/__pycache__/apps.cpython-38.pyc index cea3da8..e12f316 100644 Binary files a/users/__pycache__/apps.cpython-38.pyc and b/users/__pycache__/apps.cpython-38.pyc differ diff --git a/users/__pycache__/models.cpython-38.pyc b/users/__pycache__/models.cpython-38.pyc index 6a63d41..0ec8d15 100644 Binary files a/users/__pycache__/models.cpython-38.pyc and b/users/__pycache__/models.cpython-38.pyc differ diff --git a/users/__pycache__/priomodel.cpython-38.pyc b/users/__pycache__/priomodel.cpython-38.pyc index f822ee2..e0c5566 100644 Binary files a/users/__pycache__/priomodel.cpython-38.pyc and b/users/__pycache__/priomodel.cpython-38.pyc differ diff --git a/users/__pycache__/signals.cpython-38.pyc b/users/__pycache__/signals.cpython-38.pyc index a854aad..46f1761 100644 Binary files a/users/__pycache__/signals.cpython-38.pyc and b/users/__pycache__/signals.cpython-38.pyc differ diff --git a/users/__pycache__/urls.cpython-38.pyc b/users/__pycache__/urls.cpython-38.pyc index 8024ef2..2a7610d 100644 Binary files a/users/__pycache__/urls.cpython-38.pyc and b/users/__pycache__/urls.cpython-38.pyc differ diff --git a/users/__pycache__/usersforms.cpython-38.pyc b/users/__pycache__/usersforms.cpython-38.pyc index eff3788..a6d2408 100644 Binary files a/users/__pycache__/usersforms.cpython-38.pyc and b/users/__pycache__/usersforms.cpython-38.pyc differ diff --git a/users/__pycache__/views.cpython-38.pyc b/users/__pycache__/views.cpython-38.pyc index 0fc6dae..92b9385 100644 Binary files a/users/__pycache__/views.cpython-38.pyc and b/users/__pycache__/views.cpython-38.pyc differ diff --git a/users/templates/users/base.html b/users/templates/users/base.html index 4bf0ce9..9fafef0 100644 --- a/users/templates/users/base.html +++ b/users/templates/users/base.html @@ -188,7 +188,7 @@ + +{% endblock content %} \ No newline at end of file diff --git a/users/usersforms.py b/users/usersforms.py index 8c1c265..a70ccf4 100644 --- a/users/usersforms.py +++ b/users/usersforms.py @@ -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="

Bereich "+area.name+"

") + else: + self.fields['area_'+str(area.pk)] = forms.BooleanField(required=False, initial=False, label="

Bereich "+area.name+"

") + + 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="
"+task.name+"
") + else: + self.fields['task_'+str(task.pk)] = forms.BooleanField(required=False, initial=False, label="
"+task.name+"
") \ No newline at end of file diff --git a/users/views.py b/users/views.py index 2c3e141..e8e7e3c 100644 --- a/users/views.py +++ b/users/views.py @@ -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,42 +328,71 @@ 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)) - - # 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 - - print(finaldata) - - user_first_name = user.first_name - user_last_name = user.last_name - user_id = user.pk + finaldata = {} context = { - 'active_link' : '', - 'finaldata' : finaldata, - 'user_first_name' : user_first_name, - 'user_last_name' : user_last_name, - 'user_id' : user_id - } + '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) + + for area in areas: + if area.pk in area_ids: + area.usersfield.add(user) + else: + area.usersfield.remove(user) + area.save() + + 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' : '', + 'user_first_name' : user_first_name, + 'user_last_name' : user_last_name, + 'user_id' : user_id, + 'form' : form + } return render(request, 'users/users_areatasks.html', context)