diff --git a/areas/__pycache__/__init__.cpython-38.pyc b/areas/__pycache__/__init__.cpython-38.pyc index 3ff9165..30d31c2 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..cda1b66 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..ef3a5a0 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..42894cb 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..0f8b47f 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..4a41cf2 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 f424ff3..34faae4 100644 Binary files a/areas/__pycache__/views.cpython-38.pyc and b/areas/__pycache__/views.cpython-38.pyc differ diff --git a/areas/migrations/__pycache__/0001_initial.cpython-38.pyc b/areas/migrations/__pycache__/0001_initial.cpython-38.pyc index 4b1a5c3..7fdd250 100644 Binary files a/areas/migrations/__pycache__/0001_initial.cpython-38.pyc and b/areas/migrations/__pycache__/0001_initial.cpython-38.pyc differ diff --git a/areas/migrations/__pycache__/__init__.cpython-38.pyc b/areas/migrations/__pycache__/__init__.cpython-38.pyc index 1f7cdb4..b38d0f0 100644 Binary files a/areas/migrations/__pycache__/__init__.cpython-38.pyc and b/areas/migrations/__pycache__/__init__.cpython-38.pyc differ diff --git a/areas/templates/areas/areas_update.html b/areas/templates/areas/areas_update.html index cb2e1ba..9ba7364 100644 --- a/areas/templates/areas/areas_update.html +++ b/areas/templates/areas/areas_update.html @@ -2,9 +2,6 @@ {% load static %} {% load crispy_forms_tags %} {% block content %} - - -

Bereich aktualisieren


@@ -117,11 +114,7 @@ $("#addusertoareabtn").prop('disabled', true); } - //Ajax-Call to add a User to Area - function addUser(numb){ - console.log("USER HINZU: " + numb); - } - + //Check for valid input on inputfield function checkValue(){ var g = $('#searchusers').val(); diff --git a/digitaleagentur/__pycache__/__init__.cpython-38.pyc b/digitaleagentur/__pycache__/__init__.cpython-38.pyc index f932871..ac75e04 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 e373470..df45778 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 a77585b..2ada6cb 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..a73478d 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..742abfb 100644 Binary files a/digitaleagentur/__pycache__/wsgi.cpython-38.pyc and b/digitaleagentur/__pycache__/wsgi.cpython-38.pyc differ diff --git a/standards/__pycache__/__init__.cpython-38.pyc b/standards/__pycache__/__init__.cpython-38.pyc index 3efa48c..d4d13ac 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 142f54f..544bd60 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..29e7acd 100644 Binary files a/standards/__pycache__/apps.cpython-38.pyc and b/standards/__pycache__/apps.cpython-38.pyc differ diff --git a/standards/__pycache__/models.cpython-38.pyc b/standards/__pycache__/models.cpython-38.pyc index 8733a2b..f0076c4 100644 Binary files a/standards/__pycache__/models.cpython-38.pyc and b/standards/__pycache__/models.cpython-38.pyc differ diff --git a/standards/migrations/__pycache__/__init__.cpython-38.pyc b/standards/migrations/__pycache__/__init__.cpython-38.pyc index 29deb7e..b2c215d 100644 Binary files a/standards/migrations/__pycache__/__init__.cpython-38.pyc and b/standards/migrations/__pycache__/__init__.cpython-38.pyc differ diff --git a/tasks/__pycache__/__init__.cpython-38.pyc b/tasks/__pycache__/__init__.cpython-38.pyc index 5761d3d..b6825b0 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 c894904..43ae268 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..cccf356 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 a8b6ffc..4a42374 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 20ff2e8..c2a1882 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 5229c03..bbb20b4 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 78dd4fe..581a336 100644 Binary files a/tasks/__pycache__/views.cpython-38.pyc and b/tasks/__pycache__/views.cpython-38.pyc differ diff --git a/tasks/admin.py b/tasks/admin.py index 8c38f3f..7cf348d 100644 --- a/tasks/admin.py +++ b/tasks/admin.py @@ -1,3 +1,4 @@ from django.contrib import admin - +from .models import Tasks # Register your models here. +admin.site.register(Tasks) \ No newline at end of file diff --git a/tasks/forms.py b/tasks/forms.py index 44cf0a1..7095ce8 100644 --- a/tasks/forms.py +++ b/tasks/forms.py @@ -1,27 +1,22 @@ from django import forms from django.forms import ModelForm from .models import Tasks +from areas.models import Areas class TasksAddTaskForm(forms.ModelForm): - visible = forms.CheckboxInput() class Meta: - model = Tasks + model =Tasks labels = { "name" : "Aufgabenname", "area" : "Übergeordneter Bereich", "desc" : "Beschreibung", "visible": "Im Organigramm sichtbar" + } + fields = ['name', 'area', 'desc', 'visible'] - } - fields['visible'] = forms.HiddenInput() - fields = ['name', 'area', 'desc', 'visible'] - + def __init__(self, *args, **kwargs): + user = kwargs.pop('user') + super(TasksAddTaskForm, self).__init__(*args, **kwargs) + self.fields['area'].queryset = Areas.objects.filter(agency__pk=user.profile.agency.pk) - - - #def __init__(self, user=None, *args, **kwargs): - # super().__init__(*args, **kwargs) - # if(user != None): - # users_of_agency = User.objects.filter(profile__agency__pk=user.profile.agency.pk) - # self.fields['usersfield'].queryset = users_of_agency \ No newline at end of file diff --git a/tasks/migrations/__pycache__/0001_initial.cpython-38.pyc b/tasks/migrations/__pycache__/0001_initial.cpython-38.pyc index ff34734..a488890 100644 Binary files a/tasks/migrations/__pycache__/0001_initial.cpython-38.pyc and b/tasks/migrations/__pycache__/0001_initial.cpython-38.pyc differ diff --git a/tasks/migrations/__pycache__/0002_tasks_name.cpython-38.pyc b/tasks/migrations/__pycache__/0002_tasks_name.cpython-38.pyc index d481111..a063065 100644 Binary files a/tasks/migrations/__pycache__/0002_tasks_name.cpython-38.pyc and b/tasks/migrations/__pycache__/0002_tasks_name.cpython-38.pyc differ diff --git a/tasks/migrations/__pycache__/__init__.cpython-38.pyc b/tasks/migrations/__pycache__/__init__.cpython-38.pyc index ded374b..11e65aa 100644 Binary files a/tasks/migrations/__pycache__/__init__.cpython-38.pyc and b/tasks/migrations/__pycache__/__init__.cpython-38.pyc differ diff --git a/tasks/urls.py b/tasks/urls.py index 7919907..41a892a 100644 --- a/tasks/urls.py +++ b/tasks/urls.py @@ -1,7 +1,7 @@ from django.urls import path from django.contrib.auth import views as auth_views from django.contrib.auth.decorators import login_required, permission_required -from .views import TasksManagement, TasksAddTask +from .views import TasksManagement, TasksAddTask, TasksDeleteView, TasksUpdateView from . import views ''' Permissions definiert in models.py bei USERS und dann hier vor die View geschrieben! @@ -10,7 +10,7 @@ Permissions definiert in models.py bei USERS und dann hier vor die View geschrie urlpatterns = [ path('', permission_required('users.tasks_management')(TasksManagement.as_view(template_name="tasks/tasks_management.html")), name='tasks-management'), path('addtask/', permission_required('users.tasks_management')(TasksAddTask.as_view(template_name="tasks/tasks_add.html")), name='tasks-addtask'), - + path('tasks//delete', permission_required('users.tasks_management')(TasksDeleteView.as_view()), name='tasks-delete'), + path('tasks//', permission_required('users.tasks_management')(TasksUpdateView.as_view()), name='tasks-manage'), + path('areaajax/', views.task_addtasks_ajax, name="task-ajaxview") ] - - diff --git a/tasks/views.py b/tasks/views.py index 7abdd65..f78c9aa 100644 --- a/tasks/views.py +++ b/tasks/views.py @@ -1,9 +1,11 @@ from django.shortcuts import render from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.auth.models import User from django.views.generic import CreateView, ListView, UpdateView, DetailView, DeleteView, View from .models import Tasks from .forms import TasksAddTaskForm from django.contrib import messages +from django.http import HttpResponse, JsonResponse # Create your views here. class TasksManagement(LoginRequiredMixin, ListView): @@ -23,17 +25,16 @@ class TasksAddTask(LoginRequiredMixin, CreateView): success_url = '/tasks' form_class = TasksAddTaskForm - #def get(self,request,*args, **kwargs): - # # User ist der hier Aufgerufene, bzw. das Profil! - # return render (request, self.template_name, {'form':self.form_class(self.request.user), 'active_link': 'areasmanagement'}) + def get_form_kwargs(self): + kwargs = super(TasksAddTask, self).get_form_kwargs() + kwargs['user'] = self.request.user + return kwargs - - # Adding active_link def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({'active_link' : 'tasksmanagement'}) return context - + def form_valid(self, form): # Send message to the site messages.success(self.request, f'Aufgabe angelegt!') @@ -41,3 +42,76 @@ class TasksAddTask(LoginRequiredMixin, CreateView): form.instance.agency = self.request.user.profile.agency form.instance.created_area_by = self.request.user return super().form_valid(form) + +class TasksDeleteView(LoginRequiredMixin, DeleteView): + model = Tasks + success_url = '/tasks' + template_name = 'tasks/tasks_confirm_delete.html' + + def get_context_data(self, **kwargs): + context = super(TasksDeleteView, self).get_context_data(**kwargs) + context['active_link'] = 'tasksmanagement' + return context + +# Hier andere Nutzer ändern, wenn man Usersmanagement darf! +class TasksUpdateView(LoginRequiredMixin, UpdateView): + model = Tasks + template_name = 'tasks/tasks_update.html' + success_url = '/tasks' + form_class = TasksAddTaskForm + + def get_form_kwargs(self): + kwargs = super(TasksUpdateView, self).get_form_kwargs() + kwargs['user'] = self.request.user + return kwargs + + def form_valid(self, form): + # Send message to the site + messages.success(self.request, f'Aufgabe aktualisiert!') + return super().form_valid(form) + + def get_context_data(self, **kwargs): + context = super(TasksUpdateView, self).get_context_data(**kwargs) + tasks = Tasks.objects.get(pk=context['object'].pk) + # User still in Area + context['added_users'] = tasks.usersfield.all() + # Get all Users from same Agency which are NOT in context_added_users + possible_users = User.objects.filter(profile__agency__pk=self.request.user.profile.agency.pk).exclude(pk__in=context['added_users']) + context['possible_users'] = possible_users + # Active-Link for Base-Design + context['active_link'] = 'tasksmanagement' + # Area ID + context['objectid'] = context['object'].pk + return context + +def task_addtasks_ajax(request): + if request.method == 'GET': + + # ADD USER TO MANY-TO-MANY USERSFIELD + if request.GET['action'] == 'adduser': + task = Tasks.objects.get(pk=request.GET['objectid']) + task.usersfield.add(User.objects.get(pk=request.GET['userid'])) + task.save() + # REMOVE USER TO MANY-TO-MANY USERSFIELD + elif request.GET['action'] == 'remuser': + task = Tasks.objects.get(pk=request.GET['objectid']) + task.usersfield.remove(User.objects.get(pk=request.GET['userid'])) + task.save() + userid = request.GET['userid'] + workinguser = User.objects.get(pk=userid) + username_clean = workinguser.first_name + " " + workinguser.last_name + + # Getting Remaining-Users + task = Tasks.objects.get(pk=request.GET['objectid']) + added_users = task.usersfield.all() + possible_users = User.objects.filter(profile__agency__pk=request.user.profile.agency.pk).exclude(pk__in=added_users) + possible_users_js = list(possible_users.values()) + # Cleaned out, that only data is neede will send to the side (first/last-name and id) + final_possible_users = {} + for ele in possible_users_js: + final_possible_users.update({'first_name':ele['first_name'],'last_name':ele['last_name'],'id':ele['id']}) + # Counter for remaining users to show/hide "Keine Mitarbeiter"-Div + remaining_users_counter = len(added_users) + return JsonResponse({'userid' : userid, 'username_clean' : username_clean, 'remaining_users':possible_users_js, 'remaining_users_counter' : final_possible_users}) + else: + return HttpResponse("Request method is not a GET") diff --git a/users/__pycache__/__init__.cpython-38.pyc b/users/__pycache__/__init__.cpython-38.pyc index 1988400..a18065b 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 a7ab0e1..ecc0bbd 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..eb52b10 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 a25dac1..02990ae 100644 Binary files a/users/__pycache__/models.cpython-38.pyc and b/users/__pycache__/models.cpython-38.pyc differ diff --git a/users/__pycache__/signals.cpython-38.pyc b/users/__pycache__/signals.cpython-38.pyc index c3ecb59..09da039 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 6495e0a..16ecda0 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 484239d..22b2bd8 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 0d3488f..105ee35 100644 Binary files a/users/__pycache__/views.cpython-38.pyc and b/users/__pycache__/views.cpython-38.pyc differ diff --git a/users/migrations/__pycache__/0001_initial.cpython-38.pyc b/users/migrations/__pycache__/0001_initial.cpython-38.pyc index 86fdee3..60c7420 100644 Binary files a/users/migrations/__pycache__/0001_initial.cpython-38.pyc and b/users/migrations/__pycache__/0001_initial.cpython-38.pyc differ diff --git a/users/migrations/__pycache__/0002_auto_20191204_0857.cpython-38.pyc b/users/migrations/__pycache__/0002_auto_20191204_0857.cpython-38.pyc index ffe61ff..e4eeaf4 100644 Binary files a/users/migrations/__pycache__/0002_auto_20191204_0857.cpython-38.pyc and b/users/migrations/__pycache__/0002_auto_20191204_0857.cpython-38.pyc differ diff --git a/users/migrations/__pycache__/__init__.cpython-38.pyc b/users/migrations/__pycache__/__init__.cpython-38.pyc index e100748..593ee64 100644 Binary files a/users/migrations/__pycache__/__init__.cpython-38.pyc and b/users/migrations/__pycache__/__init__.cpython-38.pyc differ