Commit 9996aceb authored by hypsug0's avatar hypsug0
Browse files

feat: study detail view

parent b25f59ba
......@@ -42,6 +42,10 @@
"beautify.language": {
"html": ["htm", "html", "django-html"]
},
"[django-html]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "HookyQR.beautify"
},
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
......
......@@ -95,6 +95,7 @@ header h1 {
color: #fff;
height: 65px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
background-color: #473030;
}
.page-header h1 {
......
......@@ -1816,3 +1816,23 @@ const sigthingFormApp = (id_session, type_contact) => {
// options
}
}
const studyDataApp = (pk) => {
return {
el: '#StudyData',
delimiters: ['[[', ']]'],
data() {
return {
pk :pk,
msg: 'Test',
placeData: [],
sessionData: [],
sightingData: [],
data_source: 'stats',
}
}
}
}
# import the logging library
import logging
from rest_framework.generics import ListAPIView
from sights.models import Place
from sights.observation.api import GeoJSONSighting
from .serializers import StudySightingsSerializer
logger = logging.getLogger(__name__)
class StudySightings(GeoJSONSighting):
pagination_class = None
def get_queryset(self, *args, **kwargs):
qs = super().get_queryset()
qs = qs.filter(session__study__pk=self.kwargs.get("pk"))
return qs.distinct().order_by("-timestamp_update")
class StudySightingsTest(ListAPIView):
serializer_class = StudySightingsSerializer
def get_queryset(self, *args, **kwargs):
qs = Place.objects.filter(session__study=self.kwargs.get("pk"))
return qs.distinct().order_by("-timestamp_update")
import logging
from rest_framework.serializers import ModelSerializer
from sights.models import Place, Session
logger = logging.getLogger(__name__)
class SessionSerializer(ModelSerializer):
class Meta:
model = Session
fields = ("id_session", "name", "date_start")
class StudySightingsSerializer(ModelSerializer):
sessions = SessionSerializer(many=True)
class Meta:
model = Place
fields = ("name", "sessions")
def get_sessions(self, place):
sessions = Session.objects.filter(place=place.pk)
logger.debug(f"SESSIONSSSSS {sessions}")
return sessions
"""
Vues de l'application Sights
"""
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.views.generic import DetailView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from django_tables2 import SingleTableView
from ..forms import StudyForm
from ..mixins import ManagementAuthMixin
from ..models import Study
from ..tables import StudyTable
class StudyCreate(LoginRequiredMixin, CreateView):
"""Create view for the Study model."""
model = Study
form_class = StudyForm
template_name = "normal_form.html"
def form_valid(self, form):
form.instance.created_by = self.request.user
return super(StudyCreate, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(StudyCreate, self).get_context_data(**kwargs)
context["icon"] = "fi-page"
context["title"] = _("Ajout d'une étude")
context[
"js"
] = """
"""
return context
class StudyUpdate(ManagementAuthMixin, UpdateView):
model = Study
form_class = StudyForm
template_name = "normal_form.html"
def form_valid(self, form):
form.instance.updated_by = self.request.user
return super(StudyUpdate, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(StudyUpdate, self).get_context_data(**kwargs)
context["icon"] = "fi-page"
context["title"] = _("Ajout d'une étude")
context[
"js"
] = """
"""
return context
class StudyDelete(ManagementAuthMixin, DeleteView):
model = Study
template_name = "confirm_delete.html"
success_url = reverse_lazy("management:study_list")
def get_context_data(self, **kwargs):
context = super(StudyDelete, self).get_context_data(**kwargs)
context["icon"] = "fi-trash"
context["title"] = _("Suppression d'une étude")
context["message_alert"] = _("Êtes-vous certain de vouloir supprimer l'étude")
return context
class StudyList(LoginRequiredMixin, SingleTableView):
table_class = StudyTable
model = Study
template_name = "table.html"
table_pagination = {"per_page": 25}
def get_context_data(self, **kwargs):
context = super(StudyList, self).get_context_data(**kwargs)
context["icon"] = "fi-page"
context["title"] = _("Liste des études")
context[
"js"
] = """
"""
return context
class StudyDetail(LoginRequiredMixin, DetailView):
queryset = Study.objects.select_related()
template_name = "study_detail.html"
def get_context_data(self, **kwargs):
context = super(StudyDetail, self).get_context_data(**kwargs)
context["icon"] = "fi-page"
context["title"] = _("Etude")
return context
{% extends 'base_fullwidth_leaflet.html' %}
{% load i18n %}
{% block title%}{{title}} | {{object.name}} - {{object.year}}{% endblock %} {% block content%}
<h1>
<i class="{{ icon | safe }}"></i> {{ title | safe }} {{object.name}}
({{object.year}})
</h1>
<p class="text-muted">
<small>Observation créée par <b>{{ object.created_by }}</b> le
<b>{{ object.timestamp_create }}</b> {% if object.updated_by %}et mise à
jour le <b>{{ object.timestamp_update }}</b> par
<b>{{ object.updated_by }}</b> {% endif %}</small>
</p>
<div class="row">
<div class="col-md-12 col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<i class="fa fa-info-circle fa-fw"></i>Fiche détaillée
</h4>
</div>
<div class="panel-body">
<h4>Informations générales</h4>
<dl class="dl-horizontal">
<dt>Identifiant unique</dt>
<dd><code>{{object.uuid}}</code></dd>
<dt>Nom</dt>
<dd>{{object.name}}</dd>
<dt>Année</dt>
<dd>{{object.year}}</dd>
<dt>Responsable</dt>
<dd>{{object.project_manager.get_full_name}}</dd>
<dt>Type d'étude</dt>
<dd>{{object.type_etude}}</dd>
<dt>Type d'espace</dt>
<dd>{{object.type_espace}}</dd>
</dl>
<h4>Informations pratiques</h4>
<dl class="dl-horizontal">
<dt>Financement publique</dt>
<dd>
<span
class="label label-{{ object.public_funding|yesno:'success,default'}}">{{object.public_funding|yesno:'Oui,Non,-'}}</span>
</dd>
<dt>Rapport rendu publique</dt>
<dd>
<span
class="label label-{{ object.public_report|yesno:'success,default'}}">{{object.public_report|yesno:'Oui,Non,-'}}</span>
</dd>
<dt>Donnée brute publique</dt>
<dd>
<span
class="label label-{{ object.public_raw_data|yesno:'success,default'}}">{{object.public_raw_data|yesno:'Oui,Non,-'}}</span>
</dd>
<dt>Confidentiel</dt>
<dd>
<span
class="label label-{{ object.confidential|yesno:'success,default'}}">{{object.confidential|yesno:'Oui,Non,-'}}</span>
{% if object.confidential_end_date %}(jusqu'au
{{object.confidential_end_date}}){%endif%}
</dd>
</dl>
</div>
</div>
</div>
<div class="col-md-12 col-lg-8">
<div id="StudyData" class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<i class="fas fa-clipboard-list fa-fw"></i>Données (Sessions: {{object.sessions.count}})
</h4>
</div>
<div class="list-group">
{% for s in object.sessions.all %}
<div class="list-group-item">
<h4 class="list-group-item-heading">{{s.place.name}} - {{s.date_start}} ({{s.contact.descr}})
</h4>
<p class="list-group-item-text">
<dl class="dl-horizontal">
<dt>Observateur principal</dt>
<dd>
{{s.main_observer.get_full_name}}</dd>
<dt>Observations</dt>
<dd>
<ul class="list-unstyled">
{%for o in s.sighting_set.all %}
<li>{{o.codesp.sci_name}} : {{o.total_count}} {{o.is_breeding}}</li>
{% endfor %}
</ul>
</dd>
</dl>
</p>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
<script>
const studyId = parseInt('{{object.pk}}')
// $(document).ready(() => {
// const vm = new Vue(studyDataApp(parseInt('{{object.pk}}')))
// })
</script>
{% endblock %}
from django.urls import path
from .study.api import StudySightings, StudySightingsTest
from .study.views import StudyCreate, StudyDelete, StudyDetail, StudyList, StudyUpdate
from .transmitter.api import TransmitterSearchApi
from .transmitter.views import (
TransmitterCreate,
......@@ -7,26 +9,22 @@ from .transmitter.views import (
TransmitterList,
TransmitterUpdate,
)
from .views import (
CatchAuthCreate,
CatchAuthDelete,
CatchAuthList,
CatchAuthUpdate,
StudyCreate,
StudyDelete,
StudyList,
StudyUpdate,
)
from .views import CatchAuthCreate, CatchAuthDelete, CatchAuthList, CatchAuthUpdate
app_name = "management"
urlpatterns = [
# Place relative URLS
# Study relative URLS
path("study/add", StudyCreate.as_view(), name="study_create"),
path("study/<int:pk>/update", StudyUpdate.as_view(), name="study_update"),
path("study/<int:pk>/delete", StudyDelete.as_view(), name="study_delete"),
path("study/list", StudyList.as_view(), name="study_list"),
path("study/list/<int:page>", StudyList.as_view(), name="url_study_list"),
path("study/detail/<int:pk>", StudyDetail.as_view(), name="url_study_detail"),
path(
"api/v1/study/<int:pk>/observations", StudySightings.as_view(), name="api_study_sightings"
),
path("api/v1/study/<int:pk>/datas", StudySightingsTest.as_view(), name="api_study_data"),
# Transmitter relative URLS
path("transmitter/add", TransmitterCreate.as_view(), name="transmitter_create"),
path(
......
......@@ -13,82 +13,10 @@ from django_tables2 import SingleTableView
from core import js
from .forms import CatchAuthForm, StudyForm
from .forms import CatchAuthForm
from .mixins import CatchAuthCreateAuthMixin, ManagementAuthMixin
from .models import CatchAuth, Study
from .tables import CatchAuthTable, StudyTable
class StudyCreate(LoginRequiredMixin, CreateView):
"""Create view for the Study model."""
model = Study
form_class = StudyForm
template_name = "normal_form.html"
def form_valid(self, form):
form.instance.created_by = self.request.user
return super(StudyCreate, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(StudyCreate, self).get_context_data(**kwargs)
context["icon"] = "fi-page"
context["title"] = _("Ajout d'une étude")
context[
"js"
] = """
"""
return context
class StudyUpdate(ManagementAuthMixin, UpdateView):
model = Study
form_class = StudyForm
template_name = "normal_form.html"
def form_valid(self, form):
form.instance.updated_by = self.request.user
return super(StudyUpdate, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(StudyUpdate, self).get_context_data(**kwargs)
context["icon"] = "fi-page"
context["title"] = _("Ajout d'une étude")
context[
"js"
] = """
"""
return context
class StudyDelete(ManagementAuthMixin, DeleteView):
model = Study
template_name = "confirm_delete.html"
success_url = reverse_lazy("management:study_list")
def get_context_data(self, **kwargs):
context = super(StudyDelete, self).get_context_data(**kwargs)
context["icon"] = "fi-trash"
context["title"] = _("Suppression d'une étude")
context["message_alert"] = _("Êtes-vous certain de vouloir supprimer l'étude")
return context
class StudyList(LoginRequiredMixin, SingleTableView):
table_class = StudyTable
model = Study
template_name = "table.html"
table_pagination = {"per_page": 25}
def get_context_data(self, **kwargs):
context = super(StudyList, self).get_context_data(**kwargs)
context["icon"] = "fi-page"
context["title"] = _("Liste des études")
context[
"js"
] = """
"""
return context
from .models import CatchAuth
from .tables import CatchAuthTable
class CatchAuthCreate(CatchAuthCreateAuthMixin, CreateView):
......
......@@ -870,7 +870,7 @@ class Session(models.Model):
Study,
models.DO_NOTHING,
verbose_name="Etude",
related_name="study",
related_name="sessions",
blank=True,
null=True,
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment