views.py
1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from django.shortcuts import render,redirect,get_object_or_404,reverse
from django.contrib.auth import authenticate
from django.contrib.auth.decorators import login_required
from .forms import ScientificProgramForm
from src.core.pyros_django.dashboard.decorator import level_required
from common.models import ScientificProgram
from django.http import HttpResponseRedirect
@level_required(6)
@login_required
def create_sp(request):
form = ScientificProgramForm(request.POST)
if request.POST:
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse("proposal"))
form = ScientificProgramForm()
return render(request,"scientific_program/create_scientific_program.html",{"form": form})
@level_required(6)
@login_required
def edit_sp(request,id):
edit = get_object_or_404(ScientificProgram, pk=id)
form = ScientificProgramForm(request.POST or None, instance=edit)
if form.is_valid():
form.save()
return redirect('detail_scientific_program', id=id)
return render(request, 'scientific_program/scientific_program_detail_edit.html', {'id' : id, 'form': form})
@login_required
def detail_sp(request,id):
scientific_program = get_object_or_404(ScientificProgram, pk=id)
return render(request, 'scientific_program/scientific_program_detail.html', {'scientific_program': scientific_program})
@level_required(6)
@login_required()
def delete_sp(request,id):
scientific_program = get_object_or_404(ScientificProgram, pk=int(id))
scientific_program.delete()
return HttpResponseRedirect(reverse('proposal'))