Skip to content

Commit

Permalink
attendance on cancelled activity
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoglom committed Nov 19, 2015
1 parent 3d36bd0 commit ba1564d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
12 changes: 7 additions & 5 deletions intranet/apps/eighth/forms/admin/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def label_from_instance(self, obj):

class ActivitySelectionForm(forms.Form):

def __init__(self, label="Activity", block=None, sponsor=None, *args, **kwargs):
def __init__(self, label="Activity", block=None, sponsor=None, include_cancelled=False, *args, **kwargs):
super(ActivitySelectionForm, self).__init__(*args, **kwargs)

if block is not None:
Expand All @@ -39,21 +39,23 @@ def __init__(self, label="Activity", block=None, sponsor=None, *args, **kwargs):
else:
activity_ids = (EighthScheduledActivity.objects
.exclude(activity__deleted=True)
.exclude(cancelled=True)
.filter(block=block)
.values_list("activity__id", flat=True)
.nocache())
if not include_cancelled:
activity_ids = activity_ids.exclude(cancelled=True)

queryset = (EighthActivity.objects.filter(id__in=activity_ids)
.order_by("name"))
else:
if sponsor is not None:
queryset = (EighthActivity.undeleted_objects
.filter(sponsors=sponsor)
.order_by("name"))
.order_by("name")).nocache()
else:
queryset = (EighthActivity.undeleted_objects
.all()
.order_by("name"))
.order_by("name")).nocache()

self.fields["activity"] = ActivityDisplayField(queryset=queryset,
label=label,
Expand Down Expand Up @@ -84,7 +86,7 @@ def __init__(self, label="Activities", block=None, *args, **kwargs):
if block is not None:
activity_ids = (EighthScheduledActivity.objects
.exclude(activity__deleted=True)
.exclude(cancelled=True)
#.exclude(cancelled=True)
.filter(block=block)
.values_list("activity__id", flat=True)
.nocache())
Expand Down
18 changes: 13 additions & 5 deletions intranet/apps/eighth/views/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,25 @@ def take_attendance_view(request, scheduled_activity_id):
else:
logger.debug("User does not have permission to edit")
edit_perm = False

edit_perm_cancelled = False

if scheduled_activity.cancelled and not request.user.is_eighth_admin:
logger.debug("Non-admin user does not have permission to edit cancelled activity")
edit_perm = False
edit_perm_cancelled = True

if request.method == "POST":

if not edit_perm:
return render(request, "error/403.html", {
"reason": "You do not have permission to take attendance for this activity. You are not a sponsor."
}, status=403)
if edit_perm_cancelled:
return render(request, "error/403.html", {
"reason": "You do not have permission to take attendance for this activity. The activity was cancelled."
}, status=403)
else:
return render(request, "error/403.html", {
"reason": "You do not have permission to take attendance for this activity. You are not a sponsor."
}, status=403)

if "admin" in request.path:
url_name = "eighth_admin_take_attendance"
Expand Down Expand Up @@ -370,14 +378,14 @@ def take_attendance_view(request, scheduled_activity_id):
"members": members,
"p": pass_users,
"no_edit_perm": not edit_perm,
"edit_perm_cancelled": edit_perm_cancelled,
"show_checkboxes": (scheduled_activity.block.locked or request.user.is_eighth_admin),
"show_icons": (scheduled_activity.block.locked and scheduled_activity.block.attendance_locked() and not request.user.is_eighth_admin)
}

if request.user.is_eighth_admin:
context["scheduled_activities"] = (EighthScheduledActivity.objects
.filter(block__id=scheduled_activity.block.id)
.exclude(cancelled=True))
.filter(block__id=scheduled_activity.block.id))
logger.debug(context["scheduled_activities"])
context["blocks"] = (EighthBlock.objects
# .filter(date__gte=get_start_date(request))
Expand Down
9 changes: 7 additions & 2 deletions intranet/templates/eighth/take_attendance.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ <h2>
{% endif %}

{% if no_edit_perm %}
<strong style="color: red"><i class="fa fa-exclamation-triangle"></i> You are not a sponsor for this activity, so you can only view the roster.</strong>
<br />
{% if edit_perm_cancelled %}
<strong style="color: red"><i class="fa fa-exclamation-triangle"></i> This activity was cancelled, so you can only view the roster.</strong>
<br />
{% else %}
<strong style="color: red"><i class="fa fa-exclamation-triangle"></i> You are not a sponsor for this activity, so you can only view the roster.</strong>
<br />
{% endif %}
{% endif %}

{% if request.GET.no_attendance %}
Expand Down

0 comments on commit ba1564d

Please sign in to comment.