From d73ed0664280d57b0cbe935ec93dc0bd1164d231 Mon Sep 17 00:00:00 2001 From: ALEXIS-PC\alexis Date: Thu, 15 Apr 2021 19:13:33 +0200 Subject: [PATCH] adding scientific program CRUD pages --- src/core/pyros_django/dashboard/templates/dashboard/proposal.html | 15 +++++++++++++-- src/core/pyros_django/pyros/settings.py | 1 + src/core/pyros_django/pyros/urls.py | 1 + src/core/pyros_django/scientific_program/__init__.py | 0 src/core/pyros_django/scientific_program/admin.py | 3 +++ src/core/pyros_django/scientific_program/apps.py | 5 +++++ src/core/pyros_django/scientific_program/forms.py | 21 +++++++++++++++++++++ src/core/pyros_django/scientific_program/migrations/__init__.py | 0 src/core/pyros_django/scientific_program/models.py | 3 +++ src/core/pyros_django/scientific_program/templates/scientific_program/create_scientific_program.html | 12 ++++++++++++ src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail.html | 29 +++++++++++++++++++++++++++++ src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail_edit.html | 12 ++++++++++++ src/core/pyros_django/scientific_program/tests.py | 3 +++ src/core/pyros_django/scientific_program/urls.py | 10 ++++++++++ src/core/pyros_django/scientific_program/views.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 src/core/pyros_django/scientific_program/__init__.py create mode 100644 src/core/pyros_django/scientific_program/admin.py create mode 100644 src/core/pyros_django/scientific_program/apps.py create mode 100644 src/core/pyros_django/scientific_program/forms.py create mode 100644 src/core/pyros_django/scientific_program/migrations/__init__.py create mode 100644 src/core/pyros_django/scientific_program/models.py create mode 100644 src/core/pyros_django/scientific_program/templates/scientific_program/create_scientific_program.html create mode 100644 src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail.html create mode 100644 src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail_edit.html create mode 100644 src/core/pyros_django/scientific_program/tests.py create mode 100644 src/core/pyros_django/scientific_program/urls.py create mode 100644 src/core/pyros_django/scientific_program/views.py diff --git a/src/core/pyros_django/dashboard/templates/dashboard/proposal.html b/src/core/pyros_django/dashboard/templates/dashboard/proposal.html index b1bca0c..752dad2 100644 --- a/src/core/pyros_django/dashboard/templates/dashboard/proposal.html +++ b/src/core/pyros_django/dashboard/templates/dashboard/proposal.html @@ -29,6 +29,9 @@

List of proposal Info - {{proposal_info|length}}

+ {% if USER_LEVEL >= USER_LEVEL_PI %} + Create new scientific_program + {% endif %} @@ -43,8 +46,16 @@ {% for proposal_inf in proposal_info %} - - + + + diff --git a/src/core/pyros_django/pyros/settings.py b/src/core/pyros_django/pyros/settings.py index 2299ea1..a6ca668 100644 --- a/src/core/pyros_django/pyros/settings.py +++ b/src/core/pyros_django/pyros/settings.py @@ -162,6 +162,7 @@ INSTALLED_APPS = [ 'routine_manager', 'user_manager', 'devices', + 'scientific_program', #'kombu.transport.django' ] diff --git a/src/core/pyros_django/pyros/urls.py b/src/core/pyros_django/pyros/urls.py index 5027961..e2f630e 100644 --- a/src/core/pyros_django/pyros/urls.py +++ b/src/core/pyros_django/pyros/urls.py @@ -40,6 +40,7 @@ urlpatterns = [ url(r'^observation_manager/', include('observation_manager.urls')), url(r'^routine_manager/', include('routine_manager.urls')), url(r'^user_manager/', include('user_manager.urls')), + url(r'^scientific_program/', include('scientific_program.urls')), url(r'^$', user_manager.views.home) ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/src/core/pyros_django/scientific_program/__init__.py b/src/core/pyros_django/scientific_program/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/core/pyros_django/scientific_program/__init__.py diff --git a/src/core/pyros_django/scientific_program/admin.py b/src/core/pyros_django/scientific_program/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/src/core/pyros_django/scientific_program/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/src/core/pyros_django/scientific_program/apps.py b/src/core/pyros_django/scientific_program/apps.py new file mode 100644 index 0000000..e723edf --- /dev/null +++ b/src/core/pyros_django/scientific_program/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ScientificProgramConfig(AppConfig): + name = 'scientific_program' diff --git a/src/core/pyros_django/scientific_program/forms.py b/src/core/pyros_django/scientific_program/forms.py new file mode 100644 index 0000000..bdc2e2b --- /dev/null +++ b/src/core/pyros_django/scientific_program/forms.py @@ -0,0 +1,21 @@ +from django import forms +from common.models import ScientificProgram,PyrosUser + +class ScientificProgramForm(forms.ModelForm): + + class Meta: + model = ScientificProgram + fields = ( + "name", + "desc", + "quota", + "priority", + "pyros_users", + ) + + + widgets = { + + "pyros_users": forms.CheckboxSelectMultiple() + } + diff --git a/src/core/pyros_django/scientific_program/migrations/__init__.py b/src/core/pyros_django/scientific_program/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/core/pyros_django/scientific_program/migrations/__init__.py diff --git a/src/core/pyros_django/scientific_program/models.py b/src/core/pyros_django/scientific_program/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/src/core/pyros_django/scientific_program/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/src/core/pyros_django/scientific_program/templates/scientific_program/create_scientific_program.html b/src/core/pyros_django/scientific_program/templates/scientific_program/create_scientific_program.html new file mode 100644 index 0000000..8de526b --- /dev/null +++ b/src/core/pyros_django/scientific_program/templates/scientific_program/create_scientific_program.html @@ -0,0 +1,12 @@ +{% extends 'base.html' %} + +{% block content %} + + + {% csrf_token %} + {{ form.as_p }} + + Cancel + + +{% endblock %} \ No newline at end of file diff --git a/src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail.html b/src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail.html new file mode 100644 index 0000000..7047d0a --- /dev/null +++ b/src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail.html @@ -0,0 +1,29 @@ +{% extends 'base.html' %} + +{% block content %} + Return to list of scientific program + +

Name : {{ scientific_program.name }}

+

Quota : {{ scientific_program.quota }}

+

Priority: {{ scientific_program.priority }}

+
{{ proposal_inf.pyros_users }}{{ proposal_inf.name }} + {% for user in proposal_inf.pyros_users.all|slice:":3" %} + {{ user.username }} + {% endfor %} + {% if proposal_inf.pyros_users.all.count > 3 %} + ... + {% endif %} + {{ proposal_inf.name }} {{ proposal_inf.desc }} {{ proposal_inf.quota }} {{ proposal_inf.priority }}
+ + + + + + + {% for user in scientific_program.pyros_users.all %} + + {% endfor %} + +
Users
{{ user.username }}

+ {% if USER_LEVEL >= USER_LEVEL_PI %} + Edit + {% endif %} + {% if USER_LEVEL >= USER_LEVEL_PI %} + Delete + {% endif %} + + +{% endblock %} \ No newline at end of file diff --git a/src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail_edit.html b/src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail_edit.html new file mode 100644 index 0000000..f5d2c66 --- /dev/null +++ b/src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail_edit.html @@ -0,0 +1,12 @@ +{% extends 'base.html' %} + +{% block content %} + +
+ {% csrf_token %} + {{ form.as_p }} + + Cancel +
+ +{% endblock %} \ No newline at end of file diff --git a/src/core/pyros_django/scientific_program/tests.py b/src/core/pyros_django/scientific_program/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/src/core/pyros_django/scientific_program/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/src/core/pyros_django/scientific_program/urls.py b/src/core/pyros_django/scientific_program/urls.py new file mode 100644 index 0000000..b9fda94 --- /dev/null +++ b/src/core/pyros_django/scientific_program/urls.py @@ -0,0 +1,10 @@ +from django.conf.urls import url +from django.urls import path +from . import views + +urlpatterns = [ + path('create_scientific_program', views.create_sp,name='create_scientific_program'), + path('edit_scientific_program//', views.edit_sp,name='edit_scientific_program'), + path('detail_scientific_program//', views.detail_sp,name='detail_scientific_program'), + path('delete_scientific_program//', views.delete_sp,name='delete_scientific_program'), +] diff --git a/src/core/pyros_django/scientific_program/views.py b/src/core/pyros_django/scientific_program/views.py new file mode 100644 index 0000000..a1476b0 --- /dev/null +++ b/src/core/pyros_django/scientific_program/views.py @@ -0,0 +1,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')) \ No newline at end of file -- libgit2 0.21.2