-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathforms.py
More file actions
37 lines (27 loc) · 995 Bytes
/
forms.py
File metadata and controls
37 lines (27 loc) · 995 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
25
26
27
28
29
30
31
32
33
34
35
36
37
from django import forms
from django.conf import settings
from django.template.defaultfilters import filesizeformat
from .models import Comment
class UploadFileForm(forms.Form):
file = forms.FileField(
label="Select archive",
widget=forms.FileInput(attrs={"accept": "application/zip"}),
)
def clean_file(self):
data = self.cleaned_data["file"]
if data.size >= settings.FILE_UPLOAD_MAX_MEMORY_SIZE:
raise forms.ValidationError(
f"Keep files below "
f"{filesizeformat(settings.FILE_UPLOAD_MAX_MEMORY_SIZE)}"
)
return data
class LoginForm(forms.Form):
username = forms.CharField(label="Username")
password = forms.CharField(label="Password", widget=forms.PasswordInput)
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ("text",)
widgets = {
"text": forms.Textarea(attrs={"class": "form-control"}),
}