forked from heroku/python-getting-started
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
24 lines (16 loc) · 632 Bytes
/
Copy pathforms.py
File metadata and controls
24 lines (16 loc) · 632 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
from django import forms
from django.core.exceptions import ValidationError
from .models import Case
class SubmissionForm(forms.Form):
files = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': True}))
class SubmissionDebugForm(forms.Form):
file = forms.FileField()
def clean_file(self):
file = self.cleaned_data['file']
name = os.path.splitext(file.name)[0]
case = Case.objects.filter(name=name).first()
if case is None:
raise ValidationError('File name does not match any case')
self.cleaned_data['case'] = case
return file