Blame view

src/core/pyros_django/scientific_program/views.py 2.35 KB
d73ed066   ALEXIS-PC\alexis   adding scientific...
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
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()
b40f05f1   Alexis Koralewski   Improving scienti...
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    return HttpResponseRedirect(reverse('proposal'))


@login_required
@level_required(2)
def scientific_program_list(request):
    if (len(ScientificProgram.objects.all()) > 0):                              # checking if the observatory table is empty
        proposal_info = ScientificProgram.objects.order_by("-id")[:100]         # Sorting Weather table
        nb_info_proposal = len(proposal_info)                                   # Get the number of data available

    else:                                                                       # if empty set everything to 0 / None (variables are checked in src/templates/scheduler/_current_weather.html)
        proposal_info = None
        nb_info_proposal = 0

    return render(request, 'dashboard/proposal.html', {'proposal_info' : proposal_info, 'nb_info_proposal' : nb_info_proposal})