pasteque/paste/forms.py

25 lines
762 B
Python
Raw Normal View History

from webtools import settings
from django import forms
2013-04-04 17:37:30 +00:00
from django.forms import ModelForm
from .models import Paste, Language, EXPIRE_CHOICES
2013-04-04 17:37:30 +00:00
class PasteForm(ModelForm):
"""Paste model form."""
class Meta:
model = Paste
2018-05-06 21:19:49 +00:00
fields = ['language', 'title', 'password', 'content', 'lifetime',
'lifecount', 'private']
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 not self.cleaned_data['title']:
paste.title = 'no title'
if self.cleaned_data['password']:
paste.set_password(self.cleaned_data['password'])
if commit:
paste.save()
return paste