Commit 7ed6b971 authored by ynerant's avatar ynerant

Add present field

parent 57659acc
Pipeline #4119 passed with stages
in 5 minutes and 2 seconds
# Generated by Django 2.2.16 on 2020-09-25 12:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('media', '0038_auto_20200923_2030'),
]
operations = [
migrations.AddField(
model_name='bd',
name='present',
field=models.BooleanField(default=False, help_text='Tell that the medium is present in the Mediatek.', verbose_name='present'),
),
migrations.AddField(
model_name='cd',
name='present',
field=models.BooleanField(default=False, help_text='Tell that the medium is present in the Mediatek.', verbose_name='present'),
),
migrations.AddField(
model_name='futuremedia',
name='present',
field=models.BooleanField(default=False, help_text='Tell that the medium is present in the Mediatek.', verbose_name='present'),
),
migrations.AddField(
model_name='manga',
name='present',
field=models.BooleanField(default=False, help_text='Tell that the medium is present in the Mediatek.', verbose_name='present'),
),
migrations.AddField(
model_name='revue',
name='present',
field=models.BooleanField(default=False, help_text='Tell that the medium is present in the Mediatek.', verbose_name='present'),
),
migrations.AddField(
model_name='roman',
name='present',
field=models.BooleanField(default=False, help_text='Tell that the medium is present in the Mediatek.', verbose_name='present'),
),
migrations.AddField(
model_name='vinyle',
name='present',
field=models.BooleanField(default=False, help_text='Tell that the medium is present in the Mediatek.', verbose_name='present'),
),
]
......@@ -77,6 +77,12 @@ class BD(models.Model):
null=True,
)
present = models.BooleanField(
verbose_name=_("present"),
help_text=_("Tell that the medium is present in the Mediatek."),
default=False,
)
def __str__(self):
if self.subtitle:
return "{} : {}".format(self.title, self.subtitle)
......@@ -136,6 +142,12 @@ class Manga(models.Model):
null=True,
)
present = models.BooleanField(
verbose_name=_("present"),
help_text=_("Tell that the medium is present in the Mediatek."),
default=False,
)
def __str__(self):
return self.title
......@@ -192,6 +204,12 @@ class Roman(models.Model):
null=True,
)
present = models.BooleanField(
verbose_name=_("present"),
help_text=_("Tell that the medium is present in the Mediatek."),
default=False,
)
def __str__(self):
return self.title
......@@ -225,6 +243,12 @@ class Vinyle(models.Model):
verbose_name=_('authors'),
)
present = models.BooleanField(
verbose_name=_("present"),
help_text=_("Tell that the medium is present in the Mediatek."),
default=False,
)
def __str__(self):
return self.title
......@@ -250,6 +274,12 @@ class CD(models.Model):
verbose_name=_('authors'),
)
present = models.BooleanField(
verbose_name=_("present"),
help_text=_("Tell that the medium is present in the Mediatek."),
default=False,
)
def __str__(self):
return self.title
......@@ -295,6 +325,12 @@ class Revue(models.Model):
default=False,
)
present = models.BooleanField(
verbose_name=_("present"),
help_text=_("Tell that the medium is present in the Mediatek."),
default=False,
)
def __str__(self):
return self.title + " n°" + str(self.number)
......@@ -323,6 +359,12 @@ class FutureMedia(models.Model):
max_length=8,
)
present = models.BooleanField(
verbose_name=_("present"),
help_text=_("Tell that the medium is present in the Mediatek."),
default=False,
)
class Meta:
verbose_name = _("future medium")
verbose_name_plural = _("future media")
......
{% extends "base.html" %}
{% block content %}
<form action="#" onsubmit="searchISBN()">
<form id="form" action="#" onsubmit="searchISBN()">
<label for="isbn" id="id_isbn_label">ISBN :</label>
<input type="text" id="isbn" autofocus />
<input type="submit" id="isbn_search" />
<input type="text" id="isbn" autofocus>
<input type="hidden" id="old-isbn">
<input type="submit" id="isbn_search">
<input type="checkbox" id="mark_as_present" checked onchange="document.getElementById('isbn').focus()" />
<label for="mark_as_present">Marquer automatiquement comme présent si trouvé et que je cherche par ISBN</label>
</form>
<ul id="result"></ul>
{% endblock %}
{% block extrajavascript %}
<script>
function markAsPresent(type, id, present=true) {
let request = new XMLHttpRequest();
request.open("GET", "/media/mark-as-present/" + type + "/" + id + "/" + (present ? "" : "?absent=1"), true);
request.onload = function() {
document.getElementById("isbn").value = document.getElementById("old-isbn").value;
searchISBN();
};
request.send();
}
function searchISBN() {
let isbn = document.getElementById("isbn").value;
let result_div = document.getElementById("result");
let markAsPresent = document.getElementById("mark_as_present").checked;
result_div.innerHTML = "<li id='recap-isbn'>Recherche : " + isbn + "</li>";
document.getElementById("isbn").value = "";
document.getElementById("old-isbn").value = isbn;
document.getElementById("isbn").focus();
let bd_request = new XMLHttpRequest();
......@@ -24,9 +40,18 @@
bd_request.onload = function () {
let data = JSON.parse(this.response);
data.results.forEach(bd => {
let present = bd.present;
if (markAsPresent && isbn === bd.isbn) {
present = true;
let presentRequest = new XMLHttpRequest();
presentRequest.open("GET", "/media/mark-as-present/bd/" + bd.id + "/", true);
presentRequest.send();
}
result_div.innerHTML += "<li id='bd_" + bd.id + "'>" +
"<a href='/database/media/bd/" + bd.id + "/change/'>BD : "
+ bd.title + (bd.subtitle ? " - " + bd.subtitle : "") + "</a></li>";
+ bd.title + (bd.subtitle ? " - " + bd.subtitle : "") + "</a>"
+ (present ? " (<a class='absent' href='#' onclick=\"markAsPresent('bd', " + bd.id + ", false)\">marquer comme absent</a>)"
: " (absent, <a class='present' href='#' onclick=\"markAsPresent('bd', " + bd.id + ")\">marquer comme présent</a>)") + "</li>";
});
}
bd_request.send();
......@@ -36,9 +61,18 @@
manga_request.onload = function () {
let data = JSON.parse(this.response);
data.results.forEach(manga => {
let present = manga.present;
if (markAsPresent && isbn === manga.isbn) {
present = true;
let presentRequest = new XMLHttpRequest();
presentRequest.open("GET", "/media/mark-as-present/manga/" + manga.id + "/", true);
presentRequest.send();
}
result_div.innerHTML += "<li id='manga_" + manga.id + "'>" +
"<a href='/database/media/manga/" + manga.id + "/change/'>Manga : "
+ manga.title + (manga.subtitle ? " - " + manga.subtitle : "") + "</a></li>";
+ manga.title + (manga.subtitle ? " - " + manga.subtitle : "") + "</a>"
+ (present ? " (<a class='absent' href='#' onclick=\"markAsPresent('manga', " + manga.id + ", false)\">marquer comme absent</a>)"
: " (absent, <a class='present' href='#' onclick=\"markAsPresent('manga', " + manga.id + ")\">marquer comme présent</a>)") + "</li>";
});
}
manga_request.send();
......@@ -48,8 +82,11 @@
cd_request.onload = function () {
let data = JSON.parse(this.response);
data.results.forEach(cd => {
let present = cd.present;
result_div.innerHTML += "<li id='cd_" + cd.id + "'>" +
"<a href='/database/media/cd/" + cd.id + "/change/'>CD : " + cd.title + "</a></li>";
"<a href='/database/media/cd/" + cd.id + "/change/'>CD : " + cd.title + "</a>"
+ (present ? " (<a class='absent' href='#' onclick=\"markAsPresent('cd', " + cd.id + ", false)\">marquer comme absent</a>)"
: " (absent, <a class='present' href='#' onclick=\"markAsPresent('cd', " + cd.id + ")\">marquer comme présent</a>)") + "</li>";
});
}
cd_request.send();
......@@ -59,8 +96,11 @@
vinyle_request.onload = function () {
let data = JSON.parse(this.response);
data.results.forEach(vinyle => {
let present = markAsPresent || vinyle.present;
result_div.innerHTML += "<li id='vinyle_" + vinyle.id + "'>" +
"<a href='/database/media/vinyle/" + vinyle.id + "/change/'>Vinyle : " + vinyle.title + "</a></li>";
"<a href='/database/media/vinyle/" + vinyle.id + "/change/'>Vinyle : " + vinyle.title + "</a>"
+ (present ? " (<a class='absent' href='#' onclick=\"markAsPresent('vinyle', " + vinyle.id + ", false)\">marquer comme absent</a>)"
: " (absent, <a class='present' href='#' onclick=\"markAsPresent('vinyle', " + vinyle.id + ")\">marquer comme présent</a>)") + "</li>";
});
}
vinyle_request.send();
......@@ -70,8 +110,17 @@
roman_request.onload = function () {
let data = JSON.parse(this.response);
data.results.forEach(roman => {
let present = roman.present;
if (markAsPresent && isbn === roman.isbn) {
present = true;
let presentRequest = new XMLHttpRequest();
presentRequest.open("GET", "/media/mark-as-present/roman/" + roman.id + "/", true);
presentRequest.send();
}
result_div.innerHTML += "<li id='roman_" + roman.id + "'>" +
"<a href='/database/media/roman/" + roman.id + "/change/'>Roman : " + roman.title + "</a></li>";
"<a href='/database/media/roman/" + roman.id + "/change/'>Roman : " + roman.title + "</a>"
+ (present ? " (<a class='absent' href='#' onclick=\"markAsPresent('roman', " + roman.id + ", false)\">marquer comme absent</a>)"
: " (absent, <a class='present' href='#' onclick=\"markAsPresent('roman', " + roman.id + ")\">marquer comme présent</a>)") + "</li>";
});
}
roman_request.send();
......@@ -81,9 +130,17 @@
future_request.onload = function () {
let data = JSON.parse(this.response);
data.results.forEach(future => {
let present = future.present;
if (markAsPresent && isbn === future.isbn) {
present = true;
let presentRequest = new XMLHttpRequest();
presentRequest.open("GET", "/media/mark-as-present/future/" + bd.id + "/", true);
presentRequest.send();
}
result_div.innerHTML += "<li id='future_" + future.id + "'>" +
"<a href='/database/media/future/" + future.id + "/change/'>Medium non traité : "
+ future.title + "</a></li>";
"<a href='/database/media/future/" + future.id + "/change/'>Medium non traité : " + future.title + "</a>"
+ (present ? " (<a class='absent' href='#' onclick=\"markAsPresent('future', " + future.id + ", false)\">marquer comme absent</a>)"
: " (absent, <a class='present' href='#' onclick=\"markAsPresent('future', " + future.id + ")\">marquer comme présent</a>)") + "</li>";
});
}
future_request.send();
......
......@@ -12,4 +12,11 @@ urlpatterns = [
url(r'^retour_emprunt/(?P<empruntid>[0-9]+)$', views.retour_emprunt,
name='retour-emprunt'),
path('find/', views.FindMediumView.as_view(), name="find"),
path('mark-as-present/bd/<int:pk>/', views.MarkBDAsPresent.as_view(), name="mark_bd_as_present"),
path('mark-as-present/manga/<int:pk>/', views.MarkMangaAsPresent.as_view(), name="mark_manga_as_present"),
path('mark-as-present/cd/<int:pk>/', views.MarkCDAsPresent.as_view(), name="mark_cd_as_present"),
path('mark-as-present/vinyle/<int:pk>/', views.MarkVinyleAsPresent.as_view(), name="mark_vinyle_as_present"),
path('mark-as-present/roman/<int:pk>/', views.MarkRomanAsPresent.as_view(), name="mark_roman_as_present"),
path('mark-as-present/revue/<int:pk>/', views.MarkRevueAsPresent.as_view(), name="mark_revue_as_present"),
path('mark-as-present/future/<int:pk>/', views.MarkFutureAsPresent.as_view(), name="mark_future_as_present"),
]
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from http.client import NO_CONTENT
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponse
from django_filters.rest_framework import DjangoFilterBackend
from django.db import transaction
from django.shortcuts import redirect, render
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView
from django.views.generic import TemplateView, DetailView
from rest_framework import viewsets
from rest_framework.filters import SearchFilter
from reversion import revisions as reversion
......@@ -53,6 +55,42 @@ class FindMediumView(LoginRequiredMixin, TemplateView):
template_name = "media/find_medium.html"
class MarkMediumAsPresent(LoginRequiredMixin, DetailView):
def dispatch(self, request, *args, **kwargs):
object = self.get_object()
object.present = not request.GET.get("absent", False)
object.save()
return HttpResponse("", content_type=204)
class MarkBDAsPresent(MarkMediumAsPresent):
model = BD
class MarkMangaAsPresent(MarkMediumAsPresent):
model = Manga
class MarkCDAsPresent(MarkMediumAsPresent):
model = CD
class MarkVinyleAsPresent(MarkMediumAsPresent):
model = Vinyle
class MarkRomanAsPresent(MarkMediumAsPresent):
model = Roman
class MarkRevueAsPresent(MarkMediumAsPresent):
model = Revue
class MarkFutureAsPresent(MarkMediumAsPresent):
model = FutureMedia
class AuteurViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows authors to be viewed or edited.
......@@ -127,7 +165,6 @@ class RevueViewSet(viewsets.ModelViewSet):
search_fields = ["$title"]
class FutureMediaViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows media to be viewed or edited.
......
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