# Path: raggregate/queries/submission.py
# def get_story_list(page_num = 1, per_page = 30, sort = 'new', request = None, self_only = False, section = None):
# def get_story_by_id(id):
# def get_story_by_url_oldest(url):
# def update_story_vote_tally(story_id):
# def get_endpoints_from_page_num(page_num, per_page):
# def get_comments(id, organize_parentage = False, page_num = 1, per_page = 30, sort = 'new', target = 'story', target_id = None):
# def _build_comment_trees(all_comments, allowed_roots):
# def count_comment_children(comment_id):
# def get_comment_parent_story(id):
# def get_comment_by_id(id):
# def get_recent_comments(num):
# def get_story_id_from_slug(slug):
# 
# Path: raggregate/models/submission.py
# class Submission(Base):
#     __tablename__ = 'submissions'
#     id = Column(GUID, primary_key=True)
#     title = Column(UnicodeText, nullable=False)
#     description = Column(UnicodeText)
#     points = Column(Integer)
#     comment_tally = Column(Integer)
#     category = Column(GUID)
#     url = Column(UnicodeText)
#     self_post = Column(Boolean)
#     slug = Column(UnicodeText, unique=True)
#     added_on = Column(DateTime(timezone=True), default=sqlalchemy.sql.func.now())
#     added_by = Column(GUID, ForeignKey('users.id'), nullable=False)
#     deleted = Column(Boolean, default=False)
#     invisible = Column(Boolean, default=False)
#     hot_window_score = Column(Integer, default=None)
#     hot_window_score_timestamp = Column(DateTime(timezone=True), default=None)
#     downvote_tally = Column(Integer, default=None)
#     downvote_tally_timestamp = Column(DateTime(timezone=True), default=None)
#     upvote_tally = Column(Integer, default=None)
#     upvote_tally_timestamp = Column(DateTime(timezone=True), default=None)
#     total_vote_tally = Column(Integer)
#     total_vote_timestamp = Column(DateTime(timezone=True), default=None)
#     section = Column(GUID, ForeignKey('sections.id'), nullable=True)
#     render_type = Column(UnicodeText, default='story_md')
# 
#     submitter = relationship("User", backref="submissions")
#     votes = relationship("Vote", cascade="all, delete, delete-orphan")
# 
#     def __init__(self, title, description, url, user_id, slug = None, section = None,
#                  render_type = None):
#         self.title = title
#         self.description = description
#         self.url = url
#         self.added_by = user_id
#         self.slug = slug
#         self.section = section
#         self.render_type = render_type
# 
#         if url is None:
#             self.self_post = True
#         else:
#             self.self_post = False
# 
#     def tally_votes(self):
#         votes = DBSession.query(Vote).filter(Vote.submission_id == self.id).filter(Vote.comment_id == None).all()
#         tally = 0
#         for v in votes:
#             tally += v.points
#         if self.points != tally:
#             self.points = tally
#         return votes
# 
#     def tally_comments(self):
#         comments = DBSession.query(Comment).filter(Comment.submission_id == self.id).filter(Comment.body != '[deleted]').count()
#         self.comment_tally = comments
#         return comments
# 
#     def get_domain_name(self):
#         if self.url:
#             dn = urlparse.urlparse(self.url).netloc
# 
#             # replace preceding www. if it appears
#             if 'www.' in dn[0:4]:
#                 dn = dn.replace('www.', '', 1)
# 
#             return dn
#         else:
#             return ''


import markdown
import queries
from raggregate.queries import submission
from raggregate.models.submission import Submission



md = markdown.Markdown( safe_mode='escape', )

def render_md(s):
    if s:
        return md.convert(s)
    else:
        return ""

def none_as_blank(s):
    """ Make it simple to display empty values as None. """
    if s == '' or s == 'None':
        return ""
    else:
        return s

def get_submission_identifier_for_url(s):
    if s.__class__ != Submission:

# Path: raggregate/queries/submission.py
# def get_story_list(page_num = 1, per_page = 30, sort = 'new', request = None, self_only = False, section = None):
# def get_story_by_id(id):
# def get_story_by_url_oldest(url):
# def update_story_vote_tally(story_id):
# def get_endpoints_from_page_num(page_num, per_page):
# def get_comments(id, organize_parentage = False, page_num = 1, per_page = 30, sort = 'new', target = 'story', target_id = None):
# def _build_comment_trees(all_comments, allowed_roots):
# def count_comment_children(comment_id):
# def get_comment_parent_story(id):
# def get_comment_by_id(id):
# def get_recent_comments(num):
# def get_story_id_from_slug(slug):
# 
# Path: raggregate/models/submission.py
# class Submission(Base):
#     __tablename__ = 'submissions'
#     id = Column(GUID, primary_key=True)
#     title = Column(UnicodeText, nullable=False)
#     description = Column(UnicodeText)
#     points = Column(Integer)
#     comment_tally = Column(Integer)
#     category = Column(GUID)
#     url = Column(UnicodeText)
#     self_post = Column(Boolean)
#     slug = Column(UnicodeText, unique=True)
#     added_on = Column(DateTime(timezone=True), default=sqlalchemy.sql.func.now())
#     added_by = Column(GUID, ForeignKey('users.id'), nullable=False)
#     deleted = Column(Boolean, default=False)
#     invisible = Column(Boolean, default=False)
#     hot_window_score = Column(Integer, default=None)
#     hot_window_score_timestamp = Column(DateTime(timezone=True), default=None)
#     downvote_tally = Column(Integer, default=None)
#     downvote_tally_timestamp = Column(DateTime(timezone=True), default=None)
#     upvote_tally = Column(Integer, default=None)
#     upvote_tally_timestamp = Column(DateTime(timezone=True), default=None)
#     total_vote_tally = Column(Integer)
#     total_vote_timestamp = Column(DateTime(timezone=True), default=None)
#     section = Column(GUID, ForeignKey('sections.id'), nullable=True)
#     render_type = Column(UnicodeText, default='story_md')
# 
#     submitter = relationship("User", backref="submissions")
#     votes = relationship("Vote", cascade="all, delete, delete-orphan")
# 
#     def __init__(self, title, description, url, user_id, slug = None, section = None,
#                  render_type = None):
#         self.title = title
#         self.description = description
#         self.url = url
#         self.added_by = user_id
#         self.slug = slug
#         self.section = section
#         self.render_type = render_type
# 
#         if url is None:
#             self.self_post = True
#         else:
#             self.self_post = False
# 
#     def tally_votes(self):
#         votes = DBSession.query(Vote).filter(Vote.submission_id == self.id).filter(Vote.comment_id == None).all()
#         tally = 0
#         for v in votes:
#             tally += v.points
#         if self.points != tally:
#             self.points = tally
#         return votes
# 
#     def tally_comments(self):
#         comments = DBSession.query(Comment).filter(Comment.submission_id == self.id).filter(Comment.body != '[deleted]').count()
#         self.comment_tally = comments
#         return comments
# 
#     def get_domain_name(self):
#         if self.url:
#             dn = urlparse.urlparse(self.url).netloc
# 
#             # replace preceding www. if it appears
#             if 'www.' in dn[0:4]:
#                 dn = dn.replace('www.', '', 1)
# 
#             return dn
#         else:
#             return ''


# Path: raggregate/template_filters.py
import markdown
import queries
from raggregate.queries import submission
from raggregate.models.submission import Submission




md = markdown.Markdown( safe_mode='escape', )

def render_md(s):
    if s:
        return md.convert(s)
    else:
        return ""

def none_as_blank(s):
    """ Make it simple to display empty values as None. """
    if s == '' or s == 'None':
        return ""
    else:
        return s

def get_submission_identifier_for_url(s):
    if s.__class__ != Submission:

        s = submission.get_story_by_id(s)