30 lines
646 B
Python
30 lines
646 B
Python
from django import forms
|
|
from django.forms import CharField, ModelForm
|
|
|
|
from webtools import settings
|
|
|
|
from .models import Paste
|
|
|
|
|
|
class PasteForm(ModelForm):
|
|
"""Paste model form."""
|
|
|
|
content = CharField(
|
|
max_length=settings.PASTE["max_characters"], strip=False, widget=forms.Textarea
|
|
)
|
|
|
|
class Meta:
|
|
model = Paste
|
|
fields = [
|
|
"filename",
|
|
"content",
|
|
]
|
|
|
|
def save(self, commit=True):
|
|
"""Overwrites save method."""
|
|
paste = super(PasteForm, self).save(commit=False)
|
|
paste.compute_size()
|
|
if commit:
|
|
paste.save()
|
|
return paste
|