Skip to content

Commit

Permalink
allow admins to print all unprinted labels for #122
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Aug 2, 2024
1 parent cce85f2 commit e4aff72
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
12 changes: 11 additions & 1 deletion auctions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,17 @@ def total_unsold_lots(self):
def total_lots(self):
return self.lots_qs.exclude(banned=True).count()

@property
def labels_qs(self):
lots = self.lots_qs.exclude(banned=True)
if self.is_online:
lots = lots.filter(auctiontos_winner__isnull=False, winning_price__isnull=False)
return lots

@property
def unprinted_labels_qs(self):
return self.labels_qs.exclude(label_printed=True)

@property
def percent_unsold_lots(self):
try:
Expand Down Expand Up @@ -1119,7 +1130,6 @@ def print_invoice_link_html(self):
if self.unprinted_label_count and self.unprinted_label_count != self.print_labels_qs.count():
result += f"""
<button type="button" class="btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<a href='{unprinted_url}'>Print only {self.unprinted_label_count} unprinted labels</a>
Expand Down
21 changes: 21 additions & 0 deletions auctions/templates/auction_printing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "base.html" %}
{% block title %}Print labels for {{ auction }}{% endblock %}
{% load static %}
{% block content %}
{% include 'auction_ribbon.html' %}
<p><small>This page will allow you to print all unprinted labels for your auction.
You generally don't need to use this page.
<br>Some tips:<br>
<ul>
<li>Print all labels, or all unprinted labels, for an individual user on the <a href="/auctions/{{auction.slug}}/users">users</a> tab</li>
<li>Encourage users to pre-register lots and print their own labels. This saves you paper and a lot of time at the registration desk.</li>
<li>Reprint damaged labels by viewing the lot's page.</li>
</ul>
</small></p>
<p>You've printed {{ printed_labels_count }} out of {{ all_labels_count }} labels in your auction. Note that labels won't be printed for removed lots, or for unsold lots in an online auction.</p>

<br>
<div><a href='{% url "auction_printing_pdf" slug=auction.slug %}' class="btn btn-primary">Print {{ unprinted_label_count}} labels</a></div>
{% endblock %}
{% block extra_js %}
{% endblock %}
1 change: 1 addition & 0 deletions auctions/templates/auction_ribbon.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ <h3>{{auction}}</h3>
<a class="dropdown-item" href="/auctions/{{auction.slug}}/chat/">Chat messages</a>
<a class="dropdown-item" href="/auctions/new?copy={{auction.slug}}">Copy to new auction</a>
<a class="dropdown-item" href="/auctions/{{auction.slug}}/stats/">Stats</a>
<a class="dropdown-item" href='{% url "auction_printing" slug=auction.slug %}'>Print unprinted labels</a>
<a class="dropdown-item" href="/auctions/{{auction.slug}}/delete/">Delete auction</a>
</ul>
</li>
Expand Down
2 changes: 2 additions & 0 deletions auctions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
path('auctions/<slug:slug>/lots/', views.AuctionLots.as_view(), name="auction_lot_list"),
path('auctions/<slug:slug>/stats/', login_required(views.AuctionStats.as_view())),
path('auctions/<slug:slug>/report/', views.auctionReport, name="user_list"),
path('auctions/<slug:slug>/print/', views.AuctionBulkPrinting.as_view(), name="auction_printing"),
path('auctions/<slug:slug>/print/pdf', views.AuctionBulkPrintingPDF.as_view(), name="auction_printing_pdf"),
path('selling/csv/', views.my_lot_report, name="my_lot_report"),
path('auctions/<slug:slug>/lotlist/', views.auctionLotList, name="lot_list"),
path('auctions/<slug:slug>/delete/', views.AuctionDelete.as_view()),
Expand Down
32 changes: 32 additions & 0 deletions auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4801,6 +4801,38 @@ def get_data(self):
data.append({'x': i, 'y':minutes})
return [data]

class AuctionBulkPrinting(DetailView, AuctionPermissionsMixin):
model = Auction
template_name = "auction_printing.html"

def dispatch(self, request, *args, **kwargs):
self.auction = self.get_object()
self.is_auction_admin
return super().dispatch(request, *args, **kwargs)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['all_labels_count'] = self.auction.labels_qs.count()
context['unprinted_label_count'] = self.auction.unprinted_labels_qs.count()
context['printed_labels_count'] = context['all_labels_count'] - context['unprinted_label_count']
return context

class AuctionBulkPrintingPDF(LotLabelView):
"""Only unprinted labels, for all users, in a given auction"""
allow_non_admins = False

def get_queryset(self):
return self.auction.unprinted_labels_qs

def dispatch(self, request, *args, **kwargs):
# check to make sure the user has permission to view this invoice
self.auction = Auction.objects.exclude(is_deleted=True).filter(slug=kwargs['slug']).first()
self.is_auction_admin
if not self.get_queryset():
messages.error(request, "All labels have already been printed")
return redirect(self.auction.get_absolute_url())
return View.dispatch(self, request, *args, **kwargs)

class PickupLocationsIncoming(View, AuctionPermissionsMixin):
"""All lots destined for this location"""
def dispatch(self, request, *args, **kwargs):
Expand Down

0 comments on commit e4aff72

Please sign in to comment.