Skip to content

Commit

Permalink
add dropdown menu to lot admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Aug 22, 2024
1 parent 23ccfbe commit 2f856cd
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 8 deletions.
3 changes: 2 additions & 1 deletion auctions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ class UserInline(admin.TabularInline):

class ClubAdmin(admin.ModelAdmin):
model = Club
list_display = ("name", "contact_email", "date_contacted")
list_display = ("name", "contact_email", "date_contacted_for_in_person_auctions")
search_fields = ("name",'abbreviation', 'contact_email', 'homepage',)
list_filter = (
"active",
("date_contacted", admin.EmptyFieldListFilter),
("date_contacted_for_in_person_auctions", admin.EmptyFieldListFilter),
("contact_email", admin.EmptyFieldListFilter),
("notes", admin.EmptyFieldListFilter),
("latitude", admin.EmptyFieldListFilter),
Expand Down
4 changes: 2 additions & 2 deletions auctions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,9 @@ def clean(self):
def __init__(self, *args, **kwargs):
self.lot = kwargs.pop('lot')
super().__init__(*args, **kwargs)
if self.lot.active or not self.lot.winning_price:
if not self.lot.sold:
self.fields['partial_refund_percent'].widget = HiddenInput()
if self.lot.winning_price:
else:
self.fields['banned'].widget = HiddenInput()
save_button_html = f'<button hx-post="{reverse("lot_refund", kwargs={"pk":self.lot.pk})}" hx-target="#modals-here" type="submit" class="btn bg-success float-right ms-2">Save</button>'
self.helper = FormHelper()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.8 on 2024-08-22 13:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('auctions', '0141_auctiontos_email_address_status'),
]

operations = [
migrations.AddField(
model_name='club',
name='date_contacted_for_in_person_auctions',
field=models.DateTimeField(blank=True, null=True),
),
]
1 change: 1 addition & 0 deletions auctions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ class Club(models.Model):
facebook_page = models.CharField(max_length=255, blank=True, null=True)
contact_email = models.CharField(max_length=255, blank=True, null=True)
date_contacted = models.DateTimeField(blank=True, null=True)
date_contacted_for_in_person_auctions = models.DateTimeField(blank=True, null=True)
notes = models.CharField(max_length=300, blank=True, null=True)
notes.help_text = "Only visible in the admin site, never made public"
interests = models.ManyToManyField(GeneralInterest, blank=True)
Expand Down
16 changes: 15 additions & 1 deletion auctions/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,21 @@ class LotHTMxTable(tables.Table):
lot_number = tables.Column(accessor='lot_number_display', verbose_name="Lot number", orderable=False)

def render_lot_name(self, value, record):
result = f"<a href='' hx-noget hx-get='/api/lot/{record.pk}' hx-target='#modals-here' hx-trigger='click'><i class='bi bi-calendar-fill me-1'></i>{value}</a> (<a href='{record.lot_link}?src=admin'>View</a>)"
result = f"""
<a href='' hx-noget hx-get='/api/lot/{record.pk}' hx-target='#modals-here' hx-trigger='click'><i class='bi bi-calendar-fill me-1'></i>{value}</a>
<button type="button" class="btn btn-sm bg-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
</button>
<div class="dropdown-menu">
<div><a href='{record.lot_link}?src=admin'><i class="bi bi-calendar ms-1 me-1"></i>Lot page</a></div>
<div><a href='#' hx-get="{reverse('lot_refund', kwargs={'pk':record.pk})}",
hx-target="#modals-here",
hx-trigger="click",
_="on htmx:afterOnLoad wait 10ms then add .show to #modal then add .show to #modal-backdrop"><i class="bi bi-calendar-x ms-1 me-1"></i>Remove or refund</a></div>
<div><a class="" href="{reverse("single_lot_label", kwargs={"pk": record.pk})}"><i class="bi bi-tag ms-1 me-1"></i>{"Reprint label" if record.label_printed else "Print label"}</a></div>
</div>
"""
if record.banned:
result += '<span class="badge bg-danger">Removed</span>'
return mark_safe(result)

class Meta:
Expand Down
2 changes: 1 addition & 1 deletion auctions/templates/auctions/auction_lot_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% block content %}
{% include 'auction_ribbon.html' %}
<small>This is a list of items for sale in your auction. Click a lot name to edit it. To add new lots, go to the <a href="{% url 'auction_tos_list' slug=auction.slug %}">users page</a> and click add lots under the appropriate user.<br></small>
<a class='btn btn-sm btn-primary' href="{{ auction.set_lot_winners_link }}"><i class="bi bi-calendar-check"></i> Set lot winners</a>
{% if not auction.is_online %}<a class='btn btn-sm btn-primary' href="{{ auction.set_lot_winners_link }}"><i class="bi bi-calendar-check"></i> Set lot winners</a>{% endif %}
<a id='all_lot_list' href="{% url 'lot_list' slug=auction.slug %}" class="btn btn-sm mt-2 mb-2 btn-primary"><i class="bi bi-download"></i> Export CSV</a>
<a href="{{auction.view_lot_link}}" class="btn btn-sm btn-primary"><i class="bi bi-calendar"></i> See lots as users see them</a>

Expand Down
2 changes: 1 addition & 1 deletion auctions/templates/user_labels.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<li>Cut them out with scissors</li>
<li>Use packing tape to attach them to your lots (make sure your bags are dry!)</li>
</ol>
<p>If you want to print on self-adhesive labels, search for <a href="https://www.google.com/search?q=Avery 5160 labels">small labels</a> or <a href="https://www.google.com/search?q=Avery 18262 labels">large labels</a>, and make sure to print using a laser jet printer (inkjet runs when it's wet).</p>
<p>If you want to print on self-adhesive labels, search for <a href="https://www.google.com/search?q=Avery 5160 labels">small labels</a> or <a href="https://www.google.com/search?q=Avery 18262 labels">large labels</a>, and make sure to print using a laser printer (inkjet runs when it's wet).</p>
{% crispy form form.helper %}
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion auctions/templates/view_lot_images.html
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ <h5>Exchange info</h5>
{% if lot.can_be_edited %}
href="{% url 'edit_lot' pk=lot.pk %}"
{% else %}
href="javascript:void(0);" data-toggle="tooltip" data-placement="top" title="{{ lot.cannot_edit_reason }}"
href="javascript:void(0);" data-toggle="tooltip" data-placement="top" title="{{ lot.cannot_be_edited_reason }}"
{% endif %}
class="text-dark btn btn-warning"><i class="bi bi-gear-fill"></i> Edit lot</a>
<a
Expand Down
2 changes: 1 addition & 1 deletion auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3901,7 +3901,7 @@ def get_form_kwargs(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['lot'] = self.lot
if self.lot.active or not self.lot.winning_price:
if not self.lot.sold:
context['tooltip'] = "This lot has not sold, there's nothing to refund. If there's a problem with this lot, remove it."
else:
# if a refund has already been issued for this lot, we need to calculate how much is unpaid by temporarily removing it
Expand Down

0 comments on commit 2f856cd

Please sign in to comment.