# Path: blango/models.py
# class Comment(models.Model):
#     COMMENT_TYPES = [
#         ('C', _('comment')),
#         ('T', _('trackback')),
#         ('P', _('pingback')),
#     ]
#     entry = models.ForeignKey(Entry)
#     author = models.CharField(_('Name'), max_length=256, blank=True)
#     author_uri = models.CharField(_('Website'), max_length=256, blank=True)
#     author_email = models.EmailField(_('Email'), blank=True)
#     body = models.TextField(_('Comment'), max_length=1000)
#     submitted = models.DateTimeField(default=datetime.now)
#     type = models.CharField(_('Comment type'), max_length=1, choices=COMMENT_TYPES, default='C')
#     user = models.ForeignKey(User, default=None, null=True, blank=True)
# 
#     class Meta:
#         verbose_name = _('comment')
#         verbose_name_plural = _('comments')
# 
#     def save(self, *args, **kwargs):
#         if self.author_uri and \
#                 not self.author_uri.startswith('http://') and \
#                 not self.author_uri.startswith('https://'):
#             self.author_uri = 'http://%s' % self.author_uri
#         super(Comment, self).save(*args, **kwargs)
# 
#     def get_absolute_url(self):
#         position = Comment.objects.filter(entry=self.entry, submitted__lt=self.submitted).count() + 1
#         return settings.BLANGO_URL + 'entry/%s/#comment-%d' % (self.entry.slug, position)
# 
#     def __unicode__(self):
#         return self.body
# 
#     @property
#     def author_name(self):
#         if self.user is not None:
#             return self.user.username
# 
#         return self.author
# 
#     @property
#     def author_link(self):
#         if self.user is not None:
#             return mark_safe('<a href="%s">%s</a>' % \
#                     (settings.BLANGO_URL, self.author_name))
# 
#         if self.author_uri:
#             return mark_safe('<a rel="external nofollow" href="%s">%s</a>' % \
#                     (self.author_uri, force_escape(self.author_name)))
# 
#         return mark_safe(force_escape(self.author))
# 
#     @property
#     def web_title(self):
#         return mark_safe('%s %s %s' % \
#             (capfirst(ugettext(self.get_type_display())), ugettext('by'), self.author_link))
# 
#     @property
#     def title(self):
#         return mark_safe('%s %s %s' % \
#             (capfirst(ugettext(self.get_type_display())), ugettext('by'), self.author_name))
# 
#     @property
#     def description(self):
#         return self.body
# 
#     @short_description('author')
#     def formatted_author(self):
#         if self.user is not None:
#             return ('%s <%s>' % (self.user.username, self.user.email))
#         return ('%s <%s>' % (self.author, self.author_email))
# 
# Path: blango/jsforms.py
# class JSModelForm(forms.ModelForm):
#     js = forms.CharField(required=False, max_length=32, widget=JSHiddenInput())
#     js2 = forms.CharField(max_length=32, widget=JSHiddenCopyInput(), required=False)
#     def __init__(self, *args, **kwargs):
#         super(JSModelForm, self).__init__(*args, **kwargs)
#         initialize_js_form(self)
# 
#     def clean(self):
#         return clean_js_form(self)


from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
from django.contrib.auth.models import User
from django import forms
from blango.models import Comment
from blango.jsforms import JSModelForm


# This violates the DRY principe, but it's the only
# way I found for editing staff comments from
# the Django admin application

class CommentForm(JSModelForm):
    author = forms.CharField(label=_('Name'), max_length=256)
    author_uri = forms.CharField(label=_('Website'), max_length=256, required=False)
    author_email = forms.EmailField(label=_('Email'), help_text=mark_safe('<span class="small">%s</span>' % _('(Won\'t be published)')))

    class Meta:
        model = Comment
        fields = ('author', 'author_uri', 'author_email', 'body')

    def save(self, entry):
        self.instance.entry = entry
        super(CommentForm, self).save()

    def clean_author(self):
        author = self.cleaned_data['author']
        try:
            User.objects.get(username=author)
            raise forms.ValidationError(_('This username belongs to a registered user'))
        except User.DoesNotExist:
            return author


class UserCommentForm(forms.ModelForm):
    class Meta:

# Path: blango/models.py
# class Comment(models.Model):
#     COMMENT_TYPES = [
#         ('C', _('comment')),
#         ('T', _('trackback')),
#         ('P', _('pingback')),
#     ]
#     entry = models.ForeignKey(Entry)
#     author = models.CharField(_('Name'), max_length=256, blank=True)
#     author_uri = models.CharField(_('Website'), max_length=256, blank=True)
#     author_email = models.EmailField(_('Email'), blank=True)
#     body = models.TextField(_('Comment'), max_length=1000)
#     submitted = models.DateTimeField(default=datetime.now)
#     type = models.CharField(_('Comment type'), max_length=1, choices=COMMENT_TYPES, default='C')
#     user = models.ForeignKey(User, default=None, null=True, blank=True)
# 
#     class Meta:
#         verbose_name = _('comment')
#         verbose_name_plural = _('comments')
# 
#     def save(self, *args, **kwargs):
#         if self.author_uri and \
#                 not self.author_uri.startswith('http://') and \
#                 not self.author_uri.startswith('https://'):
#             self.author_uri = 'http://%s' % self.author_uri
#         super(Comment, self).save(*args, **kwargs)
# 
#     def get_absolute_url(self):
#         position = Comment.objects.filter(entry=self.entry, submitted__lt=self.submitted).count() + 1
#         return settings.BLANGO_URL + 'entry/%s/#comment-%d' % (self.entry.slug, position)
# 
#     def __unicode__(self):
#         return self.body
# 
#     @property
#     def author_name(self):
#         if self.user is not None:
#             return self.user.username
# 
#         return self.author
# 
#     @property
#     def author_link(self):
#         if self.user is not None:
#             return mark_safe('<a href="%s">%s</a>' % \
#                     (settings.BLANGO_URL, self.author_name))
# 
#         if self.author_uri:
#             return mark_safe('<a rel="external nofollow" href="%s">%s</a>' % \
#                     (self.author_uri, force_escape(self.author_name)))
# 
#         return mark_safe(force_escape(self.author))
# 
#     @property
#     def web_title(self):
#         return mark_safe('%s %s %s' % \
#             (capfirst(ugettext(self.get_type_display())), ugettext('by'), self.author_link))
# 
#     @property
#     def title(self):
#         return mark_safe('%s %s %s' % \
#             (capfirst(ugettext(self.get_type_display())), ugettext('by'), self.author_name))
# 
#     @property
#     def description(self):
#         return self.body
# 
#     @short_description('author')
#     def formatted_author(self):
#         if self.user is not None:
#             return ('%s <%s>' % (self.user.username, self.user.email))
#         return ('%s <%s>' % (self.author, self.author_email))
# 
# Path: blango/jsforms.py
# class JSModelForm(forms.ModelForm):
#     js = forms.CharField(required=False, max_length=32, widget=JSHiddenInput())
#     js2 = forms.CharField(max_length=32, widget=JSHiddenCopyInput(), required=False)
#     def __init__(self, *args, **kwargs):
#         super(JSModelForm, self).__init__(*args, **kwargs)
#         initialize_js_form(self)
# 
#     def clean(self):
#         return clean_js_form(self)


# Path: blango/forms.py
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
from django.contrib.auth.models import User
from django import forms
from blango.models import Comment
from blango.jsforms import JSModelForm



# This violates the DRY principe, but it's the only
# way I found for editing staff comments from
# the Django admin application

class CommentForm(JSModelForm):
    author = forms.CharField(label=_('Name'), max_length=256)
    author_uri = forms.CharField(label=_('Website'), max_length=256, required=False)
    author_email = forms.EmailField(label=_('Email'), help_text=mark_safe('<span class="small">%s</span>' % _('(Won\'t be published)')))

    class Meta:
        model = Comment
        fields = ('author', 'author_uri', 'author_email', 'body')

    def save(self, entry):
        self.instance.entry = entry
        super(CommentForm, self).save()

    def clean_author(self):
        author = self.cleaned_data['author']
        try:
            User.objects.get(username=author)
            raise forms.ValidationError(_('This username belongs to a registered user'))
        except User.DoesNotExist:
            return author


class UserCommentForm(forms.ModelForm):
    class Meta:

        model = Comment