Skip to content

Commit

Permalink
add label printing for a single lot for #122
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Aug 2, 2024
1 parent f8fc404 commit cce85f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions auctions/templates/view_lot_images.html
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,18 @@ <h5>Exchange info</h5>
</span>
{% if request.user.is_authenticated %}
{% if is_auction_admin %}
<button class="btn btn-primary" hx-get="{% url 'auctionlotadmin' pk=lot.pk %}",
<button class="btn btn-primary me-2" hx-get="{% url 'auctionlotadmin' pk=lot.pk %}",
hx-target="#modals-here",
hx-trigger="click",
_="on htmx:afterOnLoad wait 10ms then add .show to #modal then add .show to #modal-backdrop">Manage this lot</button>
<button class="btn btn-primary" hx-get="{% url 'lot_refund' pk=lot.pk %}",
<button class="btn btn-primary me-2" hx-get="{% url 'lot_refund' pk=lot.pk %}",
hx-target="#modals-here",
hx-trigger="click",
_="on htmx:afterOnLoad wait 10ms then add .show to #modal then add .show to #modal-backdrop">Remove or refund</button>
{% endif %}
{% if is_auction_admin or lot.user.pk == request.user.pk%}
<a class="btn btn-primary me-2" href="{% url 'single_lot_label' pk=lot.pk %}">{% if lot.label_printed%}Reprint label{% else %}Print label{% endif %}</button>
{% endif %}
{% endif %}
{% if request.user.is_superuser %}
<a href="/admin/auctions/lot/{{lot.pk}}/change/" class="btn btn-danger">Admin</a>
Expand Down
1 change: 1 addition & 0 deletions auctions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
path('lots/new/', login_required(views.LotCreateView.as_view()), name='new_lot'),
path('lots/watched/', login_required(views.MyWatched.as_view()), name='watched'),
path('lots/won/', login_required(views.MyWonLots.as_view()), name="won_lots"),
path('lots/print/<int:pk>/', login_required(views.SingleLotLabelView.as_view()), name="single_lot_label"),
path('selling', login_required(views.MyLots.as_view()), name='selling'),
path('lots/all/', views.AllLots.as_view(), name='allLots'),
path('lots/user/', views.LotsByUser.as_view(), name="user_lots"),
Expand Down
20 changes: 20 additions & 0 deletions auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3704,6 +3704,26 @@ class UnprintedLotLabelsView(LotLabelView):
def get_queryset(self):
return self.tos.unprinted_labels_qs

class SingleLotLabelView(LotLabelView):
"""Reprint labels for just one lot"""

def get_queryset(self):
return Lot.objects.filter(pk=self.lot.pk)

def dispatch(self, request, *args, **kwargs):
self.lot = get_object_or_404(Lot, pk=kwargs.pop('pk'), is_deleted=False)
if self.lot.auctiontos_seller and self.lot.auctiontos_seller.user is not request.user:
self.auction = self.lot.auctiontos_seller.auction
if not self.is_auction_admin:
messages.error(request, "You can't print lables for other people's lots unless you are an admin")
return redirect("/")
if not self.lot.auctiontos_seller:
if self.lot.user and self.lot.user is not request.user:
messages.error(request, "You can only print labels for your own lots")
return redirect("/")
# super() would try to find an auction
return View.dispatch(self, request, *args, **kwargs)

@login_required
def getClubs(request):
if request.method == 'POST':
Expand Down

0 comments on commit cce85f2

Please sign in to comment.