Skip to content

Commit

Permalink
Rettede payment_info og styling for deltager liste for aktivitet
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewel committed Jul 12, 2023
1 parent d256f04 commit f09daf4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 43 deletions.
8 changes: 7 additions & 1 deletion members/admin/activity_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ActivityParticipantInline(admin.TabularInline):
"payment_info_text",
)
readonly_fields = fields
raw_id_fields = ("person",)
can_delete = False

def get_queryset(self, request):
return ActivityParticipant.objects.all()
Expand Down Expand Up @@ -119,6 +119,12 @@ def changelist_view(self, request, extra_context=None):
"activitytype",
)
save_as = True

class Media:
# Remove title for each record ?
# see : https://stackoverflow.com/questions/41376406/remove-title-from-tabularinline-in-admin
css = {"all": ("members/css/custom_admin.css",)} # Include extra css

inlines = [ActivityParticipantInline]

def start_end(self, obj):
Expand Down
19 changes: 2 additions & 17 deletions members/admin/activityparticipant_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.http import HttpResponse
from django.urls import reverse
from django.utils import timezone
from django.utils.html import format_html
from django.utils.safestring import mark_safe

from members.models import (
Expand Down Expand Up @@ -290,26 +289,12 @@ def activity_department_link(self, item):
activity_department_link.admin_order_field = "activity__department__name"

def activity_payment_info_txt(self, item):
if item.activity.price_in_dkk == 0.00:
return "Gratis"
else:
try:
return item.payment_info(False)
except Exception:
return "Andet er aftalt"
return item.payment_info(False)

activity_payment_info_txt.short_description = "Betalingsinfo"

def activity_payment_info_html(self, item):
if item.activity.price_in_dkk == 0.00:
return format_html("<span style='color:green'><b>Gratis</b></span>")
else:
try:
return item.payment_info(True)
except Exception:
return format_html(
"<span style='color:red'><b>Andet er aftalt</b></span>"
)
return item.payment_info(True)

activity_payment_info_html.short_description = "Betalingsinfo"

Expand Down
57 changes: 32 additions & 25 deletions members/models/activityparticipant.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,11 @@ def paid(self):
)

def payment_info_text(self):
if self.activity.price_in_dkk == 0.00:
return "Gratis"
else:
try:
return self.payment_info(False)
except Exception:
return "Andet er aftalt"
return self.payment_info(False)

payment_info_text.short_description = "Betalingsinfo"

def payment_info(self, format_as_html: bool):
payment = members.models.payment.Payment.objects.get(activityparticipant=self)

if format_as_html:
html_error_pre = "<span style='color:red'><b>"
html_warn_pre = "<span style='color:blue'><b>"
Expand All @@ -82,37 +74,52 @@ def payment_info(self, format_as_html: bool):
html_post = ""

result_string = ""
paid_kr = f"{payment.amount_ore / 100}"

try:
payment = members.models.payment.Payment.objects.get(
activityparticipant=self
)
except Exception:
if format_as_html:
result_string = format_html(
f"{html_error_pre}Andet er aftalt.{html_post} "
)
else:
result_string = "Andet er aftalt. "
return result_string

# Checking for price = 0 before checking for payment
if self.activity.price_in_dkk == 0:
result_string = f"{html_good_pre}Gratis.{html_post} "

paid_kr = f"{payment.amount_ore / 100:.2f}"
if payment.refunded_at is not None:
result_string = f"{html_warn_pre}Refunderet{html_post}:{self.utc_to_local_ymdhm(payment.refunded_at)}. "
result_string += f"{html_warn_pre}Refunderet{html_post}:{self.utc_to_local_ymdhm(payment.refunded_at)}. "
if payment.confirmed_at is not None:
result_string += f"Betalt {paid_kr}kr: {self.utc_to_local_ymdhm(payment.confirmed_at)}. "
else:
result_string += (
f"(Oprettet:{self.utc_to_local_ymdhm(payment.added_at)})"
)
elif payment.rejected_at is not None:
result_string = f"{html_error_pre}Afvist:{html_post}{self.utc_to_local_ymdhm(payment.rejected_at)}. "
result_string += f"{html_error_pre}Afvist:{html_post}{self.utc_to_local_ymdhm(payment.rejected_at)}. "
result_string += f"(Oprettet:{self.utc_to_local_ymdhm(payment.added_at)})"
elif payment.cancelled_at is not None:
result_string = f"{html_error_pre}Cancelled:{html_post}{self.utc_to_local_ymdhm(payment.cancelled_at)}. "
result_string += f"{html_error_pre}Cancelled:{html_post}{self.utc_to_local_ymdhm(payment.cancelled_at)}. "
result_string += f"(Oprettet:{self.utc_to_local_ymdhm(payment.added_at)})"
else:
if payment.confirmed_at is not None:
result_string = f"{html_good_pre}Betalt {paid_kr}kr:{html_post} {self.utc_to_local_ymdhm(payment.confirmed_at)}. "
result_string += f"{html_good_pre}Betalt {paid_kr}kr:{html_post} {self.utc_to_local_ymdhm(payment.confirmed_at)}. "
else:
if payment.activity.price_in_dkk == 0:
result_string = f"{html_good_pre}Gratis.{html_post} "
if (
payment.accepted_at is not None
and self.activity.start_date.year > timezone.now().year
):
result_string += f"{html_warn_pre}Betalingsdato:{str(self.activity.start_date.year)}-01-01{html_post} "
else:
if (
payment.accepted_at is not None
and self.activity.start_date.year > timezone.now().year
):
result_string = f"{html_warn_pre}Betalingsdato:{str(self.activity.start_date.year)}-01-01{html_post} "
else:
result_string = (
f"{html_error_pre}Betaling er ikke gennemført{html_post} "
)
result_string += (
f"{html_error_pre}Betaling er ikke gennemført{html_post} "
)

result_string += f"(Oprettet:{self.utc_to_local_ymdhm(payment.added_at)})"
if format_as_html:
Expand Down
7 changes: 7 additions & 0 deletions members/static/members/css/custom_admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.inline-group .tabular tr.has_original td {
padding-top: 8px;
}

.original {
display: none;
}

0 comments on commit f09daf4

Please sign in to comment.