diff --git a/digitaleagentur/settings.py b/digitaleagentur/settings.py index 46a5249..40b9761 100644 --- a/digitaleagentur/settings.py +++ b/digitaleagentur/settings.py @@ -38,6 +38,8 @@ INSTALLED_APPS = [ 'standards.apps.StandardsConfig', 'crispy_forms', 'colorful', + 'ckeditor', + 'ckeditor_uploader', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -76,7 +78,39 @@ TEMPLATES = [ WSGI_APPLICATION = 'digitaleagentur.wsgi.application' +# CKEDITOR +CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js' +CKEDITOR_UPLOAD_PATH = "uploadsCK/" # <-- this folder you uploaded image saved in s3 under media folder +CKEDITOR_RESTRICT_BY_USER = True +CKEDITOR_REQUIRE_STAFF=False +AWS_QUERYSTRING_AUTH = True +CKEDITOR_IMAGE_BACKEND = "pillow" +CKEDITOR_CONFIGS = { + 'default': { + 'skin': 'moono-lisa', + 'toolbar_Basic': [ + ['Source', '-', 'Bold', 'Italic'] + ], + 'toolbar_YourCustomToolbarConfig': [ + {'name': 'basicstyles', + 'items': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']}, + {'name': 'paragraph', + 'items': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', + 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', + 'Language']}, + {'name': 'links', 'items': ['Link', 'Unlink']}, + {'name': 'styles', 'items': ['Styles', 'Format', 'Font', 'FontSize']}, + {'name': 'colors', 'items': ['TextColor', 'BGColor']}, + {'name': 'tools', 'items': ['Maximize', 'ShowBlocks']}, + {'name': 'insert', + 'items': ['Image', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak']}, + '/', # put this to force next toolbar on new line + ], + 'toolbar': 'YourCustomToolbarConfig', # put selected toolbar config here + }, + +} # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases diff --git a/digitaleagentur/urls.py b/digitaleagentur/urls.py index 1cfeebb..f900d7b 100644 --- a/digitaleagentur/urls.py +++ b/digitaleagentur/urls.py @@ -5,6 +5,8 @@ from django.conf import settings from django.conf.urls.static import static from users.views import AgencyCreateView from . import views +from ckeditor_uploader.views import upload + ''' ADMINPAGE - Verwaltung der Super-User - LOGIN-Page @@ -18,12 +20,14 @@ urlpatterns = [ path('dashboard/', include('users.urls'), name="dashboard"), path('areas/', include('areas.urls'), name="areas-management"), path('tasks/', include('tasks.urls'), name="tasks-management"), + path('standards/', include('standards.urls'), name="standards"), path('password-reset/', auth_views.PasswordResetView.as_view(template_name='users/password_reset.html'), name='password-reset'), path('password-reset/done/', auth_views.PasswordResetDoneView.as_view(template_name='users/password_reset_done.html'), name='password_reset_done'), path('password-reset-confirm///', auth_views.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'), name='password_reset_confirm'), path('password-reset-complete/', auth_views.PasswordResetCompleteView.as_view(template_name='users/password_reset_complete.html'), name='password_reset_complete'), path('register/', AgencyCreateView.as_view(template_name='users/register.html'), name='register'), - path('register/done', views.registerdone, name='register-done') + path('register/done', views.registerdone, name='register-done'), + path('ckeditor/', include('ckeditor_uploader.urls')), ] if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/media/uploadsCK/admin/2019/12/04/0003.png b/media/uploadsCK/admin/2019/12/04/0003.png new file mode 100644 index 0000000..a14eb67 Binary files /dev/null and b/media/uploadsCK/admin/2019/12/04/0003.png differ diff --git a/media/uploadsCK/admin/2019/12/04/0003_nMcw1ZC.png b/media/uploadsCK/admin/2019/12/04/0003_nMcw1ZC.png new file mode 100644 index 0000000..a14eb67 Binary files /dev/null and b/media/uploadsCK/admin/2019/12/04/0003_nMcw1ZC.png differ diff --git a/media/uploadsCK/admin/2019/12/04/0003_nMcw1ZC_thumb.png b/media/uploadsCK/admin/2019/12/04/0003_nMcw1ZC_thumb.png new file mode 100644 index 0000000..9213f0a Binary files /dev/null and b/media/uploadsCK/admin/2019/12/04/0003_nMcw1ZC_thumb.png differ diff --git a/media/uploadsCK/admin/2019/12/05/0002.png b/media/uploadsCK/admin/2019/12/05/0002.png new file mode 100644 index 0000000..5ac0ecb Binary files /dev/null and b/media/uploadsCK/admin/2019/12/05/0002.png differ diff --git a/media/uploadsCK/admin/2019/12/05/0002_thumb.png b/media/uploadsCK/admin/2019/12/05/0002_thumb.png new file mode 100644 index 0000000..78b6882 Binary files /dev/null and b/media/uploadsCK/admin/2019/12/05/0002_thumb.png differ diff --git a/standards/__pycache__/forms.cpython-38.pyc b/standards/__pycache__/forms.cpython-38.pyc new file mode 100644 index 0000000..c95268f Binary files /dev/null and b/standards/__pycache__/forms.cpython-38.pyc differ diff --git a/standards/__pycache__/urls.cpython-38.pyc b/standards/__pycache__/urls.cpython-38.pyc new file mode 100644 index 0000000..fd24e82 Binary files /dev/null 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 new file mode 100644 index 0000000..4af9385 Binary files /dev/null and b/standards/__pycache__/views.cpython-38.pyc differ diff --git a/standards/admin.py b/standards/admin.py index 8c38f3f..35b08d8 100644 --- a/standards/admin.py +++ b/standards/admin.py @@ -1,3 +1,5 @@ from django.contrib import admin - +from .models import Standards +# Register your models here. +admin.site.register(Standards) # Register your models here. diff --git a/standards/forms.py b/standards/forms.py new file mode 100644 index 0000000..930a4bc --- /dev/null +++ b/standards/forms.py @@ -0,0 +1,102 @@ +from django import forms +from django.forms import ModelForm +from .models import Standards +from areas.models import Areas +from tasks.models import Tasks +from ckeditor.widgets import CKEditorWidget + +class StandardAddStandard(forms.ModelForm): + + class Meta: + model =Standards + labels = { + "name" : "Titel", + "area" : "Übergeordneter Bereich", + "task" : "Aufgabenbereich", + } + fields = ['name', 'area', 'task'] + ''' + + Hier werden die Elemente für die DropDowns erstellt, damit + ein Standard nur einem Aufgabenbereich aus einem Bereich zugewiesen wird. + + Damit nach der Auswahl des Bereichs auch eine valide Aufgabe ankommt, wird diese + hier manuel validiert und das Query-Set mit der Bereichsauswahl geladen. + + ''' + + def __init__(self, *args, **kwargs): + super(StandardAddStandard, self).__init__(*args, **kwargs) + self.fields['area'].queryset = Areas.objects.filter(agency__pk=kwargs['instance'].profile.agency.pk) + self.fields['task'].queryset = Tasks.objects.none() + if 'area' in self.data: + try: + areaid = int(self.data.get('area')) + self.fields['task'].queryset = Tasks.objects.filter(area__id=areaid).order_by('name') + except (ValueError, TypeError): + pass + + elif self.instance.pk: + self.fields['task'].queryset = Tasks.objects.none() + + +class StandardAddStandardEditor(forms.ModelForm): + + #content = forms.CharField(widget=CKEditorWidget()) + + class Meta: + model = Standards + labels = { + "content" : "Inhalt" + } + fields = ['content'] + + +class StandardUpdateStandard(forms.ModelForm): + + class Meta: + model =Standards + labels = { + "name" : "Titel", + "area" : "Übergeordneter Bereich", + "task" : "Aufgabenbereich", + } + fields = ['name', 'area', 'task'] + ''' + + Hier werden die Elemente für die DropDowns erstellt, damit + ein Standard nur einem Aufgabenbereich aus einem Bereich zugewiesen wird. + + Damit nach der Auswahl des Bereichs auch eine valide Aufgabe ankommt, wird diese + hier manuel validiert und das Query-Set mit der Bereichsauswahl geladen. + + ''' + + def __init__(self, *args, **kwargs): + loggeduser = kwargs['instance'].created_standard_by + standard = kwargs['instance'] + super(StandardUpdateStandard, self).__init__(*args, **kwargs) + self.fields['area'].queryset = Areas.objects.filter(agency__pk=loggeduser.profile.agency.pk) + # Dummy PK + self.fields['task'].queryset = Tasks.objects.filter(area__pk=standard.area.pk) + if 'area' in self.data: + try: + areaid = int(self.data.get('area')) + self.fields['task'].queryset = Tasks.objects.filter(area__id=areaid).order_by('name') + except (ValueError, TypeError): + pass + elif loggeduser.pk: + self.fields['task'].queryset = Tasks.objects.filter(area__pk=standard.area.pk) + + + +class StandardUpdateStandardEditor(forms.ModelForm): + + #content = forms.CharField(widget=CKEditorWidget()) + + class Meta: + model = Standards + labels = { + "content" : "Inhalt" + } + fields = ['content'] \ No newline at end of file diff --git a/standards/migrations/0001_initial.py b/standards/migrations/0001_initial.py new file mode 100644 index 0000000..ca2973e --- /dev/null +++ b/standards/migrations/0001_initial.py @@ -0,0 +1,35 @@ +# Generated by Django 2.2.7 on 2019-12-04 16:51 + +import datetime +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('users', '0002_auto_20191204_0857'), + ('tasks', '0002_tasks_name'), + ('areas', '0001_initial'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Standards', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(default='', max_length=200)), + ('content', models.TextField(blank=True, max_length=3000)), + ('created_area_date', models.DateField(blank=True, default=datetime.date.today)), + ('public', models.BooleanField(default=True)), + ('agency', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='users.Agency')), + ('area', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='areas.Areas')), + ('created_area_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), + ('task', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='tasks.Tasks')), + ], + ), + ] diff --git a/standards/migrations/0002_auto_20191204_1808.py b/standards/migrations/0002_auto_20191204_1808.py new file mode 100644 index 0000000..93f81e5 --- /dev/null +++ b/standards/migrations/0002_auto_20191204_1808.py @@ -0,0 +1,52 @@ +# Generated by Django 2.2.7 on 2019-12-04 17:08 + +import datetime +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('standards', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='standards', + old_name='created_area_by', + new_name='created_standard_by', + ), + migrations.RenameField( + model_name='standards', + old_name='created_area_date', + new_name='created_standard_date', + ), + migrations.AddField( + model_name='standards', + name='last_modifed_by', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.PROTECT, related_name='user_modified_standard', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='standards', + name='last_modifed_on', + field=models.DateField(blank=True, default=datetime.date.today), + ), + migrations.AddField( + model_name='standards', + name='published_by', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.PROTECT, related_name='user_published_standard', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='standards', + name='published_on', + field=models.DateField(blank=True, default=datetime.date.today), + ), + migrations.AlterField( + model_name='standards', + name='public', + field=models.BooleanField(default=False), + ), + ] diff --git a/standards/migrations/0003_auto_20191204_1813.py b/standards/migrations/0003_auto_20191204_1813.py new file mode 100644 index 0000000..9103fee --- /dev/null +++ b/standards/migrations/0003_auto_20191204_1813.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.7 on 2019-12-04 17:13 + +from django.db import migrations +import tinymce.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('standards', '0002_auto_20191204_1808'), + ] + + operations = [ + migrations.AlterField( + model_name='standards', + name='content', + field=tinymce.models.HTMLField(), + ), + ] diff --git a/standards/migrations/0004_auto_20191204_1831.py b/standards/migrations/0004_auto_20191204_1831.py new file mode 100644 index 0000000..23715b8 --- /dev/null +++ b/standards/migrations/0004_auto_20191204_1831.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.7 on 2019-12-04 17:31 + +import ckeditor.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('standards', '0003_auto_20191204_1813'), + ] + + operations = [ + migrations.AlterField( + model_name='standards', + name='content', + field=ckeditor.fields.RichTextField(blank=True, null=True), + ), + ] diff --git a/standards/migrations/0005_auto_20191204_1924.py b/standards/migrations/0005_auto_20191204_1924.py new file mode 100644 index 0000000..7b2a4a6 --- /dev/null +++ b/standards/migrations/0005_auto_20191204_1924.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.7 on 2019-12-04 18:24 + +import ckeditor_uploader.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('standards', '0004_auto_20191204_1831'), + ] + + operations = [ + migrations.AlterField( + model_name='standards', + name='content', + field=ckeditor_uploader.fields.RichTextUploadingField(blank=True), + ), + ] diff --git a/standards/migrations/0006_auto_20191204_2003.py b/standards/migrations/0006_auto_20191204_2003.py new file mode 100644 index 0000000..8e699a0 --- /dev/null +++ b/standards/migrations/0006_auto_20191204_2003.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.7 on 2019-12-04 19:03 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('standards', '0005_auto_20191204_1924'), + ] + + operations = [ + migrations.RenameField( + model_name='standards', + old_name='last_modifed_by', + new_name='last_modified_by', + ), + migrations.RenameField( + model_name='standards', + old_name='last_modifed_on', + new_name='last_modified_on', + ), + ] diff --git a/standards/migrations/__pycache__/0001_initial.cpython-38.pyc b/standards/migrations/__pycache__/0001_initial.cpython-38.pyc new file mode 100644 index 0000000..b87b518 Binary files /dev/null and b/standards/migrations/__pycache__/0001_initial.cpython-38.pyc differ diff --git a/standards/migrations/__pycache__/0002_auto_20191204_1808.cpython-38.pyc b/standards/migrations/__pycache__/0002_auto_20191204_1808.cpython-38.pyc new file mode 100644 index 0000000..b1adb18 Binary files /dev/null and b/standards/migrations/__pycache__/0002_auto_20191204_1808.cpython-38.pyc differ diff --git a/standards/migrations/__pycache__/0003_auto_20191204_1813.cpython-38.pyc b/standards/migrations/__pycache__/0003_auto_20191204_1813.cpython-38.pyc new file mode 100644 index 0000000..9f0f303 Binary files /dev/null and b/standards/migrations/__pycache__/0003_auto_20191204_1813.cpython-38.pyc differ diff --git a/standards/migrations/__pycache__/0004_auto_20191204_1831.cpython-38.pyc b/standards/migrations/__pycache__/0004_auto_20191204_1831.cpython-38.pyc new file mode 100644 index 0000000..fd9bb41 Binary files /dev/null and b/standards/migrations/__pycache__/0004_auto_20191204_1831.cpython-38.pyc differ diff --git a/standards/migrations/__pycache__/0005_auto_20191204_1924.cpython-38.pyc b/standards/migrations/__pycache__/0005_auto_20191204_1924.cpython-38.pyc new file mode 100644 index 0000000..9b1971c Binary files /dev/null and b/standards/migrations/__pycache__/0005_auto_20191204_1924.cpython-38.pyc differ diff --git a/standards/migrations/__pycache__/0006_auto_20191204_2003.cpython-38.pyc b/standards/migrations/__pycache__/0006_auto_20191204_2003.cpython-38.pyc new file mode 100644 index 0000000..0c6eb96 Binary files /dev/null and b/standards/migrations/__pycache__/0006_auto_20191204_2003.cpython-38.pyc differ diff --git a/standards/models.py b/standards/models.py index 71a8362..57ec138 100644 --- a/standards/models.py +++ b/standards/models.py @@ -1,3 +1,35 @@ from django.db import models +from tinymce.models import HTMLField +from django.contrib.auth.models import User +from users.models import Agency +from django.urls import reverse +from areas.models import Areas +from tasks.models import Tasks +import datetime +from ckeditor_uploader.fields import RichTextUploadingField -# Create your models here. +class Standards(models.Model): + + agency = models.ForeignKey(Agency, on_delete=models.CASCADE) + area = models.ForeignKey(Areas, on_delete=models.CASCADE) + task = models.ForeignKey(Tasks, on_delete=models.CASCADE) + name = models.CharField(max_length=200, blank=False, default="") + content = RichTextUploadingField(blank=True, verbose_name='Inhalt') + + created_standard_by = models.ForeignKey(User, on_delete=models.PROTECT) + created_standard_date = models.DateField(default=datetime.date.today, blank=True) + + published_by = models.ForeignKey(User, on_delete=models.PROTECT, related_name='user_published_standard', default=None) + published_on = models.DateField(default=datetime.date.today, blank=True) + + last_modified_by = models.ForeignKey(User, on_delete=models.PROTECT, related_name='user_modified_standard', default=None) + last_modified_on = models.DateField(default=datetime.date.today, blank=True) + + public = models.BooleanField(default=False) + + def __str__(self): + return f'{self.name}' + + # Hier Path für Templates des Models mit Parametern + def get_absolute_url(self): + return reverse('standards-update', kwargs={'pk':self.pk}) \ No newline at end of file diff --git a/standards/templates/standards/standard_confirm_delete.html b/standards/templates/standards/standard_confirm_delete.html new file mode 100644 index 0000000..469268b --- /dev/null +++ b/standards/templates/standards/standard_confirm_delete.html @@ -0,0 +1,20 @@ +{% extends "users/base.html" %} +{% load crispy_forms_tags %} +{% block content %} +
+
+
+ +
+
+
+ +
+ {% csrf_token %} +
+   + Abbrechen +
+
+
+{% endblock content %} \ No newline at end of file diff --git a/standards/templates/standards/standards_add.html b/standards/templates/standards/standards_add.html new file mode 100644 index 0000000..7bd6f81 --- /dev/null +++ b/standards/templates/standards/standards_add.html @@ -0,0 +1,36 @@ +{% extends "users/base.html" %} +{% load crispy_forms_tags %} +{% block content %} +
+

Neuen Standard anlegen

+
+
+ {% csrf_token %} + {{normalForm|crispy}} + {{editorForm.media}} + {{editorForm}} + +

Wenn ein Standard erstellt wurde, kann er nur von einer Person mit dem Recht Standards bearbeiten und freischalten veröffentlicht werden.

+
+   + Abbrechen +
+
+ +{% endblock content %} diff --git a/standards/templates/standards/standards_management.html b/standards/templates/standards/standards_management.html new file mode 100644 index 0000000..1db3d56 --- /dev/null +++ b/standards/templates/standards/standards_management.html @@ -0,0 +1,47 @@ +{% extends "users/base.html" %} +{% block content %} +
+

Standards

+
+

+ Standards dokumentieren und erläutern verschiedenen Verfahren, strukturiert nach Bereichen und Aufgaben. +

+ +
+
+ {% for item in standards_of_agency %} + +
+
+
+ {{item.name}} + {% if item.created_standard_by == user or perms.users.standard_management %} + + + {% endif %} +
+
+
{{item.created_standard_by.first_name}} {{item.created_standard_by.last_name}}
Zuletzt bearbeitet von {{ item.last_modified_by.first_name }} {{ item.last_modified_by.last_name }} am {{ item.last_modified_on }}
+ +

{{ item.content|truncatechars:250|safe}}

+
+
+
+ + {% endfor%} +
+{% endblock content %} diff --git a/standards/templates/standards/standards_tasklist.html b/standards/templates/standards/standards_tasklist.html new file mode 100644 index 0000000..2d2e6c4 --- /dev/null +++ b/standards/templates/standards/standards_tasklist.html @@ -0,0 +1,4 @@ + +{% for task in tasks %} + +{% endfor %} \ No newline at end of file diff --git a/standards/templates/standards/standards_update.html b/standards/templates/standards/standards_update.html new file mode 100644 index 0000000..3b9a1a8 --- /dev/null +++ b/standards/templates/standards/standards_update.html @@ -0,0 +1,35 @@ +{% extends "users/base.html" %} +{% load crispy_forms_tags %} +{% block content %} +
+

Standard bearbeiten

+
+
+ {% csrf_token %} + {{normalForm|crispy}} + {{editorForm.media}} + {{editorForm}} +

Wenn ein Standard bearbeitet wurde, kann er nur von einer Person mit dem Recht Standards bearbeiten und freischalten wieder veröffentlicht werden. Ein Standard wird nach Bearbeitung als Nicht veröffentlicht gesetzt.

+
+   + Abbrechen +
+
+ +{% endblock content %} diff --git a/standards/urls.py b/standards/urls.py new file mode 100644 index 0000000..4105fcf --- /dev/null +++ b/standards/urls.py @@ -0,0 +1,17 @@ +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 StandardsManagement, StandardAdd +from .views import StandardsManagement, StandardDeleteView +from . import views +''' +Permissions definiert in models.py bei USERS und dann hier vor die View geschrieben! +''' + +urlpatterns = [ + path('', StandardsManagement.as_view(template_name="standards/standards_management.html"), name='standards'), + path('standardadd/', views.StandardAdd, name='standard-add'), + path('standardupdate/', views.StandardUpdate, name='standard-update'), + path('ajax/loadtasks/', views.load_tasks, name='ajax_loadtasks'), + path('standards//delete', StandardDeleteView.as_view(), name='standard-delete'), +] diff --git a/standards/views.py b/standards/views.py index 91ea44a..5f61c3a 100644 --- a/standards/views.py +++ b/standards/views.py @@ -1,3 +1,138 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect +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 Standards +from django.contrib import messages +from django.http import HttpResponse, JsonResponse +from .forms import StandardAddStandard, StandardAddStandardEditor, StandardUpdateStandard, StandardUpdateStandardEditor +from django.contrib.auth.decorators import login_required +from tasks.models import Tasks +from datetime import datetime # Create your views here. +class StandardsManagement(LoginRequiredMixin, ListView): + model = Standards + # Adding active_link + # Loading only user same agency + # Change context and return for template-data + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + # # Get all Users of the Same Agency as logged user + standards_of_agency = Standards.objects.filter(agency__pk=self.request.user.profile.agency.pk) + context.update({'active_link' : 'standards', 'standards_of_agency' : standards_of_agency}) + return context + +''' +class StandardAdd(LoginRequiredMixin, CreateView): + model = Standards + success_url = '/standards' + form_class = StandardAddStandardForm + + def get_form_kwargs(self): + kwargs = super(StandardAdd, self).get_form_kwargs() + kwargs['user'] = self.request.user + return kwargs + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context.update({'active_link' : 'standards'}) + return context + + def form_valid(self, form): + # Send message to the site + messages.success(self.request, f'Standard angelegt!') + form.instance.agency = self.request.user.profile.agency + form.instance.created_standard_by = self.request.user + form.instance.published_by = self.request.user + form.instance.last_modifed_by = self.request.user + return super().form_valid(form) + +''' +@login_required +def StandardAdd(request): + if request.method == 'POST': + normalForm = StandardAddStandard(request.POST, instance=request.user) + editorForm = StandardAddStandardEditor(request.POST, instance=request.user) + + if editorForm.is_valid() and normalForm.is_valid(): + normalForm.agency = request.user.profile.agency + normalForm.created_standard_by = request.user + normalForm.published_by = request.user + normalForm.last_modifed_by = request.user + normalForm.save() + editorForm.save() + new_standard = Standards() + new_standard.agency = request.user.profile.agency + new_standard.created_standard_by = request.user + new_standard.published_by = request.user + new_standard.last_modified_by = request.user + new_standard.task = normalForm.cleaned_data['task'] + new_standard.area = normalForm.cleaned_data['area'] + new_standard.name = normalForm.cleaned_data['name'] + new_standard.content = editorForm.cleaned_data['content'] + new_standard.save() + tempstandardname = normalForm.cleaned_data['name'] + messages.success(request, f'Standard {tempstandardname} hinzugefügt! Dieser muss noch veröffentlicht werden.') + return redirect('standards') + + else: + normalForm = StandardAddStandard(instance=request.user) + editorForm = StandardAddStandardEditor(instance=request.user) + + + context = { + 'normalForm' : normalForm, + 'editorForm' : editorForm, + 'active_link' : 'standards' + } + return render(request, 'standards/standards_add.html', context) + + +@login_required +def StandardUpdate(request, id): + standard = Standards.objects.get(pk=id) + if request.method == 'POST': + normalForm = StandardUpdateStandard(request.POST, instance=standard) + editorForm = StandardUpdateStandardEditor(request.POST, instance=standard) + + if editorForm.is_valid() and normalForm.is_valid(): + existing_standard = Standards.objects.get(pk=id) + existing_standard.last_modified_by = request.user + existing_standard.last_modified_on = datetime.now() + existing_standard.task = normalForm.cleaned_data['task'] + existing_standard.area = normalForm.cleaned_data['area'] + existing_standard.name = normalForm.cleaned_data['name'] + existing_standard.content = editorForm.cleaned_data['content'] + existing_standard.public = False + existing_standard.save() + messages.success(request, f'Standard {existing_standard.name} aktualisiert!') + return redirect('/standards') + + else: + normalForm = StandardUpdateStandard(instance=standard) + editorForm = StandardUpdateStandardEditor(instance=standard) + + + context = { + 'normalForm' : normalForm, + 'editorForm' : editorForm, + 'active_link' : 'standards' + } + return render(request, 'standards/standards_update.html', context) + +def load_tasks(request): + areaid = request.GET.get('areaid') + tasks = Tasks.objects.filter(area__id=areaid).order_by('name') + return render(request, 'standards/standards_tasklist.html', {'tasks': tasks}) + + +class StandardDeleteView(LoginRequiredMixin, DeleteView): + model = Standards + success_url = '/standards' + template_name = 'standards/standard_confirm_delete.html' + + def get_context_data(self, **kwargs): + context = super(StandardDeleteView, self).get_context_data(**kwargs) + context['active_link'] = 'standards' + return context \ No newline at end of file diff --git a/tasks/models.py b/tasks/models.py index 2df55ea..c4b2905 100644 --- a/tasks/models.py +++ b/tasks/models.py @@ -13,8 +13,8 @@ Model Tasks class Tasks(models.Model): - agency = models.ForeignKey(Agency, on_delete=models.PROTECT) - area = models.ForeignKey(Areas, on_delete=models.PROTECT) + agency = models.ForeignKey(Agency, on_delete=models.CASCADE) + area = models.ForeignKey(Areas, on_delete=models.CASCADE) name = models.CharField(max_length=200, blank=False, default="") desc = models.TextField(max_length=3000, blank=True) usersfield = models.ManyToManyField(User, blank=True, related_name='users_in_task') diff --git a/users/models.py b/users/models.py index 3b3772d..494e7eb 100644 --- a/users/models.py +++ b/users/models.py @@ -104,5 +104,5 @@ class Profile(models.Model): ('users_usermanagement', 'Benutzer bearbeiten'), ('areas_management', 'Bereiche bearbeiten'), ('tasks_management', 'Aufgabenbereiche bearbeiten'), - ('standard_management', 'Standards bearbeiten und freischalten') + ('standard_management', 'Standards bearbeiten und freischalten') ] \ No newline at end of file diff --git a/users/templates/users/base.html b/users/templates/users/base.html index 9ab6139..827d344 100644 --- a/users/templates/users/base.html +++ b/users/templates/users/base.html @@ -62,8 +62,12 @@ Agentur
+ {% if active_link == 'standards' %} +