minor adjustements

This commit is contained in:
Lucie Galland 2021-04-29 01:00:17 +02:00
parent 777bd930c6
commit 7b19a581cf
2 changed files with 15 additions and 14 deletions

View file

@ -13,16 +13,16 @@
<div class="row"> <div class="row">
<div class="7u 12u$(small)"> <div class="7u 12u$(small)">
<p>{% trans "Propriétaire : "%} {{instru.owner}} <br> <p>{% trans "Propriétaire : "%} {% if instru.owner %}{{instru.owner}} {% else %}-{% endif %}<br>
{% trans "Statut : "%} {{instru.statut}} <br> {% trans "Statut : "%} {{instru.statut}} <br>
{% ifequal instru.statut 'Prêté' %} {% ifequal instru.statut 'Prêté' %}
{% trans "Utilisateur : "%} {{instru.user}} <br> {% trans "Utilisateur : "%} {% if instru.user %}{{instru.user}} {% else %}-{% endif %}<br>
{% endifequal %} {% endifequal %}
{% trans "Marque : "%} {{instru.marque}} <br> {% trans "Marque : "%} {% if instru.marque %}{{instru.marque}} {% else %}-{% endif %} <br>
{% trans "Modele : "%} {{instru.model}} <br> {% trans "Modele : "%} {% if instru.model %}{{instru.model}} {% else %}-{% endif %}<br>
{% trans "Numéro de série : "%} {{instru.serial}} <br> {% trans "Numéro de série : "%} {% if instru.serial %}{{instru.serial}}{% else %}-{% endif %} <br>
{% trans "Prix : "%} {{instru.prix}} <br> {% trans "Prix : "%} {% if instru.prix %}{{instru.prix}} {% else %}-{% endif %}<br>
{% blocktrans with annee=instru.annee %} Acheté·e en {{annee}} {% endblocktrans%} {% trans "Acheté·e en" %}{% if instru.annee %}{{annee}}{% else %}-{% endif %}
</p> </p>
{% if infos or infos_en %} {% if infos or infos_en %}

View file

@ -119,30 +119,29 @@ class Morceau(LoginRequiredMixin, TemplateView):
class Upload(ChefRequiredMixin, TemplateView): class Upload(ChefRequiredMixin, TemplateView):
form_class = UploadFileForm form_class = UploadFileForm
sauvegarde = False
error = False
template_name = "partitions/upload.html" template_name = "partitions/upload.html"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(Upload, self).get_context_data(**kwargs) context = super(Upload, self).get_context_data(**kwargs)
form = self.form_class() form = self.form_class()
context["sauvegarde"] = self.sauvegarde
context["nom"] = self.kwargs["nom"] context["nom"] = self.kwargs["nom"]
context["auteur"] = self.kwargs["auteur"] context["auteur"] = self.kwargs["auteur"]
context["form"] = form context["form"] = form
context["error"] = self.error
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
form = UploadFileForm(request.POST, request.FILES) form = UploadFileForm(request.POST, request.FILES)
error = False
sauvegarde = False
if form.is_valid(): if form.is_valid():
partition = Partition() partition = Partition()
partition.part = form.cleaned_data["file"] partition.part = form.cleaned_data["file"]
partition.nom = form.cleaned_data["title"] partition.nom = form.cleaned_data["title"]
if "/" in partition.nom: if "/" in partition.nom:
self.error = _("Le caractère / n'est pas autorisé dans le nom") error = _("Le caractère / n'est pas autorisé dans le nom")
context = self.get_context_data() context = self.get_context_data()
context["error"] = error
return render(request, self.template_name, context) return render(request, self.template_name, context)
mor = get_object_or_404( mor = get_object_or_404(
PartitionSet, nom=self.kwargs["nom"], auteur=self.kwargs["auteur"] PartitionSet, nom=self.kwargs["nom"], auteur=self.kwargs["auteur"]
@ -150,13 +149,15 @@ class Upload(ChefRequiredMixin, TemplateView):
partition.morceau = mor partition.morceau = mor
try: try:
mor.partition_set.get(nom=partition.nom) mor.partition_set.get(nom=partition.nom)
self.error = _("Un morceau du même nom existe déjà") error = _("Un morceau du même nom existe déjà")
except Partition.DoesNotExist: except Partition.DoesNotExist:
partition.save() partition.save()
self.sauvegarde = True sauvegarde = True
context = self.get_context_data() context = self.get_context_data()
context["form"] = form context["form"] = form
context["error"] = error
context["sauvegarde"] = sauvegarde
return render(request, self.template_name, context) return render(request, self.template_name, context)