606 lines
24 KiB
Python
606 lines
24 KiB
Python
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, StandardComments, StandardCommentRate
|
|
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 areas.models import Areas
|
|
from datetime import datetime
|
|
from users.models import AgencyGroup, AgencyNetwork
|
|
from cloud.models import DataFile, DataDir
|
|
from django.contrib.auth.decorators import login_required
|
|
import re
|
|
from django.template import defaultfilters
|
|
|
|
# ALLE STANDARDS EINER AGENTUR
|
|
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
|
|
areas = Areas.objects.filter(agency__pk=self.request.user.profile.agency.pk).order_by("areaorder")
|
|
standards_of_user = Standards.objects.filter(agency__pk=self.request.user.profile.agency.pk, created_standard_by=self.request.user.pk)
|
|
#standards_of_agency = Standards.objects.filter(agency__pk=self.request.user.profile.agency.pk, public=True)
|
|
unpubstandards_of_user = Standards.objects.filter(agency__pk=self.request.user.profile.agency.pk, public=False)
|
|
#tasks = Tasks.objects.filter(agency__pk=self.request.user.profile.agency.pk)
|
|
|
|
standardcontent = []
|
|
|
|
for a in areas:
|
|
standardcontent.append({"area" : a, "tasks" : []})
|
|
tasks_in_area = Tasks.objects.filter(agency__pk=self.request.user.profile.agency.pk, area__pk=a.pk).order_by("name")
|
|
|
|
for t in tasks_in_area:
|
|
standardcontent[len(standardcontent)-1]['tasks'].append({"task" : t, "standards" : Standards.objects.filter(agency__pk=self.request.user.profile.agency.pk, area__pk=a.pk, task = t.pk, area = a.pk, public=True).order_by("-created_standard_date")})
|
|
|
|
#context.update({'active_link' : 'standards', 'tasks': tasks, 'unpubstandards_of_user' : unpubstandards_of_user, 'standards_of_agency' : standards_of_agency, 'areas' : areas, 'standards_of_user' : standards_of_user, 'standardcontent' : standardcontent})
|
|
|
|
#agencynetworks = AgencyNetwork.objects.filter(creator_agency=self.request.user.profile.agency) | AgencyNetwork.objects.filter(adminagencys__in=[self.request.user.profile.agency.pk]) | AgencyNetwork.objects.filter(members__in=[self.request.user.profile.agency.pk]) | AgencyNetwork.objects.filter(sharemembers__in=[self.request.user.profile.agency.pk])
|
|
|
|
#agencynetworks = AgencyNetwork.objects.filter(adminagencys__in=[self.request.user.profile.agency.pk]) | AgencyNetwork.objects.filter(members__in=[self.request.user.profile.agency.pk]) | AgencyNetwork.objects.filter(sharemembers__in=[self.request.user.profile.agency.pk])
|
|
|
|
agencynetworks_all = AgencyNetwork.objects.all()
|
|
agencynetworks = []
|
|
|
|
for a in agencynetworks_all:
|
|
if self.request.user.profile.agency in a.adminagencys.all() or self.request.user.profile.agency in a.members.all() or self.request.user.profile.agency in a.sharemembers.all():
|
|
agencynetworks.append(a)
|
|
|
|
allagencynetworkstandards = []
|
|
for agn in agencynetworks:
|
|
for agn_s in agn.standards.all():
|
|
allagencynetworkstandards.append(agn_s)
|
|
|
|
|
|
allagencynetworkstandards.sort(key=lambda x: x.agencynetworkcounter, reverse=True)
|
|
|
|
# Beliebte Standards
|
|
famestandards = []
|
|
famecounter = 0
|
|
for s in allagencynetworkstandards:
|
|
if famecounter < 10 and s not in famestandards:
|
|
famestandards.append(s)
|
|
famecounter += 1
|
|
|
|
context.update({'active_link' : 'standards', 'unpubstandards_of_user' : unpubstandards_of_user, 'areas' : areas, 'standards_of_user' : standards_of_user, 'standardcontent' : standardcontent, "agencynetworks" : agencynetworks, "allagencynetworkstandards" : allagencynetworkstandards, 'famestandards' : famestandards})
|
|
|
|
return context
|
|
|
|
|
|
@login_required
|
|
def checkUserDirRights(request, startdir, userid):
|
|
canview = True
|
|
user = User.objects.get(pk=userid)
|
|
usergroups=list(user.groups.all())
|
|
grouptomach = []
|
|
singleObj = DataDir.objects.get(pk=startdir.pk)
|
|
# AGENCYCHECK
|
|
if(singleObj.agency.pk == user.profile.agency.pk):
|
|
|
|
# Get dirs to check
|
|
while( singleObj.is_root != True and canview == True):
|
|
|
|
for g in singleObj.visibleby.all():
|
|
grouptomach.append(g.group)
|
|
|
|
if(len(grouptomach) == 0):
|
|
canview = True
|
|
else:
|
|
if(len(set(usergroups).intersection(grouptomach)) > 0):
|
|
canview = True
|
|
else:
|
|
canview = False
|
|
|
|
grouptomach = []
|
|
singleObj = DataDir.objects.get(pk=singleObj.parent.pk)
|
|
|
|
else:
|
|
canview = False
|
|
return canview
|
|
|
|
|
|
|
|
|
|
|
|
@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']
|
|
|
|
new_standard.freefield_content = normalForm.cleaned_data['freefield_content']
|
|
new_standard.freefield_title = normalForm.cleaned_data['freefield_title']
|
|
|
|
# GROUPS
|
|
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))
|
|
|
|
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)
|
|
}
|
|
return render(request, 'standards/standards_add.html', context)
|
|
|
|
|
|
@login_required
|
|
def StandardUpdate(request, id):
|
|
standard = Standards.objects.get(pk=id, agency=request.user.profile.agency)
|
|
if request.method == 'POST':
|
|
#normalForm = StandardUpdateStandard(request.POST, instance=standard)
|
|
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.freefield_content = normalForm.cleaned_data['freefield_content']
|
|
existing_standard.freefield_title = normalForm.cleaned_data['freefield_title']
|
|
|
|
#existing_standard.representative.set(normalForm.cleaned_data['representative'])
|
|
#existing_standard.executor.set(normalForm.cleaned_data['executor'])
|
|
#existing_standard.authority.set(normalForm.cleaned_data['authority'])
|
|
|
|
'''
|
|
|
|
AKTUALISIERUNG
|
|
|
|
Wennn der User selbst den Standard erstellt hat und Rechte zur Standardverwaltung hat,
|
|
dann wird der Status nicht verändert (public bleibt true bzw. false). Hat der User
|
|
aber keine Rechte und ist der Standarf public, wird er auf public=false gesetzt!
|
|
|
|
'''
|
|
if request.user.has_perm('users.standardmanager'):
|
|
messages.success(request, f'Standard {existing_standard.name} aktualisiert!')
|
|
else:
|
|
if existing_standard.public:
|
|
existing_standard.public = False
|
|
messages.warning(request, f'Standard {existing_standard.name} aktualisiert und ist nicht mehr öffentlich, damit Änderungen geprüft werden können.')
|
|
else:
|
|
messages.success(request, f'Standard {existing_standard.name} aktualisiert!')
|
|
existing_standard.save()
|
|
return redirect('/standards')
|
|
|
|
else:
|
|
normalForm = StandardUpdateStandard(instance=standard)
|
|
editorForm = StandardUpdateStandardEditor(instance=standard)
|
|
|
|
'''
|
|
Hier werden nur die Dateien dem aktuellen User zur Auswahl gestellt, auf die er auch Zugriff hat.
|
|
Das geht NICHT rekursiv! Es wird nur das oberste Verzeichnis geprüft! SPÄTER!
|
|
'''
|
|
|
|
possibleFilesByVisible = []
|
|
|
|
allfiles = DataFile.objects.filter(agency=request.user.profile.agency)
|
|
|
|
for f in allfiles:
|
|
actParent = DataDir.objects.get(pk=f.parent.pk, agency=request.user.profile.agency)
|
|
if actParent.is_root:
|
|
possibleFilesByVisible.append(f)
|
|
else:
|
|
if(checkUserDirRights(request, actParent, request.user.pk) and f not in standard.addedfiles.all()):
|
|
possibleFilesByVisible.append(f)
|
|
|
|
|
|
possiblestandards = Standards.objects.filter(agency=request.user.profile.agency, public=True)
|
|
possiblestandards_final = []
|
|
for s in possiblestandards:
|
|
if s not in standard.linked_standards.all():
|
|
possiblestandards_final.append(s)
|
|
|
|
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)
|
|
|
|
agencynetworks = AgencyNetwork.objects.filter(creator_agency=request.user.profile.agency) | AgencyNetwork.objects.filter(adminagencys__in=[request.user.profile.agency.pk]) | AgencyNetwork.objects.filter(members__in=[request.user.profile.agency.pk]) | AgencyNetwork.objects.filter(sharemembers__in=[request.user.profile.agency.pk])
|
|
|
|
|
|
|
|
context = {
|
|
'normalForm' : normalForm,
|
|
'editorForm' : editorForm,
|
|
'standard' : standard,
|
|
'active_link' : 'standards',
|
|
'standard_id' : standard.pk,
|
|
'standard_status' : standard.public,
|
|
'possibleFilesByVisible' : possibleFilesByVisible,
|
|
'agencygroups' : AgencyGroup.objects.filter(agency=request.user.profile.agency),
|
|
'parentid' : list(DataDir.objects.filter(agency=request.user.profile.agency, is_root=True))[0].pk,
|
|
'poss_verant' : possible_verant_final,
|
|
'poss_ex' : possible_ex_final,
|
|
'poss_ver' : possible_ver_final,
|
|
'possiblestandards' : possiblestandards_final,
|
|
"agencynetworks" : agencynetworks
|
|
}
|
|
return render(request, 'standards/standards_update.html', context)
|
|
|
|
@login_required
|
|
def load_tasks(request):
|
|
areaid = request.GET.get('areaid')
|
|
tasks = Tasks.objects.filter(area__id=areaid, agency=request.user.profile.agency).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 delete(self, request, *args, **kwargs):
|
|
standard = Standards.objects.get(pk=kwargs['pk'], agency=request.user.profile.agency)
|
|
response = super(StandardDeleteView, self).delete(request, *args, **kwargs)
|
|
names = standard.name
|
|
messages.success(request, f'Standard ' +names+ ' wurde gelöscht!')
|
|
return response
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(StandardDeleteView, self).get_context_data(**kwargs)
|
|
context['active_link'] = 'standards'
|
|
return context
|
|
|
|
@login_required
|
|
def StandardChangePublic(request, pk):
|
|
standard = Standards.objects.get(pk=pk)
|
|
if standard.public:
|
|
standard.public = False
|
|
messages.warning(request, f'Standard {standard.name} ist nicht mehr öffentlich!')
|
|
else:
|
|
standard.public = True
|
|
messages.success(request, f'Standard {standard.name} wurde veröffentlicht und ist innerhalb der Agentur sichtbar!')
|
|
standard.save()
|
|
return redirect('standards')
|
|
|
|
@login_required
|
|
def StandardSingle(request, pk):
|
|
|
|
# CHECK IF USER HAS RIGHTS TO SEE THIS DIR
|
|
groupsofstandard = Standards.objects.get(pk=pk, agency=request.user.profile.agency)
|
|
|
|
userisingroup = False
|
|
|
|
if len(groupsofstandard.visibleby.all()) == 0:
|
|
userisingroup = True
|
|
else:
|
|
for ag in groupsofstandard.visibleby.all():
|
|
if ag.group in request.user.groups.all():
|
|
userisingroup = True
|
|
|
|
if userisingroup:
|
|
standard = Standards.objects.get(pk=pk)
|
|
context = {
|
|
'active_link':'standards',
|
|
'standard' : standard
|
|
}
|
|
return render(request, 'standards/standards_single.html', context)
|
|
else:
|
|
context = {
|
|
'active_link':'standards'
|
|
}
|
|
return render(request, 'standards/standards_noentrie.html', context)
|
|
|
|
|
|
|
|
@login_required
|
|
def CopyStandard(request, pk):
|
|
#SANDARD COPY
|
|
sc = Standards.objects.get(pk=pk)
|
|
sc.agencynetworkcounter = sc.agencynetworkcounter+1
|
|
sc.save()
|
|
|
|
area = list(Areas.objects.filter(agency=request.user.profile.agency))[0]
|
|
task = list(Tasks.objects.filter(agency=request.user.profile.agency))[0]
|
|
|
|
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 = None
|
|
new_standard.area = None
|
|
new_standard.name = sc.name
|
|
new_standard.content = sc.content
|
|
new_standard.public = False
|
|
|
|
new_standard.freefield_content = sc.freefield_content
|
|
new_standard.freefield_title = sc.freefield_title
|
|
|
|
new_standard.parent_standard = sc
|
|
new_standard.shared_on = datetime.now()
|
|
|
|
new_standard.save()
|
|
|
|
datadir_parentid = list(DataDir.objects.filter(is_defaultstandard=True, agency__pk=request.user.profile.agency.pk))[0]
|
|
|
|
for f in sc.addedfiles.all():
|
|
tempdatafile = DataFile(file=f.file, name=f.name, owner=request.user, parent=datadir_parentid, agency=request.user.profile.agency)
|
|
tempdatafile.save()
|
|
new_standard.addedfiles.add(tempdatafile)
|
|
|
|
return redirect('standard-update', new_standard.pk)
|
|
|
|
@login_required
|
|
def StandardArea(request, pk):
|
|
standards = Standards.objects.filter(agency__pk=request.user.profile.agency.pk).filter(area__pk=pk)
|
|
area = Areas.objects.get(pk=pk, agency=request.user.profile.agency)
|
|
context = {
|
|
'active_link':'standards',
|
|
'standards_of_agency_area' : standards,
|
|
'areaid' : pk,
|
|
'areaname' : area.name
|
|
}
|
|
return render(request, 'standards/standard_area.html', context)
|
|
|
|
@login_required
|
|
def StandardTask(request, pk):
|
|
standards = Standards.objects.filter(agency__pk=request.user.profile.agency.pk).filter(task__pk=pk)
|
|
task = Tasks.objects.get(pk=pk, agency=request.user.profile.agency)
|
|
area = Areas.objects.get(pk=task.area.pk, agency=request.user.profile.agency)
|
|
context = {
|
|
'active_link':'standards',
|
|
'standards_of_agency_task' : standards,
|
|
'taskid' : pk,
|
|
'taskname' : task.name,
|
|
'areaid' : area.pk,
|
|
'areaname' : area.name
|
|
}
|
|
return render(request, 'standards/standard_task.html', context)
|
|
|
|
# AJAX Standard
|
|
@login_required
|
|
def updatesbyajax(request, pk):
|
|
if(request.method == "GET"):
|
|
success = True
|
|
workingstandard = Standards.objects.get(pk=pk, agency=request.user.profile.agency)
|
|
# Check for correct user and userrights
|
|
if(request.user.profile.agency == workingstandard.agency and request.user.has_perm("users.standardmanager")):
|
|
# CHANGE GROUP
|
|
# ADD
|
|
if(request.GET["action"] == "s_addgroup"):
|
|
workingstandard.visibleby.add(AgencyGroup.objects.get(pk=request.GET["groupid"], agency=request.user.profile.agency))
|
|
# REMOVE
|
|
elif(request.GET["action"] == "s_remgroup"):
|
|
workingstandard.visibleby.remove(AgencyGroup.objects.get(pk=request.GET["groupid"], agency=request.user.profile.agency))
|
|
# FILES
|
|
# REMOVE
|
|
elif(request.GET["action"] == "s_remfile"):
|
|
workingstandard.addedfiles.remove(DataFile.objects.get(pk=request.GET["fileid"], agency=request.user.profile.agency))
|
|
# ADD
|
|
elif(request.GET["action"] == "s_addfile"):
|
|
workingstandard.addedfiles.add(DataFile.objects.get(pk=request.GET["fileid"], agency=request.user.profile.agency))
|
|
# STANDARD
|
|
# REMOVE
|
|
elif(request.GET["action"] == "s_remstandard"):
|
|
workingstandard.linked_standards.remove(Standards.objects.get(pk=request.GET["standardid"], agency=request.user.profile.agency))
|
|
# ADD
|
|
elif(request.GET["action"] == "s_addstandard"):
|
|
workingstandard.linked_standards.add(Standards.objects.get(pk=request.GET["standardid"], agency=request.user.profile.agency))
|
|
# VERANTWORTLICHER / AUTHORITY
|
|
# REMOVE
|
|
elif(request.GET["action"] == "s_remverant"):
|
|
workingstandard.authority.remove(User.objects.get(pk=request.GET["userid"], profile__agency=request.user.profile.agency))
|
|
elif(request.GET["action"] == "s_addverant"):
|
|
workingstandard.authority.add(User.objects.get(pk=request.GET["userid"], profile__agency=request.user.profile.agency))
|
|
# ASUFÜRHENDER / EXECUTOR
|
|
# REMOVE
|
|
elif(request.GET["action"] == "s_remex"):
|
|
workingstandard.executor.remove(User.objects.get(pk=request.GET["userid"], profile__agency=request.user.profile.agency))
|
|
elif(request.GET["action"] == "s_addex"):
|
|
workingstandard.executor.add(User.objects.get(pk=request.GET["userid"], profile__agency=request.user.profile.agency))
|
|
# VERTRETER / REPRESENETATIVE
|
|
# REMOVE
|
|
elif(request.GET["action"] == "s_remver"):
|
|
workingstandard.representative.remove(User.objects.get(pk=request.GET["userid"], profile__agency=request.user.profile.agency))
|
|
elif(request.GET["action"] == "s_addver"):
|
|
workingstandard.representative.add(User.objects.get(pk=request.GET["userid"], profile__agency=request.user.profile.agency))
|
|
# ADD STANDARD TO AGENCYNETWORK
|
|
elif(request.GET["action"] == "s_addtonetwork"):
|
|
if workingstandard.public and request.user.profile.agency == workingstandard.agency:
|
|
agn = AgencyNetwork.objects.get(pk=request.GET["agn_id"])
|
|
if(request.GET["newstat"] == "true"):
|
|
agn.standards.add(workingstandard)
|
|
else:
|
|
agn.standards.remove(workingstandard)
|
|
agn.lastactivity = datetime.now()
|
|
agn.save()
|
|
else:
|
|
success = False
|
|
|
|
return JsonResponse({"success" : success})
|
|
|
|
|
|
@login_required
|
|
def StandardFromAgn(request, pk):
|
|
try:
|
|
agn = AgencyNetwork.objects.get(pk=pk)
|
|
context = {
|
|
'active_link':'standards',
|
|
'standards_of_agency_network' : agn.standards.all(),
|
|
'agn' :agn,
|
|
}
|
|
return render(request, 'standards/standards_from_agn.html', context)
|
|
except:
|
|
context = {
|
|
'active_link':'standards',
|
|
}
|
|
return redirect('standards')
|
|
|
|
|
|
# View for SingleStandard from AgencyNetwork
|
|
@login_required
|
|
def StandardSingleAgn(request, pk, agnpk):
|
|
context = {
|
|
'active_link':'standards',
|
|
'agnpk' : agnpk,
|
|
'standard' : Standards.objects.get(pk=pk),
|
|
'comments' : StandardComments.objects.filter(standard=Standards.objects.get(pk=pk)).order_by("-last_modified_on")
|
|
}
|
|
return render(request, 'standards/standards_single_agn.html', context)
|
|
|
|
@login_required
|
|
def updatesbyajax_agn(request, pk):
|
|
if(request.method == "GET"):
|
|
|
|
if(request.GET["action"] == "add_comment"):
|
|
content = re.sub('[^A-Za-z0-9,!?_ äüöÄÜÖ]+', '', request.GET.get("content"))
|
|
sc = StandardComments(standard=Standards.objects.get(pk=pk), content=content, comment_by=request.user, comment_on=datetime.now(), last_modified_on=datetime.now())
|
|
sc.save()
|
|
|
|
return JsonResponse({"success" : "success", "sc_id" : sc.pk, "sc_c" : sc.content, "sc_user" : sc.comment_by.first_name + " " + sc.comment_by.last_name, "sc_date" : defaultfilters.date(sc.last_modified_on, "SHORT_DATETIME_FORMAT") })
|
|
elif(request.GET["action"] == "del_comment"):
|
|
StandardComments.objects.get(pk=request.GET.get("id")).delete()
|
|
return JsonResponse({})
|
|
elif(request.GET["action"] == "update_comment_rate"):
|
|
|
|
user = request.user
|
|
comment = StandardComments.objects.get(pk=request.GET.get("id"))
|
|
|
|
rate = list(StandardCommentRate.objects.filter(oncomment=comment, rated_by=request.user))
|
|
|
|
if len(rate) == 0:
|
|
new_s_c_rate = StandardCommentRate(oncomment=comment, rated_by=request.user, rate_stats=request.GET.get("newstat"))
|
|
new_s_c_rate.save()
|
|
else:
|
|
s_c_rate = StandardCommentRate.objects.get(pk=rate[0].pk)
|
|
s_c_rate.rate_stats=request.GET.get("newstat")
|
|
s_c_rate.save()
|
|
|
|
counter_up = len(StandardCommentRate.objects.filter(oncomment=comment, rate_stats=1))
|
|
counter_down = len(StandardCommentRate.objects.filter(oncomment=comment, rate_stats=0))
|
|
|
|
return JsonResponse({"up" : counter_up, "down" : counter_down})
|
|
elif(request.GET["action"] == "markingfavorit"):
|
|
workingstandard = Standards.objects.get(pk=pk)
|
|
added = False
|
|
if workingstandard.public:
|
|
if(request.user in workingstandard.favoritfrom.all()):
|
|
workingstandard.favoritfrom.remove(request.user)
|
|
else:
|
|
workingstandard.favoritfrom.add(request.user)
|
|
added = True
|
|
return JsonResponse({"added" : added})
|
|
|
|
|
|
|