# Path: forum/models.py
# class Node(models.Model):
#     section = models.ForeignKey(Section, on_delete=models.PROTECT, related_name='nodes')
#     name = models.CharField(max_length=32, unique=True, blank=False, null=False)
#     description = models.TextField(blank=False, null=False)
#     icon_raw = models.ImageField("Node's icon", upload_to='upload/node/%Y%m%d', blank=True, null=True, default="")
#     icon_l = models.ImageField("large icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     icon_m = models.ImageField("medium icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     icon_s = models.ImageField("small icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     order = models.IntegerField(default=0)
#     is_trash = models.BooleanField(default=False)
#     date_created = models.DateTimeField(auto_now_add=True)
#     last_modified = models.DateTimeField(auto_now=True, blank=True, null=True)
#     watcher = models.ManyToManyField(User, blank=True, related_name='watch_nodes')
#     
#     class Meta():
#         ordering = ['section', '-order']
#     
#     def __str__(self):
#         return "%s/%s" % (self.section.name, self.name)
#     
#     def admin_image(self):
#         if self.icon_s:
#             return '<img src="/media/%s" width="24" height="24" />' % (self.icon_s)
#         else:
#             return None
#     admin_image.allow_tags = True
#     admin_image.short_description = 'Icon'


from django import forms
from django.utils.translation import ugettext_lazy as _
from forum.models import Node

class TopicForm(forms.Form):
    title = forms.CharField(label=_("Topic title"), max_length=120,
        widget=forms.TextInput(attrs={'placeholder': _('Topic title')}),
        error_messages={'required': _("title can't be blank"),
                        'max_length': _('The title should be no longer than 120 characters')})
    content = forms.CharField(widget=forms.Textarea(attrs={'rows':4, 'placeholder': _('Say something')}),
        error_messages={'required': _("content can't be blank")})
    node = forms.ModelChoiceField(queryset=Node.objects.all(), empty_label=_('---- select a node ----'),
        error_messages={'required': _("node can't be blank"), 'invalid_choice': _("invalid choice")})


# Path: forum/models.py
# class Node(models.Model):
#     section = models.ForeignKey(Section, on_delete=models.PROTECT, related_name='nodes')
#     name = models.CharField(max_length=32, unique=True, blank=False, null=False)
#     description = models.TextField(blank=False, null=False)
#     icon_raw = models.ImageField("Node's icon", upload_to='upload/node/%Y%m%d', blank=True, null=True, default="")
#     icon_l = models.ImageField("large icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     icon_m = models.ImageField("medium icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     icon_s = models.ImageField("small icon", upload_to='node/%Y%m%d', blank=True, null=True, default="")
#     order = models.IntegerField(default=0)
#     is_trash = models.BooleanField(default=False)
#     date_created = models.DateTimeField(auto_now_add=True)
#     last_modified = models.DateTimeField(auto_now=True, blank=True, null=True)
#     watcher = models.ManyToManyField(User, blank=True, related_name='watch_nodes')
#     
#     class Meta():
#         ordering = ['section', '-order']
#     
#     def __str__(self):
#         return "%s/%s" % (self.section.name, self.name)
#     
#     def admin_image(self):
#         if self.icon_s:
#             return '<img src="/media/%s" width="24" height="24" />' % (self.icon_s)
#         else:
#             return None
#     admin_image.allow_tags = True
#     admin_image.short_description = 'Icon'


# Path: forum/forms.py
from django import forms
from django.utils.translation import ugettext_lazy as _
from forum.models import Node


class TopicForm(forms.Form):
    title = forms.CharField(label=_("Topic title"), max_length=120,
        widget=forms.TextInput(attrs={'placeholder': _('Topic title')}),
        error_messages={'required': _("title can't be blank"),
                        'max_length': _('The title should be no longer than 120 characters')})
    content = forms.CharField(widget=forms.Textarea(attrs={'rows':4, 'placeholder': _('Say something')}),
        error_messages={'required': _("content can't be blank")})
    node = forms.ModelChoiceField(queryset=Node.objects.all(), empty_label=_('---- select a node ----'),
        error_messages={'required': _("node can't be blank"), 'invalid_choice': _("invalid choice")})


class ReplyForm(forms.Form):