Skip to content

Commit

Permalink
Merge pull request #89 from csyager/rush_fixes
Browse files Browse the repository at this point in the history
Fixes for rush signin
  • Loading branch information
csyager authored Sep 4, 2020
2 parents 10a74be + 1fcbd5f commit 25aeba7
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def get_model_perms(self, request):

admin.site.register(SiteSettings, SiteSettingsAdmin)

admin.site.site_header = "GreekLink Settings"
admin.site.site_header = "Greek-Rho Settings"
5 changes: 5 additions & 0 deletions core/fixtures/auth.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@
"view_rushevent",
"rush",
"rushevent"
],
[
"activate_rushsignin",
"core",
"permissionssupport"
]
]
}
Expand Down
3 changes: 2 additions & 1 deletion core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class Meta:
default_permissions = ()
permissions = (
('add_calendar', 'Add calendar'),
('delete_calendar', 'Remove calendar')
('delete_calendar', 'Remove calendar'),
('activate_rushsignin', 'Activate rushsignin')
)
#----------------------------------------------------------------------- block for resource file
class ResourceFileQuerySet(models.QuerySet):
Expand Down
12 changes: 9 additions & 3 deletions rush/templates/rush/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ <h2>Rush Events</h2>
{% if not events %}
<b><i>No rush events to display. Rush events can be created by admins, and track attendance of invited rushees.</i></b>
{% endif %}
{% for event in events %}
<a href="/rush/events/{{ event.id }}" class="list-group-item">{{ event.name }} -- {{ event.date }}, {{ event.time }} <span class="badge badge-info">{{ event.attendance.count }}</span></a>
{% endfor %}
<ul class="list-group">
{% for event in events %}
<li class="list-group-item">
<a href="/rush/events/{{ event.id }}">{{ event.name }} -- {{ event.date }}, {{ event.time }} <span class="badge badge-info">{{ event.attendance.count }}</span></a>
{% if perms.rush.deleterushevent %}
<a href="removeEvent{{ event.id }}" class="btn btn-danger btn-sm float-right">Remove</a>
{% endif %}
</li>
{% endfor %}
</div>
<br>
{% if perms.rush.add_rushevent %}
Expand Down
84 changes: 79 additions & 5 deletions rush/templates/rush/signin.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,92 @@
{% extends 'core/base.html' %}
{% block content %}
{% load static %}

{% if perms.core.activate_rushsignin %}
<div class="container">
<br><br>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="rush_signin_switch" {% if settings.rush_signin_active %}checked{% endif %} onclick="window.location = '/rush/toggle_rush_signin'">
<label class="custom-control-label" for="rush_signin_switch">Rush signin is <b>{% if settings.rush_signin_active %} active {% else %} inactive{% endif %}</b></label>
</div>
</div>
<br>
{% endif %}
{% if not settings.rush_signin_active %}
<br><br>
<div class="container">
<div class="alert alert-danger">
Rush signin is not active. Must be enabled by site admin.
</div>

</div>
{% elif event is None %}
<div class="container">
<div class="alert alert-danger">
No rush events exist! An admin must create an event for rushees to sign into first.
</div>
{% if perms.rush.add_rushevent %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#eventModal">Create an event</button>
<!-- Modal -->
<div class="modal fade" id="eventModal" tabindex="-1" role="dialog" aria-labelledby="eventModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="eventModalLabel">Create Event</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form method="post" action="createEvent">
{% csrf_token %}
<div class="form-group row">
<label for="new_name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="new_name" name="name">
</div>
</div>
<div class="form-group row">
<label for="new_date" class="col-sm-2 col-form-label">Date</label>
<div class="col-sm-10">
<input type="date" class="form-control" placeholder="YYYY-mm-dd" id="new_date" name="date">
</div>
</div>
<div class="form-group row">
<label for="new_event_round" class="col-sm-2 col-form-label">Round</label>
<div class="col-sm-10">
<select class="form-control" id="new_event_round" name="round">
{% for num in round_range %}
<option>{{ num }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group row">
<label for="new_time" class="col-sm-2 col-form-label">Time</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="new_time" placeholder="HH:mm:ss in 24-hour time" name="time">
</div>
</div>
<div class="form-group row">
<label for="new_location" class="col-sm-2 col-form-label">Location</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="new_location" name="location">
</div>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="new_new_rushees" name="new_rushees" value="new_rushees">
<label for="new_new_rushees" class="form-check-label">New Rushees Allowed?</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</form>
</div>
</div>
</div>
</div>
{% endif %}
{% else %}

<br>

<div class="dropdown" style="margin-left: 5%">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Change event
Expand Down
4 changes: 2 additions & 2 deletions rush/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ def test_events_view(self):
""" tests the view showing all rush events """
path = reverse('rush:events')
response = self.client.post(path)
self.assertContains(response, '<a href="/rush/events/' + str(self.event1.pk) + '" class="list-group-item">')
self.assertContains(response, '<a href="/rush/events/' + str(self.event2.pk) + '" class="list-group-item">')
self.assertContains(response, '<a href="/rush/events/' + str(self.event1.pk))
self.assertContains(response, '<a href="/rush/events/' + str(self.event2.pk))

def test_single_event_view(self):
""" tests the view showing a single event """
Expand Down
1 change: 1 addition & 0 deletions rush/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
path('removeEvent<int:event_id>', views.remove_event, name="remove_event"),
path('filter_rushees', views.filter_rushees, name="filter_rushees"),
path('clear_rushees_filter', views.clear_rushees_filter, name="clear_rushees_filter"),
path('toggle_rush_signin', views.toggle_rush_signin, name='toggle_rush_signin'),
]
18 changes: 17 additions & 1 deletion rush/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def signin(request, event_id=-1):
form = RusheeForm()
objects = Rushee.objects.filter(cut=False).order_by('name')
all_events = RushEvent.objects.all().order_by('date')
settings = getSettings()
round_range = range(1, settings.num_rush_rounds + 1)
if int(event_id) != -1:
this_event = RushEvent.objects.get(id=int(event_id))
objects = (Rushee.objects.filter(round=this_event.round, cut=False)
Expand All @@ -187,7 +189,8 @@ def signin(request, event_id=-1):
"event": this_event,
"objects": objects,
"events": all_events,
'settings': getSettings()
'round_range': round_range,
'settings': settings
}
return HttpResponse(template.render(context, request))

Expand Down Expand Up @@ -553,3 +556,16 @@ def clear_rushees_filter(request):
except KeyError:
pass
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

@permission_required('core.activate_rushsignin')
def toggle_rush_signin(request):
""" activates rush signin """
settings = getSettings()
if settings.rush_signin_active:
settings.rush_signin_active = False
else:
settings.rush_signin_active = True
settings.save()
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))


0 comments on commit 25aeba7

Please sign in to comment.