Skip to content

Commit 3c0f2fe

Browse files
Copilotkarbassi
andcommitted
Add cancellation_reason field to Order model with admin and template updates
Co-authored-by: karbassi <17738+karbassi@users.noreply.github.com>
1 parent 37b0c88 commit 3c0f2fe

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

coderdojochi/admin.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ class OrderAdmin(ImportExportMixin, ImportExportActionModelAdmin):
717717
"_created_at",
718718
"is_checked_in",
719719
"is_active",
720+
"has_cancellation_reason",
720721
]
721722

722723
list_filter = [
@@ -748,6 +749,21 @@ class OrderAdmin(ImportExportMixin, ImportExportActionModelAdmin):
748749

749750
date_hierarchy = "created_at"
750751

752+
fields = (
753+
"guardian",
754+
"session",
755+
"student",
756+
"is_active",
757+
"check_in",
758+
"cancellation_reason",
759+
"alternate_guardian",
760+
"affiliate",
761+
"order_number",
762+
"ip",
763+
"week_reminder_sent",
764+
"day_reminder_sent",
765+
)
766+
751767
view_on_site = False
752768

753769
actions = [
@@ -796,6 +812,12 @@ def _created_at(self, obj):
796812

797813
_created_at.short_description = "Created At"
798814

815+
def has_cancellation_reason(self, obj):
816+
return bool(obj.cancellation_reason)
817+
818+
has_cancellation_reason.boolean = True
819+
has_cancellation_reason.short_description = "Has Reason"
820+
799821

800822
def mentor_check_in(modeladmin, request, queryset):
801823
queryset.update(check_in=timezone.now())
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.6
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('coderdojochi', '0040_alter_mentor_avatar'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='order',
15+
name='cancellation_reason',
16+
field=models.TextField(blank=True, help_text='Reason for cancellation or no-show', null=True),
17+
),
18+
]

coderdojochi/models/order.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class Order(CommonInfo):
5353
day_reminder_sent = models.BooleanField(
5454
default=False,
5555
)
56+
cancellation_reason = models.TextField(
57+
blank=True,
58+
null=True,
59+
help_text="Reason for cancellation or no-show",
60+
)
5661

5762
def __str__(self):
5863
return f"{self.student.full_name} | {self.session.course.title}"

coderdojochi/templates/dashboard/session_check_in.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
width: 10%;
3737
}
3838

39+
.cancellation-reason {
40+
min-width: 150px;
41+
width: 15%;
42+
max-width: 200px;
43+
}
44+
3945
.order-date {}
4046

4147
.student-gender {
@@ -305,6 +311,7 @@ <h2 class="title">No Shows <span class="badge">{{ no_show_orders.count }}</span>
305311
<th class="parent-phone">Parent Phone</th>
306312
<th class="student-school">School</th>
307313
<th class="order-date">Last Update Date</th>
314+
<th class="cancellation-reason">Reason</th>
308315
<th class="text-right num-attended"><abbr title="Number Attended">#A</abbr></th>
309316
<th class="text-right num-missed"><abbr title="Number Missed">#M</abbr></th>
310317
</tr>
@@ -321,6 +328,13 @@ <h2 class="title">No Shows <span class="badge">{{ no_show_orders.count }}</span>
321328
<td>{{ order.guardian.phone | phone_number }}</td>
322329
<td>{{ order.student.school_name }}</td>
323330
<td>{{ order.updated_at | date:"M j, g:i A" }}</td>
331+
<td class="cancellation-reason">
332+
{% if order.cancellation_reason %}
333+
{{ order.cancellation_reason|truncatewords:10 }}
334+
{% else %}
335+
<em>No reason given</em>
336+
{% endif %}
337+
</td>
324338
<td class="text-right vert-align">{{ order.num_attended }}</td>
325339
<td class="text-right vert-align {% if order.num_missed >= 3 %}danger{% endif %}">{{ order.num_missed }}</td>
326340
</tr>
@@ -349,6 +363,7 @@ <h2 class="title">Cancelled Tickets <span class="badge">{{ inactive_orders.count
349363
<th class="parent-phone">Parent Phone</th>
350364
<th class="student-school">School</th>
351365
<th class="order-date">Cancelled Date</th>
366+
<th class="cancellation-reason">Reason</th>
352367
<th class="text-right num-attended"><abbr title="Number Attended">#A</abbr></th>
353368
<th class="text-right num-missed"><abbr title="Number Missed">#M</abbr></th>
354369
</tr>
@@ -365,6 +380,13 @@ <h2 class="title">Cancelled Tickets <span class="badge">{{ inactive_orders.count
365380
<td>{{ order.guardian.phone | phone_number }}</td>
366381
<td>{{ order.student.school_name }}</td>
367382
<td>{{ order.updated_at | date:"M j, g:i A" }}</td>
383+
<td class="cancellation-reason">
384+
{% if order.cancellation_reason %}
385+
{{ order.cancellation_reason|truncatewords:10 }}
386+
{% else %}
387+
<em>No reason given</em>
388+
{% endif %}
389+
</td>
368390
<td class="text-right">{{ order.num_attended }}</td>
369391
<td class="text-right {% if order.num_missed >= 3 %}danger{% endif %}">{{ order.num_missed }}</td>
370392
</tr>

0 commit comments

Comments
 (0)