pasteque/paste/forms.py

30 lines
646 B
Python
Raw Normal View History

from django import forms
2023-04-21 12:47:30 +00:00
from django.forms import CharField, ModelForm
from webtools import settings
2023-04-21 12:32:45 +00:00
from .models import Paste
2013-04-04 17:37:30 +00:00
class PasteForm(ModelForm):
"""Paste model form."""
2020-05-31 13:33:59 +00:00
content = CharField(
max_length=settings.PASTE["max_characters"], strip=False, widget=forms.Textarea
)
2013-04-04 17:37:30 +00:00
class Meta:
model = Paste
2020-05-31 13:33:59 +00:00
fields = [
2023-04-21 12:32:45 +00:00
"filename",
2020-05-31 13:33:59 +00:00
"content",
]
2018-05-06 21:19:49 +00:00
2013-04-04 17:37:30 +00:00
def save(self, commit=True):
"""Overwrites save method."""
paste = super(PasteForm, self).save(commit=False)
paste.compute_size()
if commit:
paste.save()
return paste