digitaleagenturnc/orga/views.py

93 lines
2.5 KiB
Python

from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from areas.models import Areas
from users.priomodel import Prio
from tasks.models import Tasks
from users.models import AgencyJob
import webcolors
@login_required
def mainorga(request):
agencyuser = list(User.objects.filter(profile__agency__pk=request.user.profile.agency.pk).filter(profile__visible=True).order_by('-id'))
nonvisibleuser = list(User.objects.filter(profile__agency__pk=request.user.profile.agency.pk).filter(profile__visible=False).order_by('-id'))
invisible_users = 0;
# Check, if parented users are invisible. Remove them and give user an info!
for ele in nonvisibleuser:
for vis in agencyuser:
try:
if vis.profile.parent.profile.pk == ele.pk:
agencyuser.remove(vis)
invisible_users += 1
except:
pass
agjobs = AgencyJob.objects.filter(agency=request.user.profile.agency)
context = {
'active_link' : 'orga',
'agencyuser' : agencyuser,
'invisible_users' : invisible_users
}
return render(request, 'orga/orga_main.html', context)
@login_required
def singleorga(request, pk):
user = User.objects.get(pk=pk, profile__agency=request.user.profile.agency)
'''
VON GROß NACH KLEIN - SINNLOS
prios = Prio.objects.filter(user__pk=pk).order_by('-prio')[::-1]
'''
'''
Wenn eingelogger Nutzer nicht die gleiche Agency-ID hat,
gehts zum Dashboard
'''
if(user.profile.agency.pk==request.user.profile.agency.pk):
prios = Prio.objects.filter(user__pk=pk).order_by('prio')
areas = list(Areas.objects.filter(agency__pk=request.user.profile.agency.pk).order_by('areaorder'))
i = 0
for area in areas:
areas[i].hex = areas[i].color
areas[i].color = list(webcolors.hex_to_rgb(areas[i].color))
i += 1
user_first_name = user.first_name
user_last_name = user.last_name
user_id = user.pk
try:
userfuncname = AgencyJob.objects.get(pk=user.profile.func.pk).name
except:
userfuncname = "Nicht vergeben"
context = {
'active_link' : 'orga',
'areas' : areas,
'user_first_name' : user_first_name,
'user_last_name' : user_last_name,
'user_id' : user_id,
'prios' : prios,
'mail' : user.email,
'userfunc' : userfuncname,
'imageurl' : user.profile.get_photo_url,
'compfunc' : user.profile.compfunc,
'phoneland' : user.profile.phoneland,
'phonemobile' : user.profile.phonemobile
}
return render(request, 'orga/orga_single.html', context)
else:
return redirect('users-dashboard')