mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 08:02:54 +11:00
Added support for spam checks.
This commit is contained in:
parent
9248e8edd5
commit
19bfd3f769
3 changed files with 25 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
||||||
from pastebin.apps.dpaste.models import Snippet
|
from pastebin.apps.dpaste.models import Snippet, Spamword
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
class SnippetAdmin(admin.ModelAdmin):
|
class SnippetAdmin(admin.ModelAdmin):
|
||||||
|
@ -11,3 +11,4 @@ class SnippetAdmin(admin.ModelAdmin):
|
||||||
)
|
)
|
||||||
|
|
||||||
admin.site.register(Snippet, SnippetAdmin)
|
admin.site.register(Snippet, SnippetAdmin)
|
||||||
|
admin.site.register(Spamword)
|
|
@ -1,7 +1,7 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from pastebin.apps.dpaste.models import Snippet
|
from pastebin.apps.dpaste.models import Snippet, Spamword
|
||||||
from pastebin.apps.dpaste.highlight import LEXER_LIST_ALL, LEXER_LIST, LEXER_DEFAULT
|
from pastebin.apps.dpaste.highlight import LEXER_LIST_ALL, LEXER_LIST, LEXER_DEFAULT
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
@ -47,6 +47,14 @@ class SnippetForm(forms.ModelForm):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def clean_content(self):
|
||||||
|
content = self.cleaned_data.get('content')
|
||||||
|
if content:
|
||||||
|
regex = Spamword.objects.get_regex()
|
||||||
|
if regex.findall(content):
|
||||||
|
raise forms.ValidationError('This snippet was identified as SPAM.')
|
||||||
|
return content
|
||||||
|
|
||||||
def save(self, parent=None, *args, **kwargs):
|
def save(self, parent=None, *args, **kwargs):
|
||||||
|
|
||||||
# Set parent snippet
|
# Set parent snippet
|
||||||
|
|
|
@ -2,6 +2,7 @@ import datetime
|
||||||
import difflib
|
import difflib
|
||||||
import random
|
import random
|
||||||
import mptt
|
import mptt
|
||||||
|
import re
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import permalink
|
from django.db.models import permalink
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
@ -46,3 +47,16 @@ class Snippet(models.Model):
|
||||||
return '%s' % self.secret_id
|
return '%s' % self.secret_id
|
||||||
|
|
||||||
mptt.register(Snippet, order_insertion_by=['content'])
|
mptt.register(Snippet, order_insertion_by=['content'])
|
||||||
|
|
||||||
|
|
||||||
|
class SpamwordManager(models.Manager):
|
||||||
|
def get_regex(self):
|
||||||
|
return re.compile(r'|'.join((i[1] for i in self.values_list())),
|
||||||
|
re.MULTILINE)
|
||||||
|
|
||||||
|
class Spamword(models.Model):
|
||||||
|
word = models.CharField(max_length=100)
|
||||||
|
objects = SpamwordManager()
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.word
|
||||||
|
|
Loading…
Reference in a new issue