Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ git:

install:
- pip install pipenv
- pipenv install
- pipenv install --dev

script:
- pycodestyle $(git ls-files '*.py')
- pydocstyle $(git ls-files '*.py')
- pyflakes $(git ls-files '*.py')
- ./manage.py makemigrations website
- ./manage.py migrate
- ./manage.py test
7 changes: 3 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[packages]

django = ">=2.2.3"
gunicorn = "*"


[dev-packages]
pyflakes = "*"
pydocstyle = "*"
pycodestyle = "*"

[requires]
python_version = "3.7"
35 changes: 33 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 29 additions & 1 deletion website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils.text import slugify

import sys

class CustomUser(AbstractUser):
"""
Expand Down Expand Up @@ -63,9 +63,27 @@ class Event(models.Model):

An event can contain multiple workshops (as long as the workshops are
within the event period.

Three types of events exist.
UNSW info days: No support needed. Students and volunteers can't sign up
School_based_events: volunteer support
UNSW_events: Volunteers and students support needed
"""

name = models.CharField(max_length=100)
SCHOOL = 'SE'
UNI_INFO = 'UIE'
UNI = 'UE'

EVENT_TYPES = (
(SCHOOL, 'School'),
(UNI_INFO, 'Uni_Info'),
(UNI, 'Uni'),
)
event_types = models.CharField(max_length = 3,
choices = EVENT_TYPES,
default = UNI,
)
start_date = models.DateField()
finish_date = models.DateField()
owner = models.ForeignKey(Volunteer, on_delete=models.SET_NULL, null=True)
Expand All @@ -74,10 +92,20 @@ class Event(models.Model):
period = models.TextField(verbose_name='availability period')
slug = models.SlugField(default='event', unique=False) # url name of event


def __str__(self):
"""Return a string representation of an event."""
return self.name

def hasWorkshops(self):
if self.event_types == self.UNI_INFO:
#print(self.event_types)
#print(self.UNI_INFO)
#sys.stdout.flush()
return False
else:
return True

def save(self, *args, **kwargs):
"""Override save to update slug."""
self.slug = slugify(self.name)
Expand Down
16 changes: 10 additions & 6 deletions website/templates/website/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
<div class="header">
<h1 class="title">{{ event.name }}</h1>
</div>
{% if perms.website.change_event %}
{% if perms.website.change_event and event.hasWorkshops%}
<a href="{% url 'website:assign_volunteers' slug=event.slug event_id=event.pk %}" class="event-button"><i class="fas fa-users"></i> Available Volunteers</a>
{% endif %}
<div class="event-detail-card">
<div class="event-card-container">
{% if user.is_staff %}
<p>
{% if event.hasWorkshops%}
<a class="event-button"
href="{% url 'website:workshop_create' slug=event.slug event_id=event.pk %}">
<i class="fas fa-calendar-plus"></i> Create Workshop</a>
{% endif %}
<a class="event-button"
href="{% url 'website:volunteer_email_preview' slug=event.slug event_id=event.pk %}">
<i class="fas fa-envelope-open"></i> Send status email</a>
Expand All @@ -32,7 +34,7 @@ <h3 class="event-detail">Event Details</h3>

<h3 class="event-detail">Description</h3>
<p>{{ event.description }}</p>

{% if event.hasWorkshops%}
<h3 class="event-detail">Workshop Schedule</h3>
<table class="table">
<thead class="thead-dark">
Expand All @@ -46,6 +48,7 @@ <h3 class="event-detail">Workshop Schedule</h3>
{% endif %}
</tr>
</thead>

{% if workshops %}
{% for workshop in workshops %}
<tbody>
Expand All @@ -67,19 +70,20 @@ <h3 class="event-detail">Workshop Schedule</h3>
<button class="btn btn-danger" type="submit">Cancel</button></td>
{% endif %}
{% else %}
<button class="btn btn-success" type="submit">Confirm</button></td>
{% endif %}
<button class="btn btn-success" type="submit">Confirm</button></td>
{% endif %}
</div>
</form>
</form>
{% endif %}
</tr>
</tbody>
{% endfor %}
{% else %}
<p>To be confirmed</p>
{% endif %}
{% endif %}
</table>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
29 changes: 25 additions & 4 deletions website/templates/website/event_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
{% block content %}
{{ block.super }}
<div class="container">
<h3 class="display-3 mb-3 mt-3">Create event</h3>
<div id = "title">
<h3 class="display-3 mb-3 mt-3" id="title">Create Event</h3>
</div>

<form class="event-form" method="post" novalidate>
{% csrf_token %}
Expand Down Expand Up @@ -37,7 +39,7 @@ <h3 class="display-3 mb-3 mt-3">Create event</h3>

<div class="form-row">

<div class="form-group col-md-4">
<div class="form-group col-md-3">
{{ form.start_date.label_tag }}
{% if form.start_date.errors %}
{{ form.start_date|add_attrs:"is-invalid" }}
Expand All @@ -54,7 +56,7 @@ <h3 class="display-3 mb-3 mt-3">Create event</h3>
</small>
</div>

<div class="form-group col-md-4">
<div class="form-group col-md-3">
{{ form.finish_date.label_tag }}
{% if form.finish_date.errors %}
{{ form.finish_date|add_attrs:"is-invalid" }}
Expand All @@ -71,7 +73,7 @@ <h3 class="display-3 mb-3 mt-3">Create event</h3>
</small>
</div>

<div class="form-group col-md-4">
<div class="form-group col-md-3">
<label for="{{ form.owner.id_for_label }}">{{ form.owner.label }}:</label>
<div class="input-group">
<div class="input-group-prepend">
Expand All @@ -93,6 +95,25 @@ <h3 class="display-3 mb-3 mt-3">Create event</h3>
</small>
</div>

<div class="form-group col-md-3">
<label for="{{ event_form.event_types.id_for_label }}">{{ event_form.event_types.label }}:</label>
<div class="input-group">
{% if event_form.event_types.errors %}
{{ event_form.event_types|add_attrs:"is-invalid" }}
{% for error in event_form.event_types.errors %}
<div class="invalid-feedback">
{{ error }}
</div>
{% endfor %}
{% else %}
{{ event_form.event_types }}
{% endif %}
</div>
<small class="form-text text-muted">
{{ event_form.event_types.help_text }}
</small>
</div>

</div>

<div class="form-group">
Expand Down
5 changes: 5 additions & 0 deletions website/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,19 @@ def test_event_create_valid(self):
'name': 'Intro to Python',
'start_date': '2018-01-01',
'finish_date': '2018-04-30',
'event_types': 'UIE',
'owner': '1',
'description': 'introduction to Python',
'prerequisite': 'Nil',
'period': 'period',
'slug': 'Intro-to-Python'
}
form = EventForm(data=form_data)
form.is_valid()
print(form.errors)
self.assertTrue(form.is_valid())


def test_event_create_invalid_dates(self):
form_data = {
'name': 'Intro to Python',
Expand Down Expand Up @@ -183,6 +187,7 @@ def setUp(self):
'start_date': '2018-10-31',
'finish_date': '2018-11-08',
'owner': '1',
'event_types':'UE',
'description': 'introduction to Python',
'prerequisite': 'Nil',
'period': 'period',
Expand Down
28 changes: 14 additions & 14 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class EventPage(DetailView):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

# add event workshops to context and display first workshop location
workshops = Workshop.objects \
.filter(event=context['event']) \
Expand All @@ -86,13 +85,14 @@ def get(self, request, event_id, slug):
# check if url is valid
event = get_object_or_404(Event, pk=event_id)
if event.slug != slug:
return redirect('website:event_page', event_id=event.pk,
return redirect('website:event_page', event_id=event.pk,
slug=event.slug)

return super().get(request, event_id, slug)

def post(self, request, event_id, slug):
if request.user.is_authenticated:
event = get_object_or_404(Event, pk=event_id)
if request.user.is_authenticated and event.hasWorkshops:
# check if user in list of available volunteers for a workshop
volunteer = Volunteer.objects.get(user=request.user)
workshop_id = request.POST.get("workshop_id")
Expand Down Expand Up @@ -138,7 +138,7 @@ def get(self, request, event_id, slug):
# check if url is valid
event = get_object_or_404(Event, pk=event_id)
if event.slug != slug:
return redirect('website:registration', event_id=event.pk,
return redirect('website:registration', event_id=event.pk,
slug=event.slug)

return super().get(request, event_id, slug)
Expand All @@ -148,7 +148,7 @@ def get_success_url(self):

class EventCreate(CreateView):
"""
Render and show an event creation form. The form allows for the creation
Render and show an event creation form. The form allows for the creation
of new events. Only staff members can access and see this page.

Args:
Expand All @@ -166,8 +166,8 @@ def get_success_url(self):
class VolunteerStatusEmailPreview(View):
"""
Render and show an email preview page, and should be shown after assigning
volunteers to workshops in an event. If a POST request is sent, an email
will be sent to the listed volunteers whether they are assigned, on a
volunteers to workshops in an event. If a POST request is sent, an email
will be sent to the listed volunteers whether they are assigned, on a
waitlist or declined. Only staff members can access and see this page.

Args:
Expand Down Expand Up @@ -204,8 +204,8 @@ def post(self, request, event_id, slug):

class EventAssignVolunteers(View):
"""
Render and show a volunteer assignment page. The page shows a series of
forms allowing a staff member to assign volunteers to workshops for a
Render and show a volunteer assignment page. The page shows a series of
forms allowing a staff member to assign volunteers to workshops for a
particular event. Only staff members can access and see this page.

Args:
Expand Down Expand Up @@ -239,7 +239,7 @@ def get(self, request, event_id, slug):

def post(self, request, event_id, slug):
if 'workshop_id' in request.POST:
workshop = get_object_or_404(Workshop,
workshop = get_object_or_404(Workshop,
pk=request.POST['workshop_id'])

post_form = VolunteerAssignForm(request.POST,
Expand All @@ -248,13 +248,13 @@ def post(self, request, event_id, slug):

if post_form.is_valid():
post_form.save()
return redirect('website:assign_volunteers',
event_id=event_id,
return redirect('website:assign_volunteers',
event_id=event_id,
slug=slug)

class WorkshopCreate(CreateView):
"""
Render and show a workshop creation form page. The page shows a form
Render and show a workshop creation form page. The page shows a form
allowing a staff member to create a new workshop for a particular event.
Only staff members can access and see this page.

Expand Down Expand Up @@ -300,7 +300,7 @@ class AboutView(TemplateView):
#@login_required
#def user_profile(request):
# """
# Render and show the user's profile page. Requires that the user is logged
# Render and show the user's profile page. Requires that the user is logged
# in.
# NOTE: this is minimally implemented and is currently not used
#
Expand Down