# Path: dinette/models.py
# class Ftopics(models.Model):
#     category = models.ForeignKey(Category)
#     posted_by = models.ForeignKey(User)
#     subject = models.CharField(max_length=999)
#     slug = models.SlugField(max_length = 200, db_index = True) 
#     message = MarkupField(default_markup_type=getattr(settings,
#                                                       'DEFAULT_MARKUP_TYPE',
#                                                       'markdown'),
#                           markup_choices=settings.MARKUP_RENDERERS,
#                           escape_html=True,
#                           )
#     file = models.FileField(upload_to='dinette/files',default='',null=True,blank=True)
#     attachment_type = models.CharField(max_length=20,default='nofile')
#     filename = models.CharField(max_length=100,default="dummyname.txt")
#     viewcount = models.IntegerField(default=0)
#     replies = models.IntegerField(default=0)    
#     created_on = models.DateTimeField(auto_now_add=True)
#     updated_on = models.DateTimeField(auto_now=True)
#     last_reply_on = models.DateTimeField(auto_now_add=True)
#     num_replies = models.PositiveSmallIntegerField(default = 0)
#     
#     #Moderation features
#     announcement_flag = models.BooleanField(default=False)
#     is_closed = models.BooleanField(default=False)
#     is_sticky = models.BooleanField(default=False)
#     is_hidden = models.BooleanField(default=False)
#     
#     # use TopicManager as default, prevent leaking of hidden topics
#     default = models.Manager()
#     objects = TopicManager()
# 
#     # for topic subscriptions
#     subscribers = models.ManyToManyField(User, related_name='subscribers')
#     
#     class Meta:
#         ordering = ('-is_sticky', '-last_reply_on',)
#         get_latest_by = ('created_on')
#         verbose_name = "Topic"
#         verbose_name_plural = "Topics"
#         
#     def save(self, *args, **kwargs):
#         if not self.slug:
#             slug = slugify(self.subject)
#             slug = slug[:198]
#             same_slug_count = Ftopics.objects.filter(slug__startswith = slug).count()
#             if same_slug_count:
#                 slug = slug + str(same_slug_count)
#             self.slug = slug
#         super(Ftopics, self).save(*args, **kwargs)
#         
#     def __unicode__(self):
#         return self.subject
#     
#     def get_absolute_url(self):
#         return reverse('dinette_topic_detail', kwargs={'categoryslug':self.category.slug, 'topic_slug': self.slug})
#     
#     def htmlfrombbcode(self):
#         if(len(self.message.raw.strip()) >  0):            
#             return render_bbcode(self.message.raw)
#         else :
#             return ""
#         
#     def search_snippet(self):
#         msg = "%s %s"% (self.subject, self.message.rendered)
#         return truncatewords(msg, 50) 
#         
#     def getTopicString(self):
#         #which is helpful for doing reverse lookup of an feed url for a topic         
#         return "topic/%s" % self.slug
#         
#     def lastPostDatetime(self):
#         return self.lastPost().created_on
#         
#     def lastPostedUser(self):
#         return self.lastPost().posted_by.username
#     
#     def lastPost(self):
#         if (self.reply_set.count() == 0):
#             return self       
#         return self.reply_set.order_by('-created_on')[0]        
#         
#     def classname(self):
#         return  self.__class__.__name__
# 
# class SiteConfig(models.Model):
#     name = models.CharField(max_length = 100)
#     tag_line = models.TextField(max_length = 100)
# 
# class NavLink(models.Model):
#     title = models.CharField(max_length = 100)
#     url = models.URLField()
#     
#     class Meta:
#         verbose_name = "Navigation Link"
#         verbose_name_plural = "Navigation Links"
#         
#     def __unicode__(self):
#         return self.title


from django import  template
from django.contrib.sites.models import Site
from django.conf import settings
from dinette.models import Ftopics, SiteConfig, NavLink
        except Ftopics.DoesNotExist:
            return ''

@register.tag
def get_announcement(parser, token):
    return GetAnnouncementNode.handle_token(parser, token)

class GetNavLinksNode(BaseDinetteNode):
    def __init__(self, as_varname='nav_links'):
        self.as_varname = as_varname

    def render(self, context):
        context[self.as_varname] = NavLink.objects.all()
        return ''

@register.tag
def get_forumwide_links(parser, token):
    return GetNavLinksNode.handle_token(parser, token)

@register.simple_tag
def get_site_name():
    try:
        config = SiteConfig.objects.get(id=1)
        return config.name
    except SiteConfig.DoesNotExist:
        return ''

@register.simple_tag
def get_site_tag_line():
    try:

# Path: dinette/models.py
# class Ftopics(models.Model):
#     category = models.ForeignKey(Category)
#     posted_by = models.ForeignKey(User)
#     subject = models.CharField(max_length=999)
#     slug = models.SlugField(max_length = 200, db_index = True) 
#     message = MarkupField(default_markup_type=getattr(settings,
#                                                       'DEFAULT_MARKUP_TYPE',
#                                                       'markdown'),
#                           markup_choices=settings.MARKUP_RENDERERS,
#                           escape_html=True,
#                           )
#     file = models.FileField(upload_to='dinette/files',default='',null=True,blank=True)
#     attachment_type = models.CharField(max_length=20,default='nofile')
#     filename = models.CharField(max_length=100,default="dummyname.txt")
#     viewcount = models.IntegerField(default=0)
#     replies = models.IntegerField(default=0)    
#     created_on = models.DateTimeField(auto_now_add=True)
#     updated_on = models.DateTimeField(auto_now=True)
#     last_reply_on = models.DateTimeField(auto_now_add=True)
#     num_replies = models.PositiveSmallIntegerField(default = 0)
#     
#     #Moderation features
#     announcement_flag = models.BooleanField(default=False)
#     is_closed = models.BooleanField(default=False)
#     is_sticky = models.BooleanField(default=False)
#     is_hidden = models.BooleanField(default=False)
#     
#     # use TopicManager as default, prevent leaking of hidden topics
#     default = models.Manager()
#     objects = TopicManager()
# 
#     # for topic subscriptions
#     subscribers = models.ManyToManyField(User, related_name='subscribers')
#     
#     class Meta:
#         ordering = ('-is_sticky', '-last_reply_on',)
#         get_latest_by = ('created_on')
#         verbose_name = "Topic"
#         verbose_name_plural = "Topics"
#         
#     def save(self, *args, **kwargs):
#         if not self.slug:
#             slug = slugify(self.subject)
#             slug = slug[:198]
#             same_slug_count = Ftopics.objects.filter(slug__startswith = slug).count()
#             if same_slug_count:
#                 slug = slug + str(same_slug_count)
#             self.slug = slug
#         super(Ftopics, self).save(*args, **kwargs)
#         
#     def __unicode__(self):
#         return self.subject
#     
#     def get_absolute_url(self):
#         return reverse('dinette_topic_detail', kwargs={'categoryslug':self.category.slug, 'topic_slug': self.slug})
#     
#     def htmlfrombbcode(self):
#         if(len(self.message.raw.strip()) >  0):            
#             return render_bbcode(self.message.raw)
#         else :
#             return ""
#         
#     def search_snippet(self):
#         msg = "%s %s"% (self.subject, self.message.rendered)
#         return truncatewords(msg, 50) 
#         
#     def getTopicString(self):
#         #which is helpful for doing reverse lookup of an feed url for a topic         
#         return "topic/%s" % self.slug
#         
#     def lastPostDatetime(self):
#         return self.lastPost().created_on
#         
#     def lastPostedUser(self):
#         return self.lastPost().posted_by.username
#     
#     def lastPost(self):
#         if (self.reply_set.count() == 0):
#             return self       
#         return self.reply_set.order_by('-created_on')[0]        
#         
#     def classname(self):
#         return  self.__class__.__name__
# 
# class SiteConfig(models.Model):
#     name = models.CharField(max_length = 100)
#     tag_line = models.TextField(max_length = 100)
# 
# class NavLink(models.Model):
#     title = models.CharField(max_length = 100)
#     url = models.URLField()
#     
#     class Meta:
#         verbose_name = "Navigation Link"
#         verbose_name_plural = "Navigation Links"
#         
#     def __unicode__(self):
#         return self.title


# Path: dinette/templatetags/dinette_tags.py
from django import  template
from django.contrib.sites.models import Site
from django.conf import settings
from dinette.models import Ftopics, SiteConfig, NavLink

        except Ftopics.DoesNotExist:
            return ''

@register.tag
def get_announcement(parser, token):
    return GetAnnouncementNode.handle_token(parser, token)

class GetNavLinksNode(BaseDinetteNode):
    def __init__(self, as_varname='nav_links'):
        self.as_varname = as_varname

    def render(self, context):
        context[self.as_varname] = NavLink.objects.all()
        return ''

@register.tag
def get_forumwide_links(parser, token):
    return GetNavLinksNode.handle_token(parser, token)

@register.simple_tag
def get_site_name():
    try:
        config = SiteConfig.objects.get(id=1)
        return config.name
    except SiteConfig.DoesNotExist:
        return ''

@register.simple_tag
def get_site_tag_line():
    try:

        config = SiteConfig.objects.get(id=1)