From 65dd7e5fa3ee54b389b200aaa7e7007a87cab60f Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 24 May 2019 19:32:57 +0200 Subject: [PATCH] Suppression d'article MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On fait pareil que précédemment pour les articles, en rajoutant une vie de délétion + de quoi afficher qu'un article a été supprimé. N.B. : le formatage automatique de VSCode fait plein de changements, donc pourquoi pas les garder. --- kfet/static/kfet/js/history.js | 50 ++++++------- kfet/templates/kfet/article_read.html | 100 ++++++++++++++++---------- kfet/urls.py | 6 ++ kfet/views.py | 14 ++++ 4 files changed, 109 insertions(+), 61 deletions(-) diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 8559f050..1c6495a7 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -1,28 +1,28 @@ -function KHistory(options={}) { +function KHistory(options = {}) { $.extend(this, KHistory.default_options, options); this.$container = $(this.container); - this.reset = function() { + this.reset = function () { this.$container.html(''); }; - this.addOpeGroup = function(opegroup) { + this.addOpeGroup = function (opegroup) { var $day = this._getOrCreateDay(opegroup['at']); var $opegroup = this._opeGroupHtml(opegroup); $day.after($opegroup); var trigramme = opegroup['on_acc_trigramme']; - var is_cof = opegroup['is_cof']; - for (var i=0; i Éditer + {% if perms.kfet.delete_account %} + +
+ {% csrf_token %} +
+ {% endif %}
  • Prix: {{ article.price }}€ - +
  • Stock: {{ article.stock }}
  • En vente: {{ article.is_sold|yesno|title }}
  • @@ -63,35 +72,35 @@
    -
    -
    -
    -
    +
    +
    +
    +
    -

    Inventaires récents

    -
    - {% include "kfet/article_inventories_snippet.html" with inventoryarts=inventoryarts|slice:5 %} -
    +

    Inventaires récents

    +
    + {% include "kfet/article_inventories_snippet.html" with inventoryarts=inventoryarts|slice:5 %} +
    -
    -
    +
    +
    -

    Derniers prix fournisseurs

    -
    - {% include "kfet/article_suppliers_snippet.html" with supplierarts=supplierarts|slice:5 %} -
    +

    Derniers prix fournisseurs

    +
    + {% include "kfet/article_suppliers_snippet.html" with supplierarts=supplierarts|slice:5 %} +
    -
    -
    -
    -
    +
    +
    +
    +
    -
    -
    -

    Ventes

    -
    -
    -
    +
    +
    +

    Ventes

    +
    +
    +
    @@ -110,26 +119,45 @@
-{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/kfet/urls.py b/kfet/urls.py index 04d1cf82..681b7c31 100644 --- a/kfet/urls.py +++ b/kfet/urls.py @@ -186,6 +186,12 @@ urlpatterns = [ teamkfet_required(views.ArticleUpdate.as_view()), name="kfet.article.update", ), + # Article - Delete + path( + "articles//delete", + views.ArticleDelete.as_view(), + name="kfet.article.delete", + ), # Article - Statistics path( "articles//stat/sales/list", diff --git a/kfet/views.py b/kfet/views.py index d1a40a82..f517bbfe 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -877,6 +877,20 @@ class ArticleUpdate(SuccessMessageMixin, UpdateView): return super().form_valid(form) +class ArticleDelete(PermissionRequiredMixin, DeleteView): + model = Article + success_url = reverse_lazy("kfet.article") + success_message = "Article supprimé avec succès !" + permission_required = "kfet.delete_article" + + def get(self, request, *args, **kwargs): + return redirect("kfet.article.read", self.kwargs.get(self.pk_url_kwarg)) + + def delete(self, request, *args, **kwargs): + messages.success(request, self.success_message) + return super().delete(request, *args, **kwargs) + + # ----- # K-Psul # -----