-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add skyward expedition submission form (#136)
* Add submission upload capability * Added submissions dashboard for admin
- Loading branch information
1 parent
717bd94
commit ab1aaba
Showing
14 changed files
with
297 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import magic | ||
from django.core.exceptions import ValidationError | ||
from django.template.defaultfilters import filesizeformat | ||
from django.utils.deconstruct import deconstructible | ||
|
||
|
||
@deconstructible | ||
class FileValidator(object): | ||
error_messages = { | ||
"max_size": ( | ||
"Ensure this file size is not greater than %(max_size)s." | ||
"Your file size is %(size)s" | ||
), | ||
"min_size": ( | ||
"Ensure this file size is not less than %(min_size)s." | ||
"Your file size is %(size)s." | ||
), | ||
"content_type": "Files of type %(content_type)s are not supported.", | ||
} | ||
|
||
def __init__(self, max_size=None, min_size=None, content_types=()): | ||
self.max_size = max_size | ||
self.min_size = min_size | ||
self.content_types = content_types | ||
|
||
def __call__(self, data): | ||
if self.max_size is not None and data.size > self.max_size: | ||
params = { | ||
"max_size": filesizeformat(self.max_size), | ||
"size": filesizeformat(data.size), | ||
} | ||
raise ValidationError(self.error_messages["max_size"], "max_size", params) | ||
|
||
if self.min_size is not None and data.size < self.min_size: | ||
params = { | ||
"min_size": filesizeformat(self.min_size), | ||
"size": filesizeformat(data.size), | ||
} | ||
raise ValidationError(self.error_messages["min_size"], "min_size", params) | ||
|
||
if self.content_types: | ||
content_type = magic.from_buffer(data.read(), mime=True) | ||
data.seek(0) | ||
|
||
if content_type not in self.content_types: | ||
params = {"content_type": content_type} | ||
raise ValidationError( | ||
self.error_messages["content_type"], "content_type", params | ||
) | ||
|
||
def __eq__(self, other): | ||
return ( | ||
isinstance(other, FileValidator) | ||
and self.max_size == other.max_size | ||
and self.min_size == other.min_size | ||
and self.content_types == other.content_types | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
asgiref==3.7.2 | ||
Django==4.2.10 | ||
cfgv==3.4.0 | ||
distlib==0.3.8 | ||
Django==4.2.7 | ||
filelock==3.13.1 | ||
gunicorn==21.2.0 | ||
identify==2.5.34 | ||
nodeenv==1.8.0 | ||
packaging==23.1 | ||
Pillow==10.2.0 | ||
Pillow==10.0.1 | ||
pip==24.0 | ||
platformdirs==4.2.0 | ||
pre-commit==3.6.1 | ||
psycopg2-binary==2.9.9 | ||
python-magic==0.4.27 | ||
PyYAML==6.0.1 | ||
setuptools==68.2.2 | ||
sqlparse==0.4.4 | ||
typing_extensions==4.8.0 | ||
virtualenv==20.25.0 | ||
wheel==0.41.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Generated by Django 4.2.7 on 2024-03-04 04:10 | ||
import django.db.models.deletion | ||
from django.db import migrations | ||
from django.db import models | ||
|
||
import corpus.validators | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
( | ||
"skyward_expedition", | ||
"0003_seuser_degree_seuser_ieee_member_seuser_ieee_number_and_more", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Submission", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"file", | ||
models.FileField( | ||
upload_to="skyward_expedition/submissions", | ||
validators=[ | ||
corpus.validators.FileValidator( | ||
content_types=( | ||
"application/zip", | ||
"application/x-rar-compressed", | ||
"application/octet-stream", | ||
), | ||
max_size=10485760, | ||
) | ||
], | ||
verbose_name="Submission File", | ||
), | ||
), | ||
( | ||
"team", | ||
models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="skyward_expedition.team", | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
corpus/templates/skyward_expedition/admin/submissions_dashboard.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% extends 'skyward_expedition/base.html' %} | ||
|
||
{% block title %} | ||
Submissions Dashboard | ||
{{ block.super }} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="flex flex-col mx-20"> | ||
<div class="flex flex-row justify-center items-center my-20"> | ||
<h1 class="text-4xl font-bold text-center">Submissions Dashboard</h1> | ||
</div> | ||
<div class="flex flex-row mb-20"> | ||
<a href="{% url 'skyward_expedition_admin' %}" class="btn btn-accent m-5">Go to Admin Dashboard</a> | ||
</div> | ||
<div class="flex flex-col my-10 overflow-x-auto"> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<td>Team</td> | ||
<td>Submission</td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for submission in submissions %} | ||
<tr> | ||
<td>{{ submission.team.team_name }}</td> | ||
<td> | ||
<a href="{{ submission.file.url }}" | ||
class="underline underline-offset-4 text-primary">{{ submission.file }}</a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.