Skip to content

Commit

Permalink
fix #166
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Aug 18, 2024
1 parent a63da3c commit 3050977
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 29 deletions.
2 changes: 2 additions & 0 deletions auctions/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def generic(self, qs, value):
'unseen': {'auctiontos__opened': False},
'no bid': {'bidding_allowed': False},
'no sell': {'selling_allowed': False},
'email good': {'email_address_status': 'BAD'},
'email bad': {'email_address_status': 'VALID'},
}

# Apply filters based on patterns
Expand Down
41 changes: 18 additions & 23 deletions auctions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,15 @@ def check_number_in_auction(number):
self.bidder_number = 999
if str(self.memo) == "None":
self.memo = ""
# update the email address as appropriate
if self.email and self.email_address_status == "UNKNOWN":
existing_instance = AuctionTOS.objects.filter(
email=self.email,
auction__created_by=self.auction.created_by,
email_address_status__ne="UNKNOWN"
).order_by('-createdon').first()
if existing_instance:
self.email_address_status = existing_instance.email_address_status
super().save(*args, **kwargs)

@property
Expand Down Expand Up @@ -3712,30 +3721,16 @@ def bounce_handler(sender, mail_obj, bounce_obj, raw_message, *args, **kwargs):
# you can then use the message ID and/or recipient_list(email address) to identify any problematic email messages that you have sent
#message_id = mail_obj['messageId']
recipient_list = mail_obj['destination']
print("Mail bounced")
print(mail_obj)
try:
email = recipient_list[0]
print(email)
auctiontos = AuctionTOS.objects.filter(email=email)
for tos in auctiontos:
tos.email_address_status="BAD"
tos.save()
except Exception as e:
print(e)
print(recipient_list)
email = recipient_list[0]
auctiontos = AuctionTOS.objects.filter(email=email)
for tos in auctiontos:
tos.email_address_status="BAD"
tos.save()

@receiver(complaint_received)
def complaint_handler(sender, mail_obj, complaint_obj, raw_message, *args, **kwargs):
recipient_list = mail_obj['destination']
print("Mail complaint")
print(mail_obj)
try:
email = recipient_list[0]
print(email)
#user = User.objects.filter(email=email).first()
#if user:
# user.userdata.unsubscribe_from_all
except Exception as e:
print(e)
print(recipient_list)
email = recipient_list[0]
user = User.objects.filter(email=email).first()
if user:
user.userdata.unsubscribe_from_all
6 changes: 4 additions & 2 deletions auctions/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ def render_name(self, value, record):
def render_email(self, value, record):
email_string = f'<a href="mailto:{value}">{value}</a>'
#email_string = value
if record.user:
email_string += "<i class='bi bi-check me-1' title='Verified email'></i>"
if record.email_address_status == "BAD":
email_string += "<i class='bi bi-envelope-exclamation-fill text-danger ms-1' title='Unable to send email to this address'></i>"
if record.email_address_status == "VALID":
email_string += "<i class='bi bi-envelope-check-fill ms-1' title='Verified email'></i>"
return mark_safe(email_string)

class Meta:
Expand Down
8 changes: 7 additions & 1 deletion auctions/templates/auction_users.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
{% if auction.is_online %}
<label class="dropdown-item ">
<input type="checkbox" class="invoice_filter" id="checkbox_no_bid"> <i class="bi bi-exclamation-octagon-fill"></i> Can't bid
<input type="checkbox" class="invoice_filter" id="checkbox_no_bid"> <i class="bi bi-cash-coin"></i> Can't bid
</label>
{% endif %}
<label class="dropdown-item ">
<input type="checkbox" class="invoice_filter" id="checkbox_no_sell"> <i class="bi bi-exclamation-octagon-fill"></i> Can't sell
</label>
<label class="dropdown-item ">
<input type="checkbox" class="invoice_filter" id="checkbox_email_good"> <i class="bi bi-envelope-exclamation-fill"></i> Only invalid email
</label>
<label class="dropdown-item ">
<input type="checkbox" class="invoice_filter" id="checkbox_email_bad"> <i class="bi bi-envelope-check-fill"></i> Only verified email
</label>
<span class="text-muted dropdown-item"><small>Users with an invoice that is:</small></span>
<label class="dropdown-item ">
<input type="checkbox" class="invoice_filter" id="checkbox_open"> <i class="bi bi-bag"></i> Open
Expand Down
11 changes: 8 additions & 3 deletions auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ def userReport(request):
found = []
writer.writerow(['Name', 'Email', 'Phone'])
auctions = Auction.objects.filter(Q(created_by=request.user)|Q(auctiontos__is_admin=True, auctiontos__user=request.user))
users = AuctionTOS.objects.filter(auction__in=auctions)
users = AuctionTOS.objects.filter(auction__in=auctions).exclude(email_address_status="BAD")
for user in users:
if user.email not in found:
writer.writerow([user.name, user.email, user.phone_as_string])
Expand Down Expand Up @@ -3123,6 +3123,9 @@ def post(self, request, *args, **kwargs):
obj.time_spent_reading_rules = form.cleaned_data['time_spent_reading_rules']
# even if an auctiontos was originally manually added, if the user clicked join, mark them as not manually added
obj.manually_added = False
if obj.email_address_status == "UNKNOWN":
# if it bounced in the past, the user may have a full inbox or something
obj.email_address_status = "VALID"
# fill out some information in the tos if not already filled out
if not obj.name:
obj.name = self.request.user.first_name + " " + self.request.user.last_name
Expand Down Expand Up @@ -3266,8 +3269,8 @@ def get_queryset(self):
qs = qs.annotate(
distance=Subquery(closest_pickup_location_subquery)
)
#if self.request.user.is_superuser:
# return qs
if self.request.user.is_superuser:
return qs
if not self.request.user.is_authenticated:
return qs.filter(standard_filter)
qs = qs.filter(Q(auctiontos__user=self.request.user)|
Expand Down Expand Up @@ -3512,6 +3515,8 @@ def dispatch(self, request, *args, **kwargs):
invoice = self.get_object()
invoice.opened = True
invoice.save()
invoice.auctiontos_user.email_address_status = "VALID"
invoice.auctiontos_user.save()
return super().dispatch(request, *args, **kwargs)

class LotLabelView(View, AuctionPermissionsMixin):
Expand Down

0 comments on commit 3050977

Please sign in to comment.