Exemple #1
0
def rozklad(request):
    if request.method == "POST":
        new_den = request.POST['add_den']
        if str(new_den) != 'виберіть день':
            nom_den = switch_case(new_den)
            Rozklad.objects.create(
                num = nom_den,
                name = new_den
            )
        else:
            ct= Rozklad.objects.all()
            ctt = []
            max_id = 1
            for el in ct:
                if el.id > max_id:
                    max_id = el.id
            for i, el in enumerate(range(max_id)):
                rez = request.POST.get('mitka'+str(i+1))
                if rez == 'on':
                    ctt.append(i+1)
                else:
                    ctt.append(0)
            for i in ctt:
                Rozklad.objects.filter(id=i).delete()
            pass

    ctx = {
        'dni' : Rozklad.objects.all()
    }
    return render(request, 'rozklad.html', ctx)
Exemple #2
0
def job(request):
    if request.method == "POST":
        new_den = request.POST['add_den']
        if str(new_den) != 'виберіть день':
            nom_den = switch_case(new_den)
            new_date = request.POST['add_date']
            DataJ.objects.create(
                dat=datetime.datetime.strptime(new_date, '%d-%m-%Y'),
                num = nom_den,
                name = new_den
            )
        else:
            ct= DataJ.objects.all()
            ctt = []
            max_id = 1
            for el in ct:
                if el.id > max_id:
                    max_id = el.id
            for i, el in enumerate(range(max_id)):
                rez = request.POST.get('mitka'+str(i+1))
                if rez == 'on':
                    ctt.append(i+1)
                else:
                    ctt.append(0)
            for i in ctt:
                DataJ.objects.filter(id=i).delete()
            pass

    ctx = {
        'dat' : DataJ.objects.all()
    }
    return render(request, 'job.html', ctx)