mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 08:02:54 +11:00
Strip content before putting it in the db.
This commit is contained in:
parent
a4a3b38a5b
commit
ce29409340
1 changed files with 12 additions and 10 deletions
|
@ -17,7 +17,7 @@ EXPIRE_CHOICES = (
|
|||
|
||||
EXPIRE_DEFAULT = 3600 * 24 * 30
|
||||
|
||||
MAX_CONTENT_LENGTH = 250*1024*1024
|
||||
MAX_CONTENT_LENGTH = getattr(settings, 'DPASTE_MAX_CONTENT_LENGTH', 250*1024*1024)
|
||||
|
||||
class SnippetForm(forms.ModelForm):
|
||||
content = forms.CharField(
|
||||
|
@ -45,6 +45,13 @@ class SnippetForm(forms.ModelForm):
|
|||
widget=forms.TextInput(attrs={'autocomplete': 'off'}),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Snippet
|
||||
fields = (
|
||||
'content',
|
||||
'lexer',
|
||||
)
|
||||
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
super(SnippetForm, self).__init__(*args, **kwargs)
|
||||
self.request = request
|
||||
|
@ -67,12 +74,14 @@ class SnippetForm(forms.ModelForm):
|
|||
lexer = dict(LEXER_LIST).get(lexer, LEXER_DEFAULT)
|
||||
return lexer
|
||||
|
||||
def clean_content(self):
|
||||
return self.cleaned_data.get('content', '').strip()
|
||||
|
||||
def clean(self):
|
||||
if self.cleaned_data.get('title'):
|
||||
raise forms.ValidationError('This snippet was identified as Spam.')
|
||||
return self.cleaned_data
|
||||
|
||||
|
||||
def save(self, parent=None, *args, **kwargs):
|
||||
|
||||
# Set parent snippet
|
||||
|
@ -97,11 +106,4 @@ class SnippetForm(forms.ModelForm):
|
|||
# Save the lexer in the session so we can use it later again
|
||||
self.request.session['lexer'] = self.cleaned_data['lexer']
|
||||
|
||||
return self.request, self.instance
|
||||
|
||||
class Meta:
|
||||
model = Snippet
|
||||
fields = (
|
||||
'content',
|
||||
'lexer',
|
||||
)
|
||||
return self.request, self.instance
|
Loading…
Reference in a new issue