Skip to content

Commit

Permalink
Merge pull request #275 from iragm/november-2024-fixes
Browse files Browse the repository at this point in the history
November 2024 fixes
  • Loading branch information
iragm authored Nov 22, 2024
2 parents d56833b + 100b115 commit 8cddd8d
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 36 deletions.
11 changes: 8 additions & 3 deletions auctions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,10 @@ def total_unsold_lots(self):
def total_lots(self):
return self.lots_qs.exclude(banned=True).count()

@property
def number_of_lots_with_scanned_qr(self):
return self.lots_qs.filter(pageview__source__icontains="qr", auction__pk=self.pk).distinct().count()

@property
def labels_qs(self):
lots = self.lots_qs.exclude(banned=True)
Expand All @@ -1110,7 +1114,7 @@ def percent_unsold_lots(self):

@property
def template_lot_link(self):
"""Not directly used in templates, use template_lot_link_first_column and template_lot_link_seperate_column instead"""
"""Not directly used in templates, use template_lot_link_first_column and template_lot_link_separate_column instead"""
if timezone.now() > self.lot_submission_start_date:
result = f"<a href='{ self.view_lot_link }'>View lots</a>"
else:
Expand All @@ -1123,7 +1127,7 @@ def template_lot_link_first_column(self):
return mark_safe(f'<small><span class="d-md-none"><br>{self.template_lot_link}</span></small>')

@property
def template_lot_link_seperate_column(self):
def template_lot_link_separate_column(self):
"""Shown on big screens only"""
return mark_safe(f'<span class="d-none d-md-inline">{self.template_lot_link}</span>')

Expand Down Expand Up @@ -2971,7 +2975,8 @@ def full_lot_link(self):
@property
def qr_code(self):
"""Full domain name URL used to for QR codes"""
return f"{self.full_lot_link}?src=qr"
current_site = Site.objects.get_current()
return f"https://{current_site.domain}{reverse('lot_by_pk_qr', kwargs={'pk': self.pk})}"

@property
def seller_string(self):
Expand Down
11 changes: 5 additions & 6 deletions auctions/tables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import django_tables2 as tables
from django.urls import reverse
from django.utils import formats
from django.utils.safestring import mark_safe

from .models import Auction, AuctionTOS, Lot
Expand Down Expand Up @@ -171,17 +170,17 @@ class AuctionHTMxTable(tables.Table):
hide_string = "d-md-table-cell d-none"

auction = tables.Column(accessor="title", verbose_name="Auction")
date = tables.Column(accessor="date_start", verbose_name="Status")
date = tables.Column(accessor="date_start", verbose_name="Starts")
lots = tables.Column(
accessor="template_lot_link_seperate_column",
accessor="template_lot_link_separate_column",
verbose_name="Lots",
orderable=False,
attrs={"th": {"class": hide_string}, "cell": {"class": hide_string}},
)

def render_date(self, value, record):
localized_date = formats.date_format(record.template_date_timestamp, use_l10n=True)
return mark_safe(f"{record.template_status}{localized_date}{record.ended_badge}")
# def render_date(self, value, record):
# localized_date = formats.date_format(record.template_date_timestamp, use_l10n=True)
# return mark_safe(f"{record.template_status}{localized_date}{record.ended_badge}")

def render_auction(self, value, record):
auction = record
Expand Down
2 changes: 1 addition & 1 deletion auctions/templates/all_lots.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h3>
{% endif %}
{% if view == "mywonlots" %}
Lots you've won
<br><a href="{% url 'my_won_lot_csv' %}" class="btn btn-sm bg-primary"><i class="bi bi-download"></i>Export CSV</a>
<br><a href="{% url 'my_won_lot_csv' %}" class="btn btn-sm bg-primary"><i class="bi bi-download me-1"></i>Export my won lots CSV</a>

{% endif %}
{% endif %}</h3>
Expand Down
4 changes: 4 additions & 0 deletions auctions/templates/auction_stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ <h4>User engagement</h4>
<tr>
<td>Seller payout</td><td>${{ auction.total_to_sellers|floatformat:2 }}</td>
</tr>
<tr>
<td>Lots with a scanned QR code</td><td>{{ auction.number_of_lots_with_scanned_qr }}</td>
</tr>

</tbody>
</table>

Expand Down
5 changes: 4 additions & 1 deletion auctions/templates/auction_users.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
{% for chunk in auction.paypal_invoice_chunks %}
<a href="{% url 'paypal_csv' slug=auction.slug chunk=chunk %}" class="dropdown-item"><i class="bi bi-paypal"></i> PayPal Invoice CSV {% if auction.paypal_invoice_chunks|length > 1 %} #{{chunk}}{% endif %}</a>
{% endfor %}
{% if not auction.paypal_invoice_chunks|length %}<span class="text-muted dropdown-item"><i class="bi bi-paypal"></i> No PayPal invoices</span>{% endif %}
{% if not auction.paypal_invoice_chunks|length %}<span class="text-muted dropdown-item"><i class="bi bi-paypal"></i> No PayPal invoices</span>
{% else %}
<a href="https://www.paypal.com/invoice/batch" class="dropdown-item"><i class="bi bi-paypal"></i> Paypal Batch Invoice Upload</span>
{% endif %}
<a href="/blog/online-payments-suck/" class="dropdown-item"><i class="bi bi-info-circle"></i> PayPal invoice help</a>
</div>
</span>
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 @@ -8,7 +8,7 @@
{% include 'auction_ribbon.html' %}
<small>This is a list of items for sale in your auction. Click a lot name to edit it. {% if auction.is_online %}You probably don't need to use this page; users will add their own lots to this auction{% else %}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.{% endif %}<br></small>
{% 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 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 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 lot CSV</a>
<a href="{{auction.view_lot_link}}" class="btn btn-sm btn-primary"><i class="bi bi-calendar"></i> See user view</a>

<form class="col-sm-12 mt-2">
Expand Down
37 changes: 35 additions & 2 deletions auctions/templates/auctions/dynamic_set_lot_winner.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@

{% block extra_js %}
<script>
let tooltipTimeout;
function initializeTooltipWithTimeout() {
if (tooltipTimeout) {
clearTimeout(tooltipTimeout);
}
tooltipTimeout = setTimeout(() => {
const tooltipTriggerElement = document.getElementById('more_save_options_tooltip');
if (tooltipTriggerElement) {
const existingTooltip = bootstrap.Tooltip.getInstance(tooltipTriggerElement);

if (!existingTooltip) {
tooltipTriggerElement.setAttribute('title', 'Ignore errors and save here');
const tooltip = new bootstrap.Tooltip(tooltipTriggerElement);
tooltip.show();
}
}
}, 100);
}

function removeTooltip() {
const tooltipTriggerElement = document.getElementById('more_save_options_tooltip');
if (tooltipTriggerElement) {
const existingTooltip = bootstrap.Tooltip.getInstance(tooltipTriggerElement);
if (existingTooltip) {
existingTooltip.dispose();
}
tooltipTriggerElement.removeAttribute('title');
}
}


function undoSellLot() {
let data = {
lot_number: $("#last_sold_lot_number").text()
Expand All @@ -28,6 +59,7 @@
$(".form-control").removeClass("is-invalid is-valid");
let fields = ['price', 'winner', 'lot']
if (response.success_message) {
removeTooltip()
fields.forEach(function(field) {
$("#" + field).val('');
})
Expand All @@ -46,6 +78,7 @@
if (response[field] === "valid") {
$("#" + field).addClass("is-valid");
} else if (response[field]) {
initializeTooltipWithTimeout();
$("#" + field).addClass("is-invalid");
$("#" + field).siblings(".invalid-tooltip").text(response[field]);
}
Expand Down Expand Up @@ -185,8 +218,8 @@
<div class="btn-group" role="group" aria-label="Save">
<button type="submit" class="btn bg-success text-black">Save</button>
<div class="btn-group" role="group">
<button id="more_safe_optins" type="button" class="btn btn-success dropdown-toggle text-black" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></button>
<div class="dropdown-menu" aria-labelledby="more_safe_optins">
<button id="more_save_options" type="button" class="btn btn-success dropdown-toggle text-black" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></button><span id="more_save_options_tooltip"></span>
<div class="dropdown-menu" aria-labelledby="more_save_options">
<a class="dropdown-item" href='javascript:void(0)' onclick="sendFormData('force_save')">Ignore errors and save</a>
<a id='sell_to_online_high_bidder' class="d-none dropdown-item" onclick="sendFormData('to_online_high_bidder')" href='javascript:void(0)'></a>
<a class="dropdown-item" href='javascript:void(0)' onclick="sendFormData('end_unsold')">End lot unsold</a>
Expand Down
2 changes: 1 addition & 1 deletion auctions/templates/auctions/lot_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
{# The actual table #}
{% render_table table %}
<div id="modals-here"></div>
<a href="{% url 'my_lot_report' %}" class="btn btn-primary"><i class="bi bi-download"></i> Export CSV</a>
<a href="{% url 'my_lot_report' %}" class="btn btn-primary"><i class="bi bi-download"></i> Export my sold lots CSV</a>
{% endblock %}
13 changes: 0 additions & 13 deletions auctions/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,6 @@ <h3>Admin Dashboard</h3>
<td> {{ bidders_last_30_days }}
</td>
</tr>
<tr>
<td>User with printed labels</td>
<td> {{ users_with_printed_labels }}
</td>
</tr>
<tr>
<td>Label preset usage:</td>
<td>
{% for preset in preset_counts %}
{{ preset.preset }}: {{ preset.count }}<br>
{% endfor %}
</td>
</tr>
<tr>
<td>users who have used search:</td>
<td> {{ users_with_search_history }}
Expand Down
1 change: 1 addition & 0 deletions auctions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
),
path("lots/recommended/", views.AllRecommendedLots.as_view()),
path("lots/", views.AllLots.as_view(), name="allLots"),
path("qr/<int:pk>/", views.LotQRView.as_view(), name="lot_by_pk_qr"),
path("lots/<int:pk>/", views.ViewLot.as_view(), name="lot_by_pk"),
path(
"lots/edit/<int:pk>/",
Expand Down
24 changes: 16 additions & 8 deletions auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,14 @@ def get_queryset(self):
return qs.order_by("-name")


class LotQRView(RedirectView):
def get_redirect_url(self, *args, **kwargs):
lot = Lot.objects.filter(pk=self.kwargs["pk"]).first()
if lot:
return f"{lot.lot_link}?src=qr"
return None


class AllRecommendedLots(TemplateView):
"""
Show all recommended lots as a standalone page
Expand Down Expand Up @@ -5486,14 +5494,14 @@ def get_context_data(self, **kwargs):
context["online_auction_lots_ending"] = Lot.objects.filter(
is_deleted=False, date_end__lte=timeframe, date_end__gte=timezone.now()
).count()
users_with_printed_labels = User.objects.filter(lot__label_printed=True).distinct()
context["users_with_printed_labels"] = users_with_printed_labels.count()
context["preset_counts"] = (
UserLabelPrefs.objects.filter(user__in=users_with_printed_labels)
.values("preset")
.annotate(count=Count("user"))
.order_by("-count")
)
# users_with_printed_labels = User.objects.filter(lot__label_printed=True).distinct()
# context["users_with_printed_labels"] = users_with_printed_labels.count()
# context["preset_counts"] = (
# UserLabelPrefs.objects.filter(user__in=users_with_printed_labels)
# .values("preset")
# .annotate(count=Count("user"))
# .order_by("-count")
# )
return context


Expand Down

0 comments on commit 8cddd8d

Please sign in to comment.