# Path: dinette/libs/postmarkup.py
# def render_bbcode(bbcode,
#                   encoding="ascii",
#                   exclude_tags=None,
#                   auto_urls=True,
#                   paragraphs=False,
#                   clean=True,
#                   tag_data=None):
# 
#     """ Renders a bbcode string in to XHTML. This is a shortcut if you don't
#         need to customize any tags.
# 
#         post_markup -- String containing bbcode.
#         encoding -- Encoding of string, defaults to "ascii" if the string is not
#         already unicode.
#         exclude_tags -- A collection of tag names to ignore.
#         auto_urls -- If True, then urls will be wrapped with url bbcode tags.
#         paragraphs -- If True then line breaks will be replaces with paragraph
#         tags, rather than break tags.
#         clean -- If True, html will be run through a cleanup_html method.
#         tag_data -- An optional dictionary to store tag data in. The default of
#         None will create a dictionary internally.
# 
#     """
#     return _postmarkup(bbcode,
#                        encoding,
#                        exclude_tags=exclude_tags,
#                        auto_urls=auto_urls,
#                        paragraphs=paragraphs,
#                        clean=clean,
#                        tag_data=tag_data)


from django.db import models
from django.contrib.auth.models import User, Group
from django.conf import settings
from django.contrib.sites.models import Site
from django.template.defaultfilters import slugify
from django.db.models.signals import post_save
from django.template.defaultfilters import truncatewords
from django.core.urlresolvers import reverse
from BeautifulSoup import BeautifulSoup
from dinette.libs.postmarkup import render_bbcode
from markupfield.fields import MarkupField
        from django.conf import settings
import hashlib
import datetime
    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):            

# Path: dinette/libs/postmarkup.py
# def render_bbcode(bbcode,
#                   encoding="ascii",
#                   exclude_tags=None,
#                   auto_urls=True,
#                   paragraphs=False,
#                   clean=True,
#                   tag_data=None):
# 
#     """ Renders a bbcode string in to XHTML. This is a shortcut if you don't
#         need to customize any tags.
# 
#         post_markup -- String containing bbcode.
#         encoding -- Encoding of string, defaults to "ascii" if the string is not
#         already unicode.
#         exclude_tags -- A collection of tag names to ignore.
#         auto_urls -- If True, then urls will be wrapped with url bbcode tags.
#         paragraphs -- If True then line breaks will be replaces with paragraph
#         tags, rather than break tags.
#         clean -- If True, html will be run through a cleanup_html method.
#         tag_data -- An optional dictionary to store tag data in. The default of
#         None will create a dictionary internally.
# 
#     """
#     return _postmarkup(bbcode,
#                        encoding,
#                        exclude_tags=exclude_tags,
#                        auto_urls=auto_urls,
#                        paragraphs=paragraphs,
#                        clean=clean,
#                        tag_data=tag_data)


# Path: dinette/models.py
from django.db import models
from django.contrib.auth.models import User, Group
from django.conf import settings
from django.contrib.sites.models import Site
from django.template.defaultfilters import slugify
from django.db.models.signals import post_save
from django.template.defaultfilters import truncatewords
from django.core.urlresolvers import reverse
from BeautifulSoup import BeautifulSoup
from dinette.libs.postmarkup import render_bbcode
from markupfield.fields import MarkupField
        from django.conf import settings
import hashlib
import datetime

    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)