Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deltagerlisten vist for aktiviteten (i Admin) indeholder nu også besked til arrangør, fototilladelse og betalingsinfo #920

Merged
15 changes: 13 additions & 2 deletions members/admin/activity_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
class ActivityParticipantInline(admin.TabularInline):
model = ActivityParticipant
extra = 0
fields = ("person",)
fields = (
"person",
"note",
"photo_permission",
"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 @@ -106,6 +111,12 @@ class ActivityAdmin(admin.ModelAdmin):
"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 @@ -287,26 +286,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
54 changes: 36 additions & 18 deletions members/models/activityparticipant.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ def paid(self):
activityparticipant=self, accepted_at=None
)

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

payment_info_text.short_description = "Betalingsinfo"

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

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

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

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

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;
}
Loading