Commit 5e8a79e3 authored by VAN ZUIJLEN Nils's avatar VAN ZUIJLEN Nils
Browse files

Merge branch 'upgrate-admin-display' into 'master'

Upgrate admin display

See merge request !52
parents 26008a7a 65a142a2
......@@ -26,23 +26,42 @@ window.addEventListener("load", function (e) {
button.addEventListener("click", function() {
let cb = function(data){
let popup = new Popup("Commandes de " + button.closest("article").querySelector("h2").innerText);
let ul = document.createElement('ul');
let orders = data["data"];
let table = document.createElement('table');
table.insertAdjacentHTML("beforeend", "<tr><th>Utilisateur</th><th>Personnalisation</th><th>Opt 1</th><th>Opt 2</th><th>Payé</th><th>Quantité</th></tr>");
for (let i = orders.length - 1; i >= 0; i--) {
let order = orders[i];
let line = document.createElement("tr")
let li = document.createElement('li');
let content = order.user + " : " + order.quantity;
console.log(orders)
content = (order.customization === '') ? content : content + ' ; ' + order.customization;
content = (order.option === '') ? content : content + ' ; ' + order.option;
content = (order.second_option === '') ? content : content + ' ; ' + order.customization;
content = order.paid ? content : content + " ; Impayé";
content = (order.quantity_delivered === 0) ? content : content + " ; " + order.quantity_delivered + " livré(s)"
li.appendChild(document.createTextNode(content));
ul.appendChild(li);
let c1 = document.createElement("td")
let c2 = document.createElement("td")
let c3 = document.createElement("td")
let c4 = document.createElement("td")
let c5 = document.createElement("td")
let c6 = document.createElement("td")
c1.appendChild(document.createTextNode(order.user))
c2.appendChild(document.createTextNode(order.customization))
c3.appendChild(document.createTextNode(order.option))
c4.appendChild(document.createTextNode(order.second_option))
c5.appendChild(document.createTextNode(order.paid))
c6.appendChild(document.createTextNode(order.quantity))
line.appendChild(c1)
line.appendChild(c2)
line.appendChild(c3)
line.appendChild(c4)
line.appendChild(c5)
line.appendChild(c6)
table.appendChild(line);
}
popup.main.appendChild(ul);
popup.main.appendChild(table);
popup.pop();
};
queryJson(document.location, {
......
......@@ -40,6 +40,8 @@
</button>
<button class="delivery_list tooltip see-orders"><i class="fas fa-eye"></i> <span class="tooltiptext">Voir les commandes</span>
</button>
<button class="delivery_list tooltip dl-orders" onclick="window.location.href = '{% url 'boutique:csvexport' pk=item.id %}'"><i class="fas fa-download"></i> <span class="tooltiptext">Voir les commandes</span>
</button>
</div>
</article>
......
......@@ -13,6 +13,7 @@ urlpatterns = [
path("create", views.ItemCreateView.as_view(), name="item_create"),
path("<int:pk>", views.ItemDetailView.as_view(), name="item_detail"),
path("manage", views.ItemManageView.as_view(), name="item_manage"),
path("csvexport/<int:pk>", views.CsvExportView.as_view(), name="csvexport"),
path("sell", views.ItemSellView.as_view(), name="item_sell"),
path("edit/<int:pk>", views.ItemEditView.as_view(), name="item_edit"),
]
......
import json
import csv
from typing import Any
from typing import Dict
from typing import Type
......@@ -29,6 +30,7 @@ from django.views.generic import DetailView
from django.views.generic import ListView
from django.views.generic import RedirectView
from django.views.generic import UpdateView
from django.views.generic import View
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import FormMixin
from django.views.generic.edit import ModelFormMixin
......@@ -159,6 +161,33 @@ class ItemEditView(PermissionRequiredMixin, UpdateView):
return response
class CsvExportView(PermissionRequiredMixin, SingleObjectMixin, View):
model = Item
permission_required = "boutique.management"
object: Item
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
self.object = self.get_object() # type: ignore[assignment]
item_qs = self.get_queryset().filter(id=self.object.id)
item = item_qs.prefetch_related(
"order_items__order__payment", "order_items__order__user__profile"
).get()
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = f'attachment; filename="{self.object.name}.csv"'
writer = csv.writer(response)
writer.writerow(['Username', 'Quantity', 'Paid', 'Customization', 'Option', 'Second Option', 'Quantity delivered'])
for oi in item.order_items.all():
writer.writerow([str(oi.order.user.profile),
oi.quantity,
oi.order.paid,
oi.customization,
oi.option,
oi.second_option,
oi.quantity_delivered])
return response
class ItemManageView(PermissionRequiredMixin, ListView):
template_name = "boutique/item_manage.html"
permission_required = "boutique.management"
......@@ -198,7 +227,6 @@ class ItemManageView(PermissionRequiredMixin, ListView):
],
}
)
else:
raise SuspiciousOperation()
......
Supports Markdown
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