Initial Commit
This commit is contained in:
commit
715224653d
58 changed files with 7760 additions and 0 deletions
28
gurps_character/forms.py
Normal file
28
gurps_character/forms.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import json
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
def validate_file(value):
|
||||
if value.size > 10**6:
|
||||
raise ValidationError("File too large")
|
||||
|
||||
try:
|
||||
data = json.loads(value.read())
|
||||
except json.JSONDecodeError:
|
||||
raise ValidationError("Not a GCS file - json decode")
|
||||
|
||||
try:
|
||||
version = data['version']
|
||||
except KeyError:
|
||||
import bpdb;bpdb.set_trace()
|
||||
raise ValidationError("Not a GCS file - key error")
|
||||
|
||||
if version < 4:
|
||||
raise ValidationError(
|
||||
f"The file version ({version}) is too old. Please use a newer version (5.20.3) of GCS."
|
||||
)
|
||||
|
||||
|
||||
class UploadFileForm(forms.Form):
|
||||
file = forms.FileField(validators=[validate_file])
|
||||
Loading…
Add table
Add a link
Reference in a new issue