Skip to content

Commit

Permalink
Merge branch 'master' into 908-feature-overblik-over-betalingsinfo-un…
Browse files Browse the repository at this point in the history
…der-selve-aktivitetens-info
  • Loading branch information
lakridserne authored Aug 20, 2023
2 parents 04f287a + 5ccd688 commit 96448c9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
34 changes: 26 additions & 8 deletions members/admin/user_admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin
from django.db.models.functions import Upper
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import Group
from members.models import AdminUserInformation, Person, Union, Department
Expand All @@ -9,6 +10,13 @@ class AdminUserInformationInline(admin.StackedInline):
filter_horizontal = ("departments", "unions")
can_delete = False

def formfield_for_manytomany(self, db_field, request, **kwargs):
if db_field.name == "departments":
kwargs["queryset"] = Department.objects.all().order_by(Upper("name").asc())
if db_field.name == "unions":
kwargs["queryset"] = Union.objects.all().order_by(Upper("name").asc())
return super().formfield_for_manytomany(db_field, request, **kwargs)


class PersonInline(admin.StackedInline):
model = Person
Expand All @@ -21,7 +29,7 @@ class AdminUserGroupListFilter(admin.SimpleListFilter):
parameter_name = "group"

def lookups(self, request, model_admin):
groupList = ()
groupList = [("none", "(ingen gruppe)")]
for aGroup in Group.objects.all().order_by("name"):
groupList += (
(
Expand All @@ -33,6 +41,8 @@ def lookups(self, request, model_admin):

def queryset(self, request, queryset):
group_id = request.GET.get(self.parameter_name, None)
if group_id == "none":
return queryset.filter(groups__isnull=True)
if group_id:
return queryset.filter(groups=group_id)
return queryset
Expand All @@ -43,7 +53,7 @@ class AdminUserUnionListFilter(admin.SimpleListFilter):
parameter_name = "union"

def lookups(self, request, model_admin):
unionList = ()
unionList = [("none", "(ingen forening)"), ("any", "(mindst en forening)")]
for aUnion in Union.objects.all().order_by("name"):
unionList += (
(
Expand All @@ -55,8 +65,12 @@ def lookups(self, request, model_admin):

def queryset(self, request, queryset):
union_id = request.GET.get(self.parameter_name, None)
if union_id:
return queryset.filter(groups=union_id)
if union_id == "none":
return queryset.filter(adminuserinformation__unions__isnull=True)
elif union_id == "any":
return queryset.exclude(adminuserinformation__unions__isnull=True)
elif union_id:
return queryset.filter(adminuserinformation__unions=union_id)
return queryset


Expand All @@ -65,7 +79,7 @@ class AdminUserDepartmentListFilter(admin.SimpleListFilter):
parameter_name = "department"

def lookups(self, request, model_admin):
departmentList = ()
departmentList = [("none", "(ingen afdeling)"), ("any", "(mindst en afdeling)")]
for aDepartment in Department.objects.all().order_by("name"):
departmentList += (
(
Expand All @@ -76,9 +90,13 @@ def lookups(self, request, model_admin):
return departmentList

def queryset(self, request, queryset):
union_id = request.GET.get(self.parameter_name, None)
if union_id:
return queryset.filter(groups=union_id)
department_id = request.GET.get(self.parameter_name, None)
if department_id == "none":
return queryset.filter(adminuserinformation__departments__isnull=True)
elif department_id == "any":
return queryset.exclude(adminuserinformation__departments__isnull=True)
if department_id:
return queryset.filter(adminuserinformation__departments=department_id)
return queryset


Expand Down
2 changes: 1 addition & 1 deletion members/templates/members/membership.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h2>Tilmeld som medlem her</h2>
</tr>
</thead>
<tbody class="union-membership-tablebody">
{% for activity in region.list|dictsort:"department.name" %}
{% for activity in region.list|dictsort:"department.union.name" %}
<tr>
<td>
Coding Pirates<br>
Expand Down
2 changes: 1 addition & 1 deletion members/tests/factories/union_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UnionFactory(DjangoModelFactory):
class Meta:
model = Union

name = factory.LazyAttribute(lambda u: "Coding Pirates {}".format(u.address.city))
name = factory.LazyAttribute(lambda u: "{}".format(u.address.city))
chairman_old = Faker("name")
chairman_email_old = Faker("email")
second_chair_old = Faker("name")
Expand Down

0 comments on commit 96448c9

Please sign in to comment.