Skip to content

Commit

Permalink
Merge pull request #863 from lakridserne/feature/776_refactor_members…
Browse files Browse the repository at this point in the history
…_table

Fjern medlemmer fra admin, og alle andre steder, mens vi arbejder på en ny og retvisende medlemstabel
  • Loading branch information
lakridserne authored Mar 19, 2023
2 parents b8b9d2a + 699fdbb commit 3e3acc8
Show file tree
Hide file tree
Showing 28 changed files with 131 additions and 236 deletions.
3 changes: 0 additions & 3 deletions members/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
EmailTemplate,
Equipment,
Family,
Member,
Payment,
Person,
Union,
Expand All @@ -25,7 +24,6 @@
from .department_admin import DepartmentAdmin
from .equipment_admin import EquipmentAdmin
from .family_admin import FamilyAdmin
from .member_admin import MemberAdmin
from .payment_admin import PaymentAdmin
from .person_admin import PersonAdmin
from .union_admin import UnionAdmin
Expand All @@ -43,7 +41,6 @@
admin.site.register(EmailTemplate)
admin.site.register(Equipment, EquipmentAdmin)
admin.site.register(Family, FamilyAdmin)
admin.site.register(Member, MemberAdmin)
admin.site.register(Payment, PaymentAdmin)
admin.site.register(Person, PersonAdmin)
admin.site.register(Union, UnionAdmin)
Expand Down
4 changes: 2 additions & 2 deletions members/admin/activity_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
class ActivityParticipantInline(admin.TabularInline):
model = ActivityParticipant
extra = 0
fields = ("member",)
fields = ("person",)
readonly_fields = fields
raw_id_fields = ("member",)
raw_id_fields = ("person",)

def get_queryset(self, request):
return ActivityParticipant.objects.all()
Expand Down
50 changes: 24 additions & 26 deletions members/admin/activityparticipant_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ActivityParticipantListCurrentYearFilter(admin.SimpleListFilter):
title = "Efter aktivitet (\u2265 år " + str(timezone.now().year) + ")"

# Parameter for the filter that will be used in the URL query.
parameter_name = "activity"
parameter_name = "activity_current_year"

def lookups(self, request, model_admin):
activitys = []
Expand All @@ -59,7 +59,7 @@ class ActivityParticipantListLastYearFilter(admin.SimpleListFilter):
title = "Efter aktivitet (= år " + str(timezone.now().year - 1) + ")"

# Parameter for the filter that will be used in the URL query.
parameter_name = "activity"
parameter_name = "activity_last_year"

def lookups(self, request, model_admin):
activitys = []
Expand All @@ -82,7 +82,7 @@ class ActivityParticipantListOldYearsFilter(admin.SimpleListFilter):
title = "Efter aktivitet (\u2264 år " + str(timezone.now().year - 2) + ")"

# Parameter for the filter that will be used in the URL query.
parameter_name = "activity"
parameter_name = "activity_old_years"

def lookups(self, request, model_admin):
activitys = []
Expand Down Expand Up @@ -200,7 +200,7 @@ class ActivityParticipantAdmin(admin.ModelAdmin):
date_hierarchy = "activity__start_date"
raw_id_fields = ("activity",)
search_fields = (
"member__person__name",
"person__name",
"activity__name",
)

Expand All @@ -209,13 +209,13 @@ class ActivityParticipantAdmin(admin.ModelAdmin):
]

def person_age_years(self, item):
return item.member.person.age_years()
return item.person.age_years()

person_age_years.short_description = "Alder"
person_age_years.admin_order_field = "-member__person__birthday"
person_age_years.admin_order_field = "-person__birthday"

def person_zipcode(self, item):
return item.member.person.zipcode
return item.person.zipcode

person_zipcode.short_description = "Postnummer"

Expand All @@ -227,32 +227,30 @@ def get_queryset(self, request):
return qs.filter(activity__department__adminuserinformation__user=request.user)

def activity_person_gender(self, item):
if item.member.person.gender == "MA":
if item.person.gender == "MA":
return "Dreng"
elif item.member.person.gender == "FM":
elif item.person.gender == "FM":
return "Pige"
else:
return "Andet"

activity_person_gender.short_description = "Køn"

def activity_person_link(self, item):
url = reverse("admin:members_person_change", args=[item.member.person_id])
link = '<a href="%s">%s</a>' % (url, item.member.person.name)
url = reverse("admin:members_person_change", args=[item.person_id])
link = '<a href="%s">%s</a>' % (url, item.person.name)
return mark_safe(link)

activity_person_link.short_description = "Deltager"
activity_person_link.admin_order_field = "member__person__name"
activity_person_link.admin_order_field = "person__name"

def activity_family_email_link(self, item):
url = reverse(
"admin:members_family_change", args=[item.member.person.family_id]
)
link = '<a href="%s">%s</a>' % (url, item.member.person.family.email)
url = reverse("admin:members_family_change", args=[item.person.family_id])
link = '<a href="%s">%s</a>' % (url, item.person.family.email)
return mark_safe(link)

activity_family_email_link.short_description = "Familie"
activity_family_email_link.admin_order_field = "member__person__family__email"
activity_family_email_link.admin_order_field = "person__family__email"

def activity_link(self, item):
url = reverse("admin:members_activity_change", args=[item.activity.id])
Expand Down Expand Up @@ -311,21 +309,21 @@ def export_csv_full(self, request, queryset):
result_string += "Køn;Post-nr;Betalingsinfo;Forældre navn;Forældre email;"
result_string += "Forældre tlf;Note til arrangørerne\n"
for p in queryset:
if p.member.person.gender is not None:
if p.member.person.gender == "MA":
if p.person.gender is not None:
if p.person.gender == "MA":
gender = "Dreng"
elif p.member.person.gender == "FM":
elif p.person.gender == "FM":
gender = "Pige"
else:
gender = p.member.person.gender
gender = p.person.gender
else:
gender = "andet"

parent = p.member.person.family.get_first_parent()
parent = p.person.family.get_first_parent()
if parent:
parent_name = parent.name
parent_phone = parent.phone
if not p.member.person.family.dont_send_mails:
if not p.person.family.dont_send_mails:
parent_email = parent.email
else:
parent_email = ""
Expand All @@ -342,13 +340,13 @@ def export_csv_full(self, request, queryset):
+ ";"
+ p.activity.name
+ ";"
+ p.member.person.name
+ p.person.name
+ ";"
+ str(p.member.person.age_years())
+ str(p.person.age_years())
+ ";"
+ gender
+ ";"
+ p.member.person.zipcode
+ p.person.zipcode
+ ";"
+ self.activity_payment_info_txt(p)
+ ";"
Expand Down
2 changes: 1 addition & 1 deletion members/admin/family_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_queryset(self, request):
adminuserinformation__user=request.user
).values("id")
return qs.filter(
Q(person__member__activityparticipant__activity__department__in=departments)
Q(person__activityparticipant__activity__department__in=departments)
| Q(person__waitinglist__department__in=departments)
| Q(person__activityinvite__activity__department__in=departments)
).distinct()
8 changes: 0 additions & 8 deletions members/admin/inlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Department,
EmailItem,
EquipmentLoan,
Member,
Payment,
Person,
Volunteer,
Expand Down Expand Up @@ -96,13 +95,6 @@ class EquipmentLoanInline(admin.TabularInline):
extra = 0


class MemberInline(admin.TabularInline):
fields = ["department", "member_since", "member_until"]
readonly_fields = fields
model = Member
extra = 0


class PaymentInline(admin.TabularInline):
model = Payment
fields = ("added_at", "payment_type", "confirmed_at", "rejected_at", "amount_ore")
Expand Down
42 changes: 0 additions & 42 deletions members/admin/member_admin.py

This file was deleted.

4 changes: 1 addition & 3 deletions members/admin/person_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

from .inlines import (
ActivityInviteInline,
MemberInline,
PaymentInline,
VolunteerInline,
WaitingListInline,
Expand Down Expand Up @@ -67,7 +66,6 @@ class PersonAdmin(admin.ModelAdmin):
PaymentInline,
VolunteerInline,
ActivityInviteInline,
MemberInline,
WaitingListInline,
]

Expand Down Expand Up @@ -376,7 +374,7 @@ def get_queryset(self, request):
).values("id")
return qs.filter(
Q(
family__person__member__activityparticipant__activity__department__in=departments
family__person__activityparticipant__activity__department__in=departments
)
| Q(family__person__waitinglist__department__in=departments)
| Q(
Expand Down
28 changes: 14 additions & 14 deletions members/admin/person_admin_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class PersonParticipantCurrentYearListFilter(admin.SimpleListFilter):
title = "Deltager på (år " + str(timezone.now().year) + ")"
parameter_name = "participant_list_active"
parameter_name = "participant_list_current_year"

def lookups(self, request, _model_admin):
return [
Expand All @@ -20,18 +20,18 @@ def lookups(self, request, _model_admin):

def queryset(self, request, queryset):
if self.value() == "none":
return queryset.filter(member__activityparticipant__isnull=True)
return queryset.filter(activityparticipant__isnull=True)
elif self.value() == "any":
return queryset.exclude(member__activityparticipant__isnull=True)
return queryset.exclude(activityparticipant__isnull=True)
elif self.value() is None:
return queryset
else:
return queryset.filter(member__activityparticipant__activity=self.value())
return queryset.filter(activityparticipant__activity=self.value())


class PersonParticipantLastYearListFilter(admin.SimpleListFilter):
title = "Deltager på (år " + str(timezone.now().year - 1) + ")"
parameter_name = "participant_list_active"
parameter_name = "participant_list_last_year"

def lookups(self, request, _model_admin):
return [
Expand All @@ -45,13 +45,13 @@ def lookups(self, request, _model_admin):

def queryset(self, request, queryset):
if self.value() == "none":
return queryset.filter(member__activityparticipant__isnull=True)
return queryset.filter(activityparticipant__isnull=True)
elif self.value() == "any":
return queryset.exclude(member__activityparticipant__isnull=True)
return queryset.exclude(activityparticipant__isnull=True)
elif self.value() is None:
return queryset
else:
return queryset.filter(member__activityparticipant__activity=self.value())
return queryset.filter(activityparticipant__activity=self.value())


class PersonParticipantActiveListFilter(admin.SimpleListFilter):
Expand All @@ -70,13 +70,13 @@ def lookups(self, request, _model_admin):

def queryset(self, request, queryset):
if self.value() == "none":
return queryset.filter(member__activityparticipant__isnull=True)
return queryset.filter(activityparticipant__isnull=True)
elif self.value() == "any":
return queryset.exclude(member__activityparticipant__isnull=True)
return queryset.exclude(activityparticipant__isnull=True)
elif self.value() is None:
return queryset
else:
return queryset.filter(member__activityparticipant__activity=self.value())
return queryset.filter(activityparticipant__activity=self.value())


class PersonParticipantListFilter(admin.SimpleListFilter):
Expand All @@ -94,13 +94,13 @@ def lookups(self, request, model_admin):

def queryset(self, request, queryset):
if self.value() == "none":
return queryset.filter(member__activityparticipant__isnull=True)
return queryset.filter(activityparticipant__isnull=True)
elif self.value() == "any":
return queryset.exclude(member__activityparticipant__isnull=True)
return queryset.exclude(activityparticipant__isnull=True)
elif self.value() is None:
return queryset
else:
return queryset.filter(member__activityparticipant__activity=self.value())
return queryset.filter(activityparticipant__activity=self.value())


class PersonInvitedListFilter(admin.SimpleListFilter):
Expand Down
16 changes: 8 additions & 8 deletions members/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ def do(self):
for announcement in unannounced_signups:
context = {
"activity": announcement.activity,
"person": announcement.member.person,
"family": announcement.member.person.family,
"person": announcement.person,
"family": announcement.person.family,
"union": announcement.activity.department.union,
}
emails = EmailTemplate.objects.get(idname="ACT_CONFIRM").makeEmail(
[announcement.member.person, announcement.member.person.family], context
[announcement.person, announcement.person.family], context
)
for email in emails:
notification = Notification(
family=announcement.member.person.family,
family=announcement.person.family,
email=email,
anounced_activity_participant=announcement,
)
Expand Down Expand Up @@ -163,16 +163,16 @@ def do(self):
for announcement in unannounced_signups:
context = {
"activity": announcement.activity,
"person": announcement.member.person,
"family": announcement.member.person.family,
"person": announcement.person,
"family": announcement.person.family,
"union": announcement.activity.department.union,
}
emails = EmailTemplate.objects.get(idname="ACT_CONFIRM").makeEmail(
[announcement.member.person, announcement.member.person.family], context
[announcement.person, announcement.person.family], context
)
for email in emails:
notification = Notification(
family=announcement.member.person.family,
family=announcement.person.family,
email=email,
anounced_activity_participant=announcement,
)
Expand Down
Loading

0 comments on commit 3e3acc8

Please sign in to comment.