Commit d73ed0664280d57b0cbe935ec93dc0bd1164d231

Authored by ALEXIS-PC\alexis
1 parent 6df730cd
Exists in dev

adding scientific program CRUD pages

src/core/pyros_django/dashboard/templates/dashboard/proposal.html
... ... @@ -29,6 +29,9 @@
29 29 <div class="row">
30 30 <h3>List of proposal Info - <span class="label label-primary">{{proposal_info|length}}</span></h3>
31 31 <div class="table-responsive">
  32 + {% if USER_LEVEL >= USER_LEVEL_PI %}
  33 + <a href="{% url "create_scientific_program" %}" class="btn btn-info" role="button">Create new scientific_program</a>
  34 + {% endif %}
32 35 <table
33 36 class="table table-bordered table-hover table-striped tablesorter" style="font-family: 'Montserra', sans-serif;">
34 37 <thead>
... ... @@ -43,8 +46,16 @@
43 46 <tbody>
44 47 {% for proposal_inf in proposal_info %}
45 48 <tr>
46   - <td>{{ proposal_inf.pyros_users }}</td>
47   - <td>{{ proposal_inf.name }}</td>
  49 + <td>
  50 + {% for user in proposal_inf.pyros_users.all|slice:":3" %}
  51 + {{ user.username }}
  52 + {% endfor %}
  53 + {% if proposal_inf.pyros_users.all.count > 3 %}
  54 + ...
  55 + {% endif %}
  56 + </td>
  57 +
  58 + <td><a href="{% url 'detail_scientific_program' proposal_inf.id %}">{{ proposal_inf.name }}</a></td>
48 59 <td>{{ proposal_inf.desc }}</td>
49 60 <td>{{ proposal_inf.quota }}</td>
50 61 <td>{{ proposal_inf.priority }}</td>
... ...
src/core/pyros_django/pyros/settings.py
... ... @@ -162,6 +162,7 @@ INSTALLED_APPS = [
162 162 'routine_manager',
163 163 'user_manager',
164 164 'devices',
  165 + 'scientific_program',
165 166 #'kombu.transport.django'
166 167 ]
167 168  
... ...
src/core/pyros_django/pyros/urls.py
... ... @@ -40,6 +40,7 @@ urlpatterns = [
40 40 url(r'^observation_manager/', include('observation_manager.urls')),
41 41 url(r'^routine_manager/', include('routine_manager.urls')),
42 42 url(r'^user_manager/', include('user_manager.urls')),
  43 + url(r'^scientific_program/', include('scientific_program.urls')),
43 44 url(r'^$', user_manager.views.home)
44 45 ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
45 46  
... ...
src/core/pyros_django/scientific_program/__init__.py 0 → 100644
src/core/pyros_django/scientific_program/admin.py 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +from django.contrib import admin
  2 +
  3 +# Register your models here.
... ...
src/core/pyros_django/scientific_program/apps.py 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +from django.apps import AppConfig
  2 +
  3 +
  4 +class ScientificProgramConfig(AppConfig):
  5 + name = 'scientific_program'
... ...
src/core/pyros_django/scientific_program/forms.py 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +from django import forms
  2 +from common.models import ScientificProgram,PyrosUser
  3 +
  4 +class ScientificProgramForm(forms.ModelForm):
  5 +
  6 + class Meta:
  7 + model = ScientificProgram
  8 + fields = (
  9 + "name",
  10 + "desc",
  11 + "quota",
  12 + "priority",
  13 + "pyros_users",
  14 + )
  15 +
  16 +
  17 + widgets = {
  18 +
  19 + "pyros_users": forms.CheckboxSelectMultiple()
  20 + }
  21 +
... ...
src/core/pyros_django/scientific_program/migrations/__init__.py 0 → 100644
src/core/pyros_django/scientific_program/models.py 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +from django.db import models
  2 +
  3 +# Create your models here.
... ...
src/core/pyros_django/scientific_program/templates/scientific_program/create_scientific_program.html 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +{% extends 'base.html' %}
  2 +
  3 +{% block content %}
  4 +
  5 +<form id="createSPForm" action="" method="post">
  6 + {% csrf_token %}
  7 + {{ form.as_p }}
  8 + <input id="submit" class="btn btn-info" type="submit" value="Submit" />
  9 + <a href="{% url "proposal" %}" class="btn btn-info" role="button">Cancel</a>
  10 +</form>
  11 +
  12 +{% endblock %}
0 13 \ No newline at end of file
... ...
src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail.html 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +{% extends 'base.html' %}
  2 +
  3 +{% block content %}
  4 + <a href="{% url "proposal" %}" class="btn btn-info" role="button">Return to list of scientific program</a>
  5 +
  6 + <p><strong>Name : </strong>{{ scientific_program.name }}</p>
  7 + <p><strong>Quota : </strong>{{ scientific_program.quota }}</p>
  8 + <p><strong>Priority: </strong>{{ scientific_program.priority }}</p>
  9 + <table class="table table-bordered table-hover table-striped tablesorter" style="font-family: 'Montserra', sans-serif;">
  10 + <thead>
  11 + <tr>
  12 + <th>Users <i class="fa fa-sort"></i></th>
  13 + </tr>
  14 + </thead>
  15 + <tbody>
  16 + {% for user in scientific_program.pyros_users.all %}
  17 + <tr><td>{{ user.username }}</td></tr>
  18 + {% endfor %}
  19 + </tbody>
  20 + </table></p>
  21 + {% if USER_LEVEL >= USER_LEVEL_PI %}
  22 + <a href="{% url "edit_scientific_program" scientific_program.id %}" class="btn btn-info" role="button">Edit</a>
  23 + {% endif %}
  24 + {% if USER_LEVEL >= USER_LEVEL_PI %}
  25 + <a href="{% url "delete_scientific_program" scientific_program.id %}" class="btn btn-danger" role="button">Delete</a>
  26 + {% endif %}
  27 +</form>
  28 +
  29 +{% endblock %}
0 30 \ No newline at end of file
... ...
src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail_edit.html 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +{% extends 'base.html' %}
  2 +
  3 +{% block content %}
  4 +
  5 +<form id="editSPForm" action="" method="post">
  6 + {% csrf_token %}
  7 + {{ form.as_p }}
  8 + <input id="submit" class="btn btn-info" type="submit" value="Submit" />
  9 + <a href="{% url "detail_scientific_program" id %}" class="btn btn-info" role="button">Cancel</a>
  10 +</form>
  11 +
  12 +{% endblock %}
0 13 \ No newline at end of file
... ...
src/core/pyros_django/scientific_program/tests.py 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +from django.test import TestCase
  2 +
  3 +# Create your tests here.
... ...
src/core/pyros_django/scientific_program/urls.py 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +from django.conf.urls import url
  2 +from django.urls import path
  3 +from . import views
  4 +
  5 +urlpatterns = [
  6 + path('create_scientific_program', views.create_sp,name='create_scientific_program'),
  7 + path('edit_scientific_program/<int:id>/', views.edit_sp,name='edit_scientific_program'),
  8 + path('detail_scientific_program/<int:id>/', views.detail_sp,name='detail_scientific_program'),
  9 + path('delete_scientific_program/<int:id>/', views.delete_sp,name='delete_scientific_program'),
  10 +]
... ...
src/core/pyros_django/scientific_program/views.py 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +from django.shortcuts import render,redirect,get_object_or_404,reverse
  2 +from django.contrib.auth import authenticate
  3 +from django.contrib.auth.decorators import login_required
  4 +from .forms import ScientificProgramForm
  5 +from src.core.pyros_django.dashboard.decorator import level_required
  6 +from common.models import ScientificProgram
  7 +from django.http import HttpResponseRedirect
  8 +
  9 +
  10 +@level_required(6)
  11 +@login_required
  12 +def create_sp(request):
  13 + form = ScientificProgramForm(request.POST)
  14 + if request.POST:
  15 + if form.is_valid():
  16 + form.save()
  17 + return HttpResponseRedirect(reverse("proposal"))
  18 + form = ScientificProgramForm()
  19 + return render(request,"scientific_program/create_scientific_program.html",{"form": form})
  20 +
  21 +@level_required(6)
  22 +@login_required
  23 +def edit_sp(request,id):
  24 + edit = get_object_or_404(ScientificProgram, pk=id)
  25 + form = ScientificProgramForm(request.POST or None, instance=edit)
  26 + if form.is_valid():
  27 + form.save()
  28 + return redirect('detail_scientific_program', id=id)
  29 + return render(request, 'scientific_program/scientific_program_detail_edit.html', {'id' : id, 'form': form})
  30 +
  31 +
  32 +@login_required
  33 +def detail_sp(request,id):
  34 + scientific_program = get_object_or_404(ScientificProgram, pk=id)
  35 + return render(request, 'scientific_program/scientific_program_detail.html', {'scientific_program': scientific_program})
  36 +
  37 +@level_required(6)
  38 +@login_required()
  39 +def delete_sp(request,id):
  40 + scientific_program = get_object_or_404(ScientificProgram, pk=int(id))
  41 + scientific_program.delete()
  42 + return HttpResponseRedirect(reverse('proposal'))
0 43 \ No newline at end of file
... ...