forked from rc/aircox
add missing files
This commit is contained in:
parent
88a5a9556e
commit
160a5db500
47
cms/forms.py
Normal file
47
cms/forms.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
import django.forms as forms
|
||||||
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
|
from honeypot.decorators import verify_honeypot_value
|
||||||
|
|
||||||
|
import aircox.cms.models as models
|
||||||
|
|
||||||
|
|
||||||
|
class CommentForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = models.Comment
|
||||||
|
fields = ['author', 'email', 'url', 'content']
|
||||||
|
localized_fields = '__all__'
|
||||||
|
widgets = {
|
||||||
|
'author': forms.TextInput(attrs={
|
||||||
|
'placeholder': _('your name'),
|
||||||
|
}),
|
||||||
|
'email': forms.TextInput(attrs={
|
||||||
|
'placeholder': _('your email (optional)'),
|
||||||
|
}),
|
||||||
|
'url': forms.URLInput(attrs={
|
||||||
|
'placeholder': _('your website (optional)'),
|
||||||
|
}),
|
||||||
|
'comment': forms.TextInput(attrs={
|
||||||
|
'placeholder': _('your lovely comment'),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.request = kwargs.pop('request', None)
|
||||||
|
self.thread = kwargs.pop('object', None)
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
super().clean()
|
||||||
|
if self.request:
|
||||||
|
if verify_honeypot_value(self.request, 'hp_website'):
|
||||||
|
raise ValidationError(_('You are a bot, that is not cool'))
|
||||||
|
|
||||||
|
if not self.object:
|
||||||
|
raise ValidationError(_('No publication found for this comment'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
22
cms/utils.py
Normal file
22
cms/utils.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import aircox.cms.routes as routes
|
||||||
|
|
||||||
|
def tags_to_html(model, tags, sep = ', '):
|
||||||
|
"""
|
||||||
|
Render tags as string of HTML urls. `self` can be a class, but in
|
||||||
|
this case, it `tags` must be provided.
|
||||||
|
|
||||||
|
tags must be an iterator on taggit's Tag models (or similar)
|
||||||
|
|
||||||
|
"""
|
||||||
|
website = model._website
|
||||||
|
r = []
|
||||||
|
for tag in tags:
|
||||||
|
url = website.reverse(model, routes.TagsRoute, tags = tag.slug)
|
||||||
|
if url:
|
||||||
|
r.append('<a href="{url}">{name}</a>'.format(
|
||||||
|
url = url, name = tag.name)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
r.append(tag.name)
|
||||||
|
return sep.join(r)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user