# 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
            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):

# 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

            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):