Verwandte Standards
{% for standard in standard.linked_standards.all %}
-
-
{% setbool False %}
{% for ag in standard.visibleby.all %}
{% if request.user|has_group:ag.group.name %}
@@ -211,7 +212,7 @@
{% setbool False %}
{% for passgrous in pass.visibleby.all %}
-
+
{% if user|has_group:passgrous.group.name %}
{% setbool True %}
{% endif %}
diff --git a/standards/urls.py b/standards/urls.py
index 3946033..95649a3 100644
--- a/standards/urls.py
+++ b/standards/urls.py
@@ -10,6 +10,7 @@ Permissions definiert in models.py bei USERS und dann hier vor die View geschrie
urlpatterns = [
path('', StandardsManagement.as_view(template_name="standards/standards_management.html"), name='standards'),
path('standardadd/', views.StandardAdd, name='standard-add'),
+ path('standardadd/', views.StandardAdd, name='standard-add'),
path('standardupdate/', views.StandardUpdate, name='standard-update'),
path('ajax/loadtasks/', views.load_tasks, name='ajax_loadtasks'),
path('ajups/', views.updatesbyajax, name='update_standard_by_ajax'),
diff --git a/standards/views.py b/standards/views.py
index 0c85d19..83ecef0 100644
--- a/standards/views.py
+++ b/standards/views.py
@@ -111,137 +111,338 @@ def checkUserDirRights(request, startdir, userid):
@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.created_standard_date = datetime.now()
- 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.created_standard_date = datetime.now()
- new_standard.last_modified_on = datetime.now()
- 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.public = normalForm.cleaned_data['public']
+def StandardAdd(request, id=False):
+ # NEW STANDARD
+ if(id == False):
+ 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.created_standard_date = datetime.now()
+ 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.created_standard_date = datetime.now()
+ new_standard.last_modified_on = datetime.now()
+ 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.public = normalForm.cleaned_data['public']
- new_standard.freefield_content = normalForm.cleaned_data['freefield_content']
- new_standard.freefield_title = normalForm.cleaned_data['freefield_title']
+ new_standard.freefield_content = normalForm.cleaned_data['freefield_content']
+ new_standard.freefield_title = normalForm.cleaned_data['freefield_title']
+
+ new_standard.save()
+
+ #new_standard.representative.set(normalForm.cleaned_data['representative'])
+ #new_standard.executor.set(normalForm.cleaned_data['executor'])
+ #new_standard.authority.set(normalForm.cleaned_data['authority'])
+
+ # REPRESENTATIV
+ verant = normalForm.cleaned_data['us_verant'].split(",")
+ for v in verant:
+ if(v.isdigit()):
+ new_standard.authority.add(User.objects.get(pk=v))
+
+ # EXECUTORS
+ ex = normalForm.cleaned_data['us_ex'].split(",")
+ for v in ex:
+ if(v.isdigit()):
+ new_standard.executor.add(User.objects.get(pk=v))
+
+ # AUTHORITY
+ ver = normalForm.cleaned_data['us_ver'].split(",")
+ for v in ver:
+ if(v.isdigit()):
+ new_standard.representative.add(User.objects.get(pk=v))
+
+ # ADD GROUPS
+ groups = normalForm.cleaned_data['checked_groups'].split(",")
+
+ for g in groups:
+ if(g.isdigit()):
+ new_standard.visibleby.add(AgencyGroup.objects.get(pk=g))
+
+ # ADD STANDARDS
+ standards = normalForm.cleaned_data['added_standards'].split(",")
+ for s in standards:
+ if(s.isdigit()):
+ new_standard.linked_standards.add(Standards.objects.get(pk=s))
+
+ # ADD FILES
+ files = normalForm.cleaned_data['added_files'].split(",")
+ for f in files:
+ if(f.isdigit()):
+ new_standard.addedfiles.add(DataFile.objects.get(pk=f))
+
+ # ADD QUICKLINKS
+ quicklinks = normalForm.cleaned_data['added_quicklinks'].split(",")
+ for f in quicklinks:
+ if(f.isdigit()):
+ new_standard.addedquicklinks.add(QuickLinks.objects.get(pk=f))
+
+ # ADD PASSWORDS
+ addedpasswords = normalForm.cleaned_data['added_passwords'].split(",")
+ for f in addedpasswords:
+ if(f.isdigit()):
+ new_standard.addedpasswords.add(AGPassword.objects.get(pk=f))
+
+ # ADD CONTACTS
+ contacts = normalForm.cleaned_data['added_contacts'].split(",")
+ for f in contacts:
+ if(f.isdigit()):
+ new_standard.addedcontacts.add(AGContacts.objects.get(pk=f))
+
+
+ tempstandardname = normalForm.cleaned_data['name']
+ if(new_standard.public and request.user.has_perm('users.standardmanager')):
+ messages.success(request, f'Standard {tempstandardname} hinzugefügt und veröffentlicht.')
+ else:
+ new_standard.public = False
+ new_standard.save()
+ 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)
+
+
+ possibleFilesByVisible = []
+
+ allfiles = DataFile.objects.filter(agency=request.user.profile.agency)
+
+ for f in allfiles:
+ actParent = DataDir.objects.get(pk=f.parent.pk)
+ if actParent.is_root:
+ possibleFilesByVisible.append(f)
+ else:
+ if(checkUserDirRights(request, actParent, request.user.pk)):
+ possibleFilesByVisible.append(f)
+
+ context = {
+ 'normalForm' : normalForm,
+ 'editorForm' : editorForm,
+ 'active_link' : 'standards',
+ 'agencygroups' : AgencyGroup.objects.filter(agency=request.user.profile.agency),
+ 'usersofagency' : User.objects.filter(profile__agency=request.user.profile.agency),
+ 'files' : possibleFilesByVisible,
+ 'parentid' : list(DataDir.objects.filter(agency=request.user.profile.agency, is_root=True))[0].pk,
+ 'standards' : Standards.objects.filter(agency=request.user.profile.agency, public=True),
+ 'quicklinks' : QuickLinks.objects.filter(agency=request.user.profile.agency),
+ 'contacts' : AGContacts.objects.filter(agency=request.user.profile.agency),
+ 'passwords' : AGPassword.objects.filter(agency=request.user.profile.agency),
+ }
+ return render(request, 'standards/standards_add.html', context)
+ # UPDATE A STANDARD
+ else:
+ standard = Standards.objects.get(pk=id, agency=request.user.profile.agency)
+ # SAVE UPDATED STANDARD
+ if request.method == 'POST':
+ normalForm = StandardUpdateStandard(request.POST, instance=standard)
+ editorForm = StandardUpdateStandardEditor(request.POST, instance=standard)
+
+ if editorForm.is_valid() and normalForm.is_valid():
+ standard.last_modified_by = request.user
+ standard.last_modified_on = datetime.now()
+ standard.task = normalForm.cleaned_data['task']
+ standard.area = normalForm.cleaned_data['area']
+ standard.name = normalForm.cleaned_data['name']
+ standard.public = normalForm.cleaned_data['public']
+ standard.content = editorForm.cleaned_data['content']
+ standard.freefield_content = normalForm.cleaned_data['freefield_content']
+ standard.freefield_title = normalForm.cleaned_data['freefield_title']
+
+
+ # ADD NEW INFOS
+ # REPRESENTATIV
+ verant = normalForm.cleaned_data['us_verant'].split(",")
+ for v in verant:
+ if(v.isdigit()):
+ standard.authority.add(User.objects.get(pk=v))
+
+ # EXECUTORS
+ ex = normalForm.cleaned_data['us_ex'].split(",")
+ for v in ex:
+ if(v.isdigit()):
+ standard.executor.add(User.objects.get(pk=v))
+
+ # AUTHORITY
+ ver = normalForm.cleaned_data['us_ver'].split(",")
+ for v in ver:
+ if(v.isdigit()):
+ standard.representative.add(User.objects.get(pk=v))
+
+ # ADD GROUPS
+ groups = normalForm.cleaned_data['checked_groups'].split(",")
+
+ for g in groups:
+ if(g.isdigit()):
+ standard.visibleby.add(AgencyGroup.objects.get(pk=g))
+
+ # ADD STANDARDS
+ standards = normalForm.cleaned_data['added_standards'].split(",")
+ for s in standards:
+ if(s.isdigit()):
+ standard.linked_standards.add(Standards.objects.get(pk=s))
+
+ # ADD FILES
+ files = normalForm.cleaned_data['added_files'].split(",")
+ for f in files:
+ if(f.isdigit()):
+ standard.addedfiles.add(DataFile.objects.get(pk=f))
+
+ # ADD QUICKLINKS
+ quicklinks = normalForm.cleaned_data['added_quicklinks'].split(",")
+ for f in quicklinks:
+ if(f.isdigit()):
+ standard.addedquicklinks.add(QuickLinks.objects.get(pk=f))
+
+ # ADD PASSWORDS
+ addedpasswords = normalForm.cleaned_data['added_passwords'].split(",")
+ for f in addedpasswords:
+ if(f.isdigit()):
+ standard.addedpasswords.add(AGPassword.objects.get(pk=f))
+
+ # ADD CONTACTS
+ contacts = normalForm.cleaned_data['added_contacts'].split(",")
+ for f in contacts:
+ if(f.isdigit()):
+ standard.addedcontacts.add(AGContacts.objects.get(pk=f))
+
+ # ADD TO NETWORKS
+ networks = normalForm.cleaned_data['checked_networks'].split(",")
+ for f in networks:
+ if(f.isdigit()):
+ tempnetwork = AgencyNetwork.objects.get(pk=f)
+ tempnetwork.standards.add(standard)
+
+ if request.user.has_perm('users.standardmanager'):
+ messages.success(request, f'Standard {standard.name} aktualisiert!')
+ else:
+ if standard.public:
+ standard.public = False
+ messages.warning(request, f'Standard {standard.name} aktualisiert und ist nicht mehr öffentlich, damit Änderungen geprüft werden können.')
+ else:
+ messages.success(request, f'Standard {standard.name} aktualisiert!')
+ standard.save()
+ return redirect('/standards')
+ # SHOW EXISTING STANDARD
+ else:
+ normalForm = StandardUpdateStandard(instance=standard)
+ editorForm = StandardUpdateStandardEditor(instance=standard)
+ # GET ALL DATAS FROM STANDARD
+ # FILES
+ possibleFilesByVisible = []
+
+ allfiles = DataFile.objects.filter(agency=request.user.profile.agency)
+ # Get all files by view
+ for f in allfiles:
+ actParent = DataDir.objects.get(pk=f.parent.pk)
+ if actParent.is_root:
+ possibleFilesByVisible.append(f)
+ else:
+ if(checkUserDirRights(request, actParent, request.user.pk)):
+ possibleFilesByVisible.append(f)
+
+ # Remove files which are in standard
+ for f in possibleFilesByVisible:
+ if f in standard.addedfiles.all():
+ possibleFilesByVisible.remove(f)
+
+
+ # STANDARDS
+ possible_standards = []
+ allstandards = Standards.objects.filter(agency=request.user.profile.agency, public=True)
+
+ for s in allstandards:
+ if s not in standard.linked_standards.all():
+ possible_standards.append(s)
+
+
+ # USERS VER AUTH EX
+ possible_verant = User.objects.filter(profile__agency__pk=request.user.profile.agency.pk)
+ possible_verant_final = []
+ for pv in possible_verant:
+ if pv not in standard.authority.all():
+ possible_verant_final.append(pv)
+
+ possible_ex = User.objects.filter(profile__agency__pk=request.user.profile.agency.pk)
+ possible_ex_final = []
+ for pv in possible_ex:
+ if pv not in standard.executor.all():
+ possible_ex_final.append(pv)
+
+ possible_ver = User.objects.filter(profile__agency__pk=request.user.profile.agency.pk)
+ possible_ver_final = []
+ for pv in possible_ver:
+ if pv not in standard.representative.all():
+ possible_ver_final.append(pv)
+
+ # QUICKLINKS
+ possible_quicklinks = []
+ quicklinks = QuickLinks.objects.filter(agency=request.user.profile.agency)
+
+ for q in quicklinks:
+ if q not in standard.addedquicklinks.all():
+ possible_quicklinks.append(q)
+
+ # CONTACTS
+ possible_contacts = []
+ contacts = AGContacts.objects.filter(agency=request.user.profile.agency)
+
+ for q in contacts:
+ if q not in standard.addedcontacts.all():
+ possible_contacts.append(q)
+
+ # PASSWORDS
+ possible_passwords = []
+ contacts = AGPassword.objects.filter(agency=request.user.profile.agency)
+
+ for q in contacts:
+ if q not in standard.addedpasswords.all():
+ possible_passwords.append(q)
+
+ # AGENCYNETWORKS
+
+ agencynetworks_all = AgencyNetwork.objects.all()
+ agencynetworks = []
+
+ for a in agencynetworks_all:
+ if request.user.profile.agency in a.adminagencys.all() or request.user.profile.agency in a.members.all() or request.user.profile.agency in a.sharemembers.all():
+ agencynetworks.append(a)
# GROUPS
- new_standard.save()
+ # Nicht nötig, da alles über agencygroups und direkt im Standard gemacht wird
- #new_standard.representative.set(normalForm.cleaned_data['representative'])
- #new_standard.executor.set(normalForm.cleaned_data['executor'])
- #new_standard.authority.set(normalForm.cleaned_data['authority'])
-
- # REPRESENTATIV
- verant = normalForm.cleaned_data['us_verant'].split(",")
- for v in verant:
- if(v.isdigit()):
- new_standard.authority.add(User.objects.get(pk=v))
-
- # EXECUTORS
- ex = normalForm.cleaned_data['us_ex'].split(",")
- for v in ex:
- if(v.isdigit()):
- new_standard.executor.add(User.objects.get(pk=v))
-
- # AUTHORITY
- ver = normalForm.cleaned_data['us_ver'].split(",")
- for v in ver:
- if(v.isdigit()):
- new_standard.representative.add(User.objects.get(pk=v))
-
- # ADD GROUPS
- groups = normalForm.cleaned_data['checked_groups'].split(",")
-
- for g in groups:
- if(g.isdigit()):
- new_standard.visibleby.add(AgencyGroup.objects.get(pk=g))
-
- # ADD STANDARDS
- standards = normalForm.cleaned_data['added_standards'].split(",")
- for s in standards:
- if(s.isdigit()):
- new_standard.linked_standards.add(Standards.objects.get(pk=s))
-
- # ADD FILES
- files = normalForm.cleaned_data['added_files'].split(",")
- for f in files:
- if(f.isdigit()):
- new_standard.addedfiles.add(DataFile.objects.get(pk=f))
-
- # ADD QUICKLINKS
- quicklinks = normalForm.cleaned_data['added_quicklinks'].split(",")
- for f in quicklinks:
- if(f.isdigit()):
- new_standard.addedquicklinks.add(QuickLinks.objects.get(pk=f))
-
- # ADD PASSWORDS
- addedpasswords = normalForm.cleaned_data['added_passwords'].split(",")
- for f in addedpasswords:
- if(f.isdigit()):
- new_standard.addedpasswords.add(AGPassword.objects.get(pk=f))
-
- # ADD CONTACTS
- contacts = normalForm.cleaned_data['added_contacts'].split(",")
- for f in contacts:
- if(f.isdigit()):
- new_standard.addedcontacts.add(AGContacts.objects.get(pk=f))
-
-
- tempstandardname = normalForm.cleaned_data['name']
- if(new_standard.public and request.user.has_perm('users.standardmanager')):
- messages.success(request, f'Standard {tempstandardname} hinzugefügt und veröffentlicht.')
- else:
- new_standard.public = False
- new_standard.save()
- 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)
-
-
- possibleFilesByVisible = []
-
- allfiles = DataFile.objects.filter(agency=request.user.profile.agency)
-
- for f in allfiles:
- actParent = DataDir.objects.get(pk=f.parent.pk)
- if actParent.is_root:
- possibleFilesByVisible.append(f)
- else:
- if(checkUserDirRights(request, actParent, request.user.pk)):
- possibleFilesByVisible.append(f)
-
- context = {
- 'normalForm' : normalForm,
- 'editorForm' : editorForm,
- 'active_link' : 'standards',
- 'agencygroups' : AgencyGroup.objects.filter(agency=request.user.profile.agency),
- 'usersofagency' : User.objects.filter(profile__agency=request.user.profile.agency),
- 'files' : possibleFilesByVisible,
- 'parentid' : list(DataDir.objects.filter(agency=request.user.profile.agency, is_root=True))[0].pk,
- 'standards' : Standards.objects.filter(agency=request.user.profile.agency, public=True),
- 'quicklinks' : QuickLinks.objects.filter(agency=request.user.profile.agency),
- 'contacts' : AGContacts.objects.filter(agency=request.user.profile.agency),
- 'passwords' : AGPassword.objects.filter(agency=request.user.profile.agency),
- }
- return render(request, 'standards/standards_add.html', context)
+ context = {
+ 'normalForm' : normalForm,
+ 'editorForm' : editorForm,
+ 'standard' : standard,
+ 'files' : possibleFilesByVisible,
+ 'standard_possible' : possible_standards,
+ 'poss_verant' : possible_verant_final,
+ 'poss_ex' : possible_ex_final,
+ 'poss_ver' : possible_ver_final,
+ 'possible_quicklinks' : possible_quicklinks,
+ 'possible_passwords' : possible_passwords,
+ 'possible_contacts' : possible_contacts,
+ 'agencynetworks' : agencynetworks,
+ 'agencygroups' : AgencyGroup.objects.filter(agency=request.user.profile.agency),
+ 'parentid' : list(DataDir.objects.filter(agency=request.user.profile.agency, is_root=True))[0].pk,
+ 'active_link' : 'standards',
+ 'update' : True
+ }
+ return render(request, 'standards/standards_add.html', context)
@login_required
diff --git a/users/admin.py b/users/admin.py
index 67216b9..5108f47 100644
--- a/users/admin.py
+++ b/users/admin.py
@@ -5,6 +5,7 @@ from standards.models import StandardCommentRate, StandardComments
from django.contrib.auth.models import Permission
from message.models import Message
from cloud.models import DataFile
+from organizer.models import AGContacts
admin.site.register(StandardComments)
@@ -17,6 +18,7 @@ admin.site.register(AgencyJob)
admin.site.register(Prio)
admin.site.register(Message)
admin.site.register(AgencyNetwork)
+admin.site.register(AGContacts)
admin.site.register(AgencyNetworkPreperation)
admin.site.register(DataFile)