Skip to content

Commit

Permalink
Merge branch 'master' into feature/AdminPayment.MoreDetailsAndFilters
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewel authored Sep 24, 2023
2 parents 741de0d + c01490d commit 6748348
Show file tree
Hide file tree
Showing 42 changed files with 1,180 additions and 451 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:
run: cp .env.example .env
- name: Builds the stack
run: docker-compose build
- name: Check formatting (Black)
run: docker-compose run web black --check .
- name: Static error check (Flake8)
run: docker-compose run web flake8
- name: Test
run: docker-compose run web ./manage.py test
- uses: actions/[email protected]
if: always()
with:
name: selenium-screens
path: ./test-screens
- name: Check formatting (Black)
run: docker-compose run web black --check .
- name: Static error check (Flake8)
run: docker-compose run web flake8
- name: Create and upload UML diagram
run: mkdir -p UML && docker-compose run web ./manage.py graph_models members -o UML/UML_diagram.png
- uses: actions/[email protected]
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
FROM python:3.10
WORKDIR /app

RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash - && \
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get update && apt-get install -y \
graphviz \
nodejs


RUN npm install -g npm

# This is not a nice way to install npm packages, but it is the
Expand Down
106 changes: 84 additions & 22 deletions members/admin/activity_admin.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,81 @@
from django.contrib import admin
from django.urls import reverse
from django.utils.safestring import mark_safe
from members.models import Department
from members.models import ActivityParticipant

from members.models import (
ActivityParticipant,
AdminUserInformation,
Department,
Union,
)


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()


class ActivityUnionListFilter(admin.SimpleListFilter):
title = "Lokalforeninger"
parameter_name = "department__union"

def lookups(self, request, model_admin):
unions = []
for union1 in (
Union.objects.filter(
department__union__in=AdminUserInformation.get_unions_admin(
request.user
)
)
.order_by("name")
.distinct()
):
unions.append((str(union1.pk), str(union1.name)))
return unions

def queryset(self, request, queryset):
if self.value() is None:
return queryset
else:
return queryset.filter(department__union__pk=self.value())


class ActivityDepartmentListFilter(admin.SimpleListFilter):
title = "Afdelinger"
parameter_name = "department"

def lookups(self, request, model_admin):
departments = []
for department1 in (
Department.objects.filter(
activity__department__in=AdminUserInformation.get_departments_admin(
request.user
)
)
.order_by("name")
.distinct()
):
departments.append((str(department1.pk), str(department1)))
return departments

def queryset(self, request, queryset):
if self.value() is None:
return queryset
else:
return queryset.filter(department__pk=self.value())


class ActivityAdmin(admin.ModelAdmin):
list_display = (
"name",
Expand Down Expand Up @@ -45,33 +105,31 @@ class ActivityAdmin(admin.ModelAdmin):
"department",
)
list_filter = (
"department__union__name",
"department__name",
ActivityUnionListFilter,
ActivityDepartmentListFilter,
"open_invite",
"activitytype",
)
save_as = True
inlines = [ActivityParticipantInline]

def startend(self, obj):
return str(obj.start_date) + " - " + str(obj.end_date)

startend.short_description = "Periode"
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

def age(self, obj):
return str(obj.min_age) + " - " + str(obj.max_age)

age.short_description = "Alder"
inlines = [ActivityParticipantInline]

def start_end(self, obj):
return str(obj.start_date) + " - " + str(obj.end_date)

start_end.short_description = "Periode"
start_end.admin_order_field = "start_date"

def age(self, obj):
return str(obj.min_age) + " - " + str(obj.max_age)

age.short_description = "Alder"
age.admin_order_field = "min_age"

def union_link(self, item):
url = reverse("admin:members_union_change", args=[item.department.union_id])
Expand All @@ -93,6 +151,7 @@ def seats_total(self, obj):
return str(obj.max_participants)

seats_total.short_description = "Total"
seats_total.admin_order_field = "max_participants"

def seats_used(self, obj):
return str(obj.activityparticipant_set.count())
Expand All @@ -104,6 +163,16 @@ def seats_free(self, obj):

seats_free.short_description = "Ubesat"

def activity_membership_union_link(self, obj):
if obj.activitytype_id in ["FORENINGSMEDLEMSKAB", "STØTTEMEDLEMSKAB"]:
url = reverse("admin:members_union_change", args=[obj.union_id])
link = '<a href="%s">%s</a>' % (url, obj.union.name)
return mark_safe(link)
else:
return ""

activity_membership_union_link.short_description = "Forening for medlemskab"

# Only view activities on own department
def get_queryset(self, request):
qs = super(ActivityAdmin, self).get_queryset(request)
Expand All @@ -130,13 +199,6 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs):
"fields": ("department",),
},
),
(
"Forening",
{
"description": "<p><b>Bemærk:</b> Denne værdi bruges kun til foreningsmedlemsskab/støttemedlemsskab.</p>",
"fields": ("union",),
},
),
(
"Aktivitet",
{
Expand Down
Loading

0 comments on commit 6748348

Please sign in to comment.