diff --git a/src/nalodeni/models.py b/src/nalodeni/models.py index 55ed4ed..2854a8e 100644 --- a/src/nalodeni/models.py +++ b/src/nalodeni/models.py @@ -339,6 +339,7 @@ class UserSkill(Model): ordering = ['tag',] unique_together = ( ('tag',),) + class UserTopic(Model): """ Zájmová témata daného uživatele. @@ -356,8 +357,6 @@ class UserTopic(Model): unique_together = ( ('tag',),) - - class UserForm(Model, DataAudited): """ Dotaznik ohledne dovednosti a schopnosti uzivatele. @@ -372,7 +371,7 @@ class UserForm(Model, DataAudited): class AppRegEmail(Model): """ - Pozadavky na registraci emailu. + Pozadavky na registraci emailu - sem jdou novi lide, kteri vyplni formular 'jdu do toho' """ createdStamp = DateTimeField(_('Uživatel vytvořen'), default=datetime.datetime.now, blank=False, null=False, editable=False) diff --git a/src/nalodeni/people.py b/src/nalodeni/people.py index eb918b0..ecc3ec0 100644 --- a/src/nalodeni/people.py +++ b/src/nalodeni/people.py @@ -34,6 +34,7 @@ from . import auth as nalodeni_auth # Logger instance logger = logging.getLogger(__name__) + def role_required(roles=[]): def decorate(func): def call(request, *args, **kwargs): @@ -46,6 +47,7 @@ def role_required(roles=[]): return call return decorate + def get_AppUser_objects(request): ''' Zkontroluje, že všechny objekty v 'objs' vyhovují přiděleným rolím. Nevyhovující vyřadí. @@ -57,14 +59,12 @@ def get_AppUser_objects(request): if 'sso_admin' in sp: return models.AppUser.objects.all() - objs = models.AppUser.objects.filter(district__in=request.session['spc']['dist']) + return models.AppUser.objects.filter(district__in=request.session['spc']['dist']) - return objs def get_AppUser_districts(request): '''Vrátí dostupné kraje podle rolí.''' - if 'sso_admin' in request.session['site_perms']: return list(models.AppUser.DISTRICT_CHOICES) @@ -132,22 +132,21 @@ def eu2019(request, dist=None): return response - - template = 'people/eu2019.html' context = { 'people' : objs, 'distAvail' : districts, 'selDist' : selDist, } + return render(request, 'people/eu2019.html', context) - return render(request, template, context) @ensure_csrf_cookie @login_required(login_url="/prihlaseni") @role_required(['sso_kodo']) def confirmed(request, newOnly=False, dist=None): - if dist is None: - dist = int(request.POST.get('dist', -1)) + """ Seznam nalodenych pasazeru """ + + dist = dist or int(request.POST.get('dist', -1)) doCsvExport = None != request.POST.get('doCsvExport', None) objs = get_AppUser_objects(request).order_by('last_name', 'first_name' ,'email') @@ -226,16 +225,13 @@ def confirmed(request, newOnly=False, dist=None): return response - - template = 'people/list.html' context = { 'people' : objs, 'newOnly' : newOnly, 'distAvail' : districts, 'selDist' : selDist, } - - return render(request, template, context) + return render(request, 'people/list.html', context) @ensure_csrf_cookie @@ -285,14 +281,12 @@ def pending(request): objs = objs.filter(emailToken = None) objs = objs.order_by('etStamp') - template = 'people/pending.html' context = { 'people' : objs, 'tokenValidAfter' : tokenValidAfter, 'show_all' : show_all, } - - return render(request, template, context) + return render(request, 'people/pending.html', context) @@ -320,7 +314,6 @@ def update(request): return HttpResponseRedirect('/people/list-new/') else: messages.error(request, 'Špatný požadavek.') - return HttpResponseRedirect('/people/list/') @@ -340,12 +333,11 @@ def person_detail(request, id): messages.error(request, 'K tomuto záznamu nemáte přístup. ') return redirect('nalodeni:people_list') - template = 'person/detail.html' context = { 'obj' : obj, } + return render(request, 'person/detail.html', context) - return render(request, template, context) @login_required(login_url="/prihlaseni") @transaction.atomic @@ -389,13 +381,10 @@ def person_edit(request, id): else: form = None - template = 'person/edit.html' context = { 'obj' : obj, 'form' : form, 'AUTH_SERVER' : appSettings.AUTH_SERVER, } - - return render(request, template, context) - + return render(request, 'person/edit.html', context) diff --git a/src/nalodeni/stats.py b/src/nalodeni/stats.py index 2c40b95..ea8afc4 100644 --- a/src/nalodeni/stats.py +++ b/src/nalodeni/stats.py @@ -38,6 +38,7 @@ from . import auth as nalodeni_auth # Logger instance logger = logging.getLogger(__name__) + def role_required(roles=[]): def decorate(func): def call(request, *args, **kwargs): @@ -50,6 +51,7 @@ def role_required(roles=[]): return call return decorate + def get_AppUser_objects(request): ''' Zkontroluje, že všechny objekty v 'objs' vyhovují přiděleným rolím. Nevyhovující vyřadí. @@ -65,10 +67,10 @@ def get_AppUser_objects(request): return objs + def get_AppUser_districts(request): '''Vrátí dostupné kraje podle rolí.''' - if 'sso_admin' in request.session['site_perms']: return list(models.AppUser.DISTRICT_CHOICES) @@ -100,16 +102,16 @@ def reg_counts(request, dist=None): objs = objs.annotate( month=TruncMonth('createdStamp')).values('month', 'district').annotate(c=Count('id')).order_by('district','month') for o in objs: - o['district'] = models.AppUser.DISTRICT_CHOICES_STR[o['district']] if o['district'] is not None else "---" - #print( "%s \t %s \t %s" % (o['district'], o['month'].strftime('%Y-%m'),o['c'])) + try: + o['district'] = models.AppUser.DISTRICT_CHOICES_STR[o['district']] if o['district'] is not None else "---" + except KeyError: + o['district'] ="---" - template = 'stats/reg_counts.html' context = { 'objs' : objs, 'distAvail' : districts, 'selDist' : selDist, } - return render(request, template, context) - + return render(request, 'stats/reg_counts.html', context) diff --git a/src/nalodeni/templates/people/list.html b/src/nalodeni/templates/people/list.html index 312dc1a..6d9dc25 100644 --- a/src/nalodeni/templates/people/list.html +++ b/src/nalodeni/templates/people/list.html @@ -46,6 +46,7 @@ $(document).ready(function(){