Beispiel #1
0
 def wrapper(*args, **kwargs):
     request = __find_request(*args)
     if not request.user.is_authenticated:
         return view(*args, **kwargs)
     if not request.user.gr_key:
         return iredirect('accounts:graphic_key', get={'status': 'new'})
     if 'graphic_key' in request.session:
         if type(request.session['graphic_key']) == str:
             return iredirect('accounts:graphic_key',
                              get={'status': 'confirm'})
         return view(*args, **kwargs)
     return iredirect('accounts:graphic_key')
Beispiel #2
0
def graphic_key(request):
    if not request.user.is_authenticated:
        return redirect(reverse('accounts:login'))
    status = request.GET.get('status')
    if request.method == 'POST':
        gr_key = request.POST.get('gr_key')
        if status == 'new':
            request.session['graphic_key'] = gr_key
            return iredirect('accounts:graphic_key', get={'status': 'confirm'})
        elif status == 'confirm':
            if request.session['graphic_key'] == gr_key:
                request.user.gr_key = gr_key
                request.session['graphic_key'] = True
                request.user.save()
            else:
                request.session.pop('graphic_key')
            return iredirect('main:index')
        elif request.user.gr_key == gr_key:
            request.session['graphic_key'] = True
            return iredirect('main:index')
        return iredirect('accounts:login')
    return render(request, 'Accounts/GraphicKey.html', {'status': status})
Beispiel #3
0
def download_shtatnoe_raspisanie(request):
    if request.user.is_superuser or request.user.is_zav_kafedra:
        fakultet_id = ''
        if request.GET.get('type', 'word') == 'word':
            path = word_shtat_rasp(request, fakultet_id=fakultet_id)
        elif request.GET.get('type', 'word') == 'excel':
            path = excel_shtat_rasp(request, fakultet_id=fakultet_id)
        else:
            path = excel_shtat_rasp(request,
                                    fakultet_id=fakultet_id,
                                    _all=True)
        return FileResponse(open(path, 'rb'))
    return iredirect('main:index')
Beispiel #4
0
def form(request, id, template, model, model_form, reverse_name, field_name):
    data = {
        'form': model_form(),
        'persons': Person.objects.all(),
        'source': request.GET.get('source'),
        'ispdns': Ispdn.objects.all(),
        'source_ispdn': Ispdn.objects.get_or_none(id=request.GET.get('source'))
    }
    if data['source']:
        data['source'] = int(data['source'])
    instance = None
    if id:
        instance = model.objects.get_or_404(id=id)
        data['instance_ispdns'] = list(
            instance.ispdns.values_list('id', flat=True).all())
        data['form'] = model_form(instance=instance)

    if request.method == 'POST':
        ispdns_ids = list(map(int, request.POST.getlist('ispdn', [])))
        form = model_form(request.POST, request.FILES, instance=instance)
        if form.is_valid():
            if instance:
                act_flag = CHANGE
            else:
                act_flag = ADDITION
            instance = form.save()
            for ispdn in data['ispdns']:
                if ispdn.id in ispdns_ids:
                    getattr(ispdn, field_name).add(instance)
                else:
                    getattr(ispdn, field_name).remove(instance)
                ispdn.save()
            add_log_entry(request.user, instance, act_flag)
            if data['source']:
                return iredirect(f'ispdn:{reverse_name}',
                                 ispdn_id=data['source'])
            return iredirect(f'ispdn:{reverse_name}_all')
    return render(request, template, data)
Beispiel #5
0
def prepods_list(request):
    if request.user.is_superuser:
        prepods = Prepod.objects.all()
    elif request.user.prepod.count() == 0:
        return iredirect('main:index')
    else:
        prepods = Prepod.objects.filter(
            kafedra=request.user.prepod.first().kafedra)
    prepods = prepods.annotate(
        num_nagruzki=Count('nagruzki', filter=Q(nagruzki__archive=None)))

    return render(request, 'Prepods/List.html', {
        'prepods': prepods,
        'dis_errors': check_discipline_errors(request)
    })
Beispiel #6
0
def registration(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                email=form.cleaned_data['email'],
                password=form.cleaned_data['fpassword'],
                last_name=form.cleaned_data['last_name'],
                first_name=form.cleaned_data['first_name'],
                surname=form.cleaned_data['surname'],
                dolzhnost=form.cleaned_data['dolzhnost'])
            auth.login(request, user)
            return iredirect('main:index')
        return render(request, 'Accounts/Registration.html', {'form': form})
    form = RegistrationForm()
    return render(request, 'Accounts/Registration.html', {'form': form})
Beispiel #7
0
def prepod_form(request, id=None):
    prepod = Prepod.objects.get_or_none(id=id)
    form = PrepodForm(instance=prepod)
    if request.method == 'POST':
        form = PrepodForm(request.POST, instance=prepod)
        if form.is_valid():
            prepod = form.save(commit=False)
            if not request.user.is_superuser:
                prepod.kafedra = request.user.prepod.first().kafedra
            prepod.save()
            return iredirect('prepods:list')
    return render(
        request, 'Prepods/Form.html', {
            'form': form,
            'kafedri': Kafedra.objects.all(),
            'users': User.objects.all()
        })
Beispiel #8
0
def zhurnal_form(request, id=None):
    data = {'skzi_names': SkziName.objects.all(),
            'fio_rassilki': FioRassilki.objects.all(),
            'organs_crypto': OrganCrypto.objects.all(),
            'form': SkziForm()}
    skzi = None
    if id:
        skzi = Skzi.objects.get_or_404(id=id)
        data['form'] = SkziForm(instance=skzi)
    if request.method == 'POST':
        form = SkziForm(request.POST, instance=skzi)
        if form.is_valid():
            if skzi:
                act_flag = CHANGE
            else:
                act_flag = ADDITION
            skzi = form.save()
            add_log_entry(request.user, skzi, act_flag)
            return iredirect('skzi:zhurnal')
        print(form.errors)
        data['form'] = form
    return render(request, 'Skzi/ZhurnalForm.html', data)
    def wrapper(*args, **kwargs):
        request = __find_request(*args)

        if not request.user.is_superuser and request.user.prepod.count() == 0:
            return iredirect('main:index')
        return view(*args, **kwargs)