diff --git a/members/admin/activity_admin.py b/members/admin/activity_admin.py
index 40c8a0e8..7b6fdc59 100644
--- a/members/admin/activity_admin.py
+++ b/members/admin/activity_admin.py
@@ -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()
@@ -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):
diff --git a/members/admin/activityparticipant_admin.py b/members/admin/activityparticipant_admin.py
index 87dd0b4f..fb68f83e 100644
--- a/members/admin/activityparticipant_admin.py
+++ b/members/admin/activityparticipant_admin.py
@@ -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 (
@@ -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("Gratis")
- else:
- try:
- return item.payment_info(True)
- except Exception:
- return format_html(
- "Andet er aftalt"
- )
+ return item.payment_info(True)
activity_payment_info_html.short_description = "Betalingsinfo"
diff --git a/members/models/activityparticipant.py b/members/models/activityparticipant.py
index b34089b7..2c266396 100644
--- a/members/models/activityparticipant.py
+++ b/members/models/activityparticipant.py
@@ -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 = ""
html_warn_pre = ""
@@ -71,9 +74,27 @@ 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:
@@ -81,27 +102,24 @@ def payment_info(self, format_as_html: bool):
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:
diff --git a/members/static/members/css/custom_admin.css b/members/static/members/css/custom_admin.css
new file mode 100644
index 00000000..f8f5eda8
--- /dev/null
+++ b/members/static/members/css/custom_admin.css
@@ -0,0 +1,7 @@
+.inline-group .tabular tr.has_original td {
+ padding-top: 8px;
+}
+
+.original {
+ display: none;
+}
\ No newline at end of file