Commit a5278cec by Joseph Walton-Rivers

form fields for students, filter cleanup

parent 8bdc0c8b
Pipeline #1335 passed with stages
in 4 minutes 48 seconds
......@@ -18,7 +18,7 @@ class RegisterForm(forms.ModelForm):
raise ValidationError("registrations are not currently open")
class Meta:
fields = ["name", "description", "track", "allow_download"]
fields = ["name", "description", "track", "allow_download", "is_student"]
widgets = {'track': forms.HiddenInput()}
model = Submission
......
# Generated by Django 2.0.2 on 2018-03-12 10:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fg_competitions', '0011_auto_20180309_1506'),
]
operations = [
migrations.AddField(
model_name='submission',
name='is_student',
field=models.CharField(choices=[('y', 'Yes'), ('n', 'No')], default='n', help_text='Is this submission by a student?', max_length=1, verbose_name='Student Submission'),
preserve_default=False,
),
]
# Generated by Django 2.0.2 on 2018-03-12 10:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fg_competitions', '0012_submission_is_student'),
]
operations = [
migrations.AlterField(
model_name='submission',
name='allow_download',
field=models.BooleanField(default=True, help_text='Allow public distribution after results publication', verbose_name='Make public'),
),
]
......@@ -17,6 +17,13 @@ SUBMISSION_TYPES = [
("U", "Upload")
]
# non-optional boolean field
YES_OR_NO = (
('y', 'Yes'),
('n', 'No')
)
@python_2_unicode_compatible
class Competition(models.Model):
"""A high-level descripiton of a topic"""
......@@ -79,11 +86,12 @@ class Submission(models.Model):
name = models.CharField(max_length=50)
description = models.TextField(blank=True, help_text="Briefly describe your submission")
created = models.DateTimeField(auto_now_add=True)
sample = models.BooleanField(default=False)
submission_type = models.CharField(max_length=1, default="U", choices=SUBMISSION_TYPES)
# Extras
allow_download = models.BooleanField(default=False, verbose_name="Make public", help_text="Allow public distribution after results publication")
allow_download = models.BooleanField(default=True, verbose_name="Make public", help_text="Allow public distribution after results publication")
is_student = models.CharField(max_length=1, choices=YES_OR_NO, verbose_name="Student Submission", help_text="Is this submission by a student?")
sample = models.BooleanField(default=False)
# foreign keys
track = models.ForeignKey(Track, on_delete=models.CASCADE)
......
......@@ -52,41 +52,39 @@
</div>
</div>
{% empty %}
<p class="text-muted">No tracks are currently running</p>
<p class="text-muted">No tracks matching this criteria</p>
{% endfor %}
</div>
<div class="col-12 col-md-4 col-lg-3 collapse" id="filters">
<h2 style="margin-bottom: 15px" >Filters</h2>
<div class="col-12 col-md-4 col-lg-3 collapse show" id="filters">
<h2 class="mb-3" >Filters</h2>
<form action="?search" method="GET">
<div class="input-group">
<div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-search" aria-hidden="true"></i></span></div>
<input type="text" class="form-control" placeholder="search..." name="name" />
<input type="text" class="form-control" placeholder="search..." value="{{get_name}}" name="name" />
</div>
</form>
<div class="filters" style="margin-top: 30px">
<h4 data-toggle="collapse" data-target="#filter-uploads">Allow uploads</h4>
<div id="filter-uploads" class="list-group collapse in">
<a class="list-group-item list-group-item-action" href="?{% url_replace allow_submit=2 %}">Yes</a>
<a class="list-group-item list-group-item-action" href="?{% url_replace allow_submit=3 %}">No</a>
<h4 class="mt-3">Allow uploads</h4>
<div id="filter-uploads" class="list-group">
<a class="list-group-item list-group-item-action {% if not get_allow_submit or get_allow_submit == '1' %}active{% endif %}" href="?{% url_replace allow_submit=1 %}">Either</a>
<a class="list-group-item list-group-item-action {% if get_allow_submit == '2' %}active{% endif %}" href="?{% url_replace allow_submit=2 %}">Yes</a>
<a class="list-group-item list-group-item-action {% if get_allow_submit == '3' %}active{% endif %}" href="?{% url_replace allow_submit=3 %}">No</a>
</div>
<h4 style="margin-top: 15px" data-toggle="collapse" data-target="#filter-competition">Competition</h4>
<h4 class="mt-3" >Competition</h4>
<div id="filter-competition" class="list-group">
<a class="list-group-item list-group-item-action" href="?{% url_replace competition=None %}">All competitions</a>
<a class="list-group-item list-group-item-action {% if not get_competition %}active{% endif %}" href="?{% url_replace competition=None %}">All competitions</a>
{% for competition in competitions %}
<a class="list-group-item list-group-item-action" href="?{% url_replace competition=competition.pk %}">{{competition}}</a>
<a class="list-group-item list-group-item-action {% if get_competition == competition.pk %}active{% endif %}" href="?{% url_replace competition=competition.pk %}">{{competition}}</a>
{% endfor %}
</div>
</div>
</div>
</div>
{% if is_paginated %}
<nav aria-label="Page navigation example">
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li class="page-item">
......
......@@ -68,7 +68,14 @@ class TrackList(FilterView):
def get_context_data(self, **kwargs):
context = super(TrackList, self).get_context_data(**kwargs)
# Filter paramters - this is hacky
# if there is a better way without using the form we should do that instead...
context['competitions'] = Competition.objects.all()
context['get_name'] = self.request.GET.get('name', '')
context['get_allow_submit'] = self.request.GET.get('allow_submit', None)
filter_comp = self.request.GET.get('competition', None)
context['get_competition'] = int(filter_comp) if filter_comp else None
if self.request.user.is_authenticated:
results = Submission.objects.filter(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment