Skip to content

Commit

Permalink
Merge branch 'master' into 957-bug-rettigheder-skal-kun-håndteres-på-…
Browse files Browse the repository at this point in the history
…gruppe-niveau-ikke-på-bruger-niveau-for-alm-admins
  • Loading branch information
lakridserne authored Sep 24, 2023
2 parents 3237ce5 + ec618ba commit b92517d
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 24 deletions.
4 changes: 2 additions & 2 deletions members/admin/activity_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class ActivityParticipantInline(admin.TabularInline):
"person",
"note",
"photo_permission",
"payment_info_text",
"payment_info_html",
)
readonly_fields = fields
can_delete = False

def get_queryset(self, request):
return ActivityParticipant.objects.all()
return ActivityParticipant.objects.all().order_by("person")


class ActivityUnionListFilter(admin.SimpleListFilter):
Expand Down
9 changes: 9 additions & 0 deletions members/admin/activityinvite_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def get_form(self, request, obj=None, change=False, **kwargs):
"invite_dtm",
"expire_dtm",
"rejected_at",
"participating",
)
list_filter = (
ActivityInviteUnionListFilter,
Expand Down Expand Up @@ -244,3 +245,11 @@ def person_link(self, item):

person_link.short_description = "Person"
person_link.admin_order_field = "person__name"

def participating(self, item):
return item.person.activityparticipant_set.filter(
activity=item.activity
).exists()

participating.short_description = "Deltager"
participating.boolean = True
43 changes: 41 additions & 2 deletions members/admin/admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from django.utils.safestring import mark_safe
from django.utils.html import escape
from django.shortcuts import render
import members.models.emailtemplate
import members.models.waitinglist

from members.models import (
Activity,
Expand All @@ -23,6 +25,10 @@

class AdminActions(admin.ModelAdmin):
def invite_many_to_activity_action(modelAdmin, request, queryset):
template = members.models.emailtemplate.EmailTemplate.objects.get(
idname="ACT_INVITE"
)

# Get list of available departments
if request.user.is_superuser or request.user.has_perm(
"members.view_all_persons"
Expand Down Expand Up @@ -60,6 +66,9 @@ class MassInvitationForm(forms.Form):
widget=AdminDateWidget(),
initial=timezone.now() + timedelta(days=30 * 3),
)
email_text = forms.CharField(
label="Email ekstra info", widget=forms.Textarea
)

# Lookup all the selected persons - to show confirmation list
# Check if it's called from Waiting List
Expand Down Expand Up @@ -180,15 +189,45 @@ class MassInvitationForm(forms.Form):
"expire"
],
)

email_info = mass_invitation_form.cleaned_data[
"email_text"
]

mail_context = {
"activity": activity,
"activity_invite": invitation,
"person": current_person,
"family": current_person.family,
"email_extra_info": email_info,
}
invitation.save()
if current_person.email and (
current_person.email
!= current_person.family.email
):
# If invited has own email, also send to that.
template.makeEmail(
[current_person, current_person.family],
mail_context,
True,
)
else:
# otherwise use only family
template.makeEmail(
current_person.family,
mail_context,
True,
)
persons_invited.append(current_person.name)

except Exception:
except Exception as E:
messages.error(
request,
"Fejl - ingen personer blev inviteret! Der var problemer med "
+ (invitation.person.name if invitation else "(n/a)")
+ ". Vær sikker på personen ikke allerede er inviteret og opfylder alderskravet.",
+ ". Vær sikker på personen ikke allerede er inviteret og opfylder alderskravet."
+ f"{E=}",
)
return

Expand Down
14 changes: 12 additions & 2 deletions members/admin/department_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DepartmentAdmin(admin.ModelAdmin):
"isOpening",
"created",
"closed_dtm",
"description",
"waitinglist_count_link",
)
list_filter = (
"address__region",
Expand All @@ -45,7 +45,6 @@ class DepartmentAdmin(admin.ModelAdmin):
"address__placename",
"address__zipcode",
"address__city",
"description",
)
filter_horizontal = ["department_leaders"]

Expand Down Expand Up @@ -117,3 +116,14 @@ def department_link(self, item):

department_link.short_description = "Afdeling"
department_link.admin_order_field = "name"

def waitinglist_count_link(self, item):
admin_url = reverse("admin:members_waitinglist_changelist")
link = f"""<a
href="{admin_url}?waiting_list={item.id}"
title="Vis venteliste for afdelingen Coding Pirates {item.name}">
{item.waitinglist_set.count()}
</a>"""
return mark_safe(link)

waitinglist_count_link.short_description = "Venteliste"
21 changes: 20 additions & 1 deletion members/admin/union_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
from django.urls import reverse
from django.utils.safestring import mark_safe

from members.models import Address, Person
from members.models import (
Address,
Person,
Department,
)


class UnionAdmin(admin.ModelAdmin):
Expand All @@ -16,6 +20,7 @@ class UnionAdmin(admin.ModelAdmin):
"union_email",
"founded_at",
"closed_at",
"waitinglist_count_link",
)
list_filter = (
"address__region",
Expand Down Expand Up @@ -108,6 +113,20 @@ def union_link(self, item):
union_link.short_description = "Forening"
union_link.admin_order_field = "name"

def waitinglist_count_link(self, item):
waitinglist_count = 0
for department in Department.objects.all().filter(union=item.id):
waitinglist_count += department.waitinglist_set.count()
admin_url = reverse("admin:members_waitinglist_changelist")
link = f"""<a
href="{admin_url}?={item.id}"
title="Vis venteliste for forening Coding Pirates {item.name}">
{waitinglist_count}
</a>"""
return mark_safe(link)

waitinglist_count_link.short_description = "Venteliste"

def export_csv_union_info(self, request, queryset):
result_string = "Forening;Oprettelsdato;Lukkedato;"
result_string += "formand-navn;formand-email;formand-tlf;"
Expand Down
15 changes: 0 additions & 15 deletions members/models/activityinvite.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@ def clean(self):
def save(self, *args, **kwargs):
if not self.id:
super(ActivityInvite, self).save(*args, **kwargs)
template = members.models.emailtemplate.EmailTemplate.objects.get(
idname="ACT_INVITE"
)
context = {
"activity": self.activity,
"activity_invite": self,
"person": self.person,
"family": self.person.family,
}
if self.person.email and (self.person.email != self.person.family.email):
# If invited has own email, also send to that.
template.makeEmail([self.person, self.person.family], context)
else:
# otherwise use only family
template.makeEmail(self.person.family, context)
# remove from department waiting list
if self.activity.is_season():
members.models.waitinglist.WaitingList.objects.filter(
Expand Down
11 changes: 10 additions & 1 deletion members/models/activityparticipant.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def payment_info_text(self):

payment_info_text.short_description = "Betalingsinfo"

def payment_info_html(self):
return self.payment_info(True)

payment_info_html.short_description = "Betalingsinfo"

def payment_info(self, format_as_html: bool):
if format_as_html:
html_error_pre = "<span style='color:red'><b>"
Expand All @@ -77,7 +82,11 @@ def payment_info(self, format_as_html: bool):

# Checking for price = 0 before checking for payment
if self.activity.price_in_dkk == 0:
return f"{html_good_pre}Gratis.{html_post} "
result_string = f"{html_good_pre}Gratis.{html_post} "
if format_as_html:
return format_html(result_string)
else:
return result_string

try:
payment = members.models.payment.Payment.objects.get(
Expand Down
16 changes: 15 additions & 1 deletion members/templates/admin/invite_many_to_activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<h2>Vælg aktivitet</h2>
<div class="description">
<p>Gennemgå listen og vælg den korrekte afdeling og aktivitet der skal inviteres til.</p>
<p>Vælg desuden en udløbsdato for invitationen. </p>
<p>Vælg desuden en udløbsdato for invitationen.</p>
<p>Skriv noget ekstra tekst</p>
<p>Når du trykker på <kbd style="background-color:green; color: white;">&nbsp;INVITER&nbsp;</kbd>-knappen vil systemet invitere personer, der ikke allerede deltager/er inviteret til aktiviteten samt er indenfor aldersgrænsen når aktiviteten starter. Det endeligt antal inviterede kan derfor afvige fra antallet i listen herunder.</p>
<p>Der sendes en email med en beskrivelse af aktiviteten samt et link til tilmelding!</p>
</div>
Expand All @@ -51,6 +52,19 @@ <h2>Vælg aktivitet</h2>
</div>
{% endfor %}

<h2>Email template</h2>
<div class="description">
<p>Alle personer inviteres og der sendes en email udfra følgende mail template:</p><br>
<b>ID: </b>
<text readonly><pre>{{ emailtemplate.idname }}</pre></text><br>
<b>Subject: </b>
<text readonly><pre>{{ emailtemplate.subject }}</pre></text><br>
<b>HTML: </b>
<text readonly><pre>{{ emailtemplate.body_html }}</pre></text>
<b>Text: </b>
<text readonly><pre>{{ emailtemplate.body_text }}</pre></text>
</div>

<h2>Bekræft deltagere</h2>
<div class="description">
<p>Følgende ({{persons.count}}) personer inviteres:</p>
Expand Down
1 change: 1 addition & 0 deletions members/tests/test_admin_admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def create_mock_request_object(self):
"activity": "1",
"department": "1",
"expire": datetime.fromisoformat("2023-12-31"),
"email_text": "Lidt ekstra tekst",
}
request.user = self.user

Expand Down

0 comments on commit b92517d

Please sign in to comment.