Ejemplo n.º 1
0
def dodajStran(request):
    if request.method == 'POST':
        form = DodajStranForm(request.POST)
        if form.is_valid():
            nova_stran = form.save(commit='False')
            nova_stran.avtor = UporabnikProfil.objects.get(uporabnik=request.user)
            nova_stran.datum_nastanka = timezone.now()
            nova_stran.save()
            return redirect('myapp:stran', stran_id=nova_stran.id)
    else:
        form = DodajStranForm()
        return render(request, 'myapp/dodaj.html', {
            'form': form,
            'strani_seznam': Stran.objects.all(),
            'is_supervisor': request.user.groups.filter(name='Nadzorniki').exists(),
            'is_prosilec': request.user.groups.filter(name='Prosilci').exists()
        })
Ejemplo n.º 2
0
def uredi(request, stran_id):
    post = get_object_or_404(Stran, id=stran_id)
    if request.method == "POST":
        form = DodajStranForm(request.POST, instance=post)
        if form.is_valid():
            post = form.save(commit='False')
            post.avtor = post.avtor
            post.datum_nastanka = timezone.now()
            post.save(force_update=True)
            return redirect('myapp:stran', stran_id=post.id)
    else:
        form = DodajStranForm(instance=post)
    return render(request, 'myapp/uredi.html', {
        'form': form,
        'id': post.id,
        'strani_seznam': Stran.objects.all(),
        'is_supervisor': request.user.groups.filter(name='Nadzorniki').exists(),
        'is_prosilec': request.user.groups.filter(name='Prosilci').exists()
    })