コード例 #1
0
    def GET_policy_page(self, page, requested_rev):
        if c.render_style == 'compact':
            self.redirect('/wiki/' + page)
        if page == 'privacypolicy':
            wiki_name = g.wiki_page_privacy_policy
            pagename = _('privacy policy')
        elif page == 'useragreement':
            wiki_name = g.wiki_page_user_agreement
            pagename = _('user agreement')
        elif page == 'contentpolicy':
            wiki_name = g.wiki_page_content_policy
            pagename = _('content policy')
        else:
            abort(404)

        wp = WikiPage.get(Frontpage, wiki_name)

        revs = list(wp.get_revisions())

        # collapse minor edits into revisions with reasons
        rev_info = []
        last_edit = None
        for rev in revs:
            if rev.is_hidden:
                continue

            if not last_edit:
                last_edit = rev

            if rev._get('reason'):
                rev_info.append({
                    'id': str(last_edit._id),
                    'title': rev._get('reason'),
                })
                last_edit = None

        if requested_rev:
            try:
                display_rev = WikiRevision.get(requested_rev, wp._id)
            except (tdb_cassandra.NotFound, WikiBadRevision):
                abort(404)
        else:
            display_rev = revs[0]

        doc_html = wikimarkdown(display_rev.content, include_toc=False)
        soup = BeautifulSoup(doc_html.decode('utf-8'))
        toc = generate_table_of_contents(soup, prefix='section')
        self._number_sections(soup)
        self._linkify_headings(soup)

        content = PolicyView(
            body_html=unsafe(soup),
            toc_html=unsafe(toc),
            revs=rev_info,
            display_rev=str(display_rev._id),
        )
        return PolicyPage(
            pagename=pagename,
            content=content,
        ).render()
コード例 #2
0
    def __init__(self,
                 content,
                 edit_by,
                 edit_date,
                 may_revise=False,
                 page=None,
                 diff=None,
                 renderer='wiki',
                 sr_path=True):
        self.page_content_md = content
        if renderer == 'wiki':
            self.page_content = wikimarkdown(content)
        elif renderer == 'reddit':
            self.page_content = safemarkdown(content)
        elif renderer == 'stylesheet':
            self.page_content = SubredditStylesheetSource(content).render()
        elif renderer == "automoderator":
            self.page_content = AutoModeratorConfig(content).render()
        elif renderer == "rawcode":
            self.page_content = RawCode(content).render()

        self.renderer = renderer
        self.page = page
        self.diff = diff
        self.edit_by = edit_by
        self.may_revise = may_revise
        self.edit_date = edit_date
        self.base_url = c.wiki_base_url
        self.sr_path = sr_path
        Templated.__init__(self)
コード例 #3
0
ファイル: wiki.py プロジェクト: Anenome/reddit
 def __init__(self, content, edit_by, edit_date, diff=None):
     self.page_content = wikimarkdown(content) if content else ''
     self.page_content_md = content
     self.diff = diff
     self.edit_by = edit_by
     self.edit_date = edit_date
     self.base_url = c.wiki_base_url
     self.may_revise = this_may_revise(c.page_obj)
     Templated.__init__(self)
コード例 #4
0
 def __init__(self, content, edit_by, edit_date, diff=None):
     self.page_content = wikimarkdown(content) if content else ''
     self.page_content_md = content
     self.diff = diff
     self.edit_by = edit_by
     self.edit_date = edit_date
     self.base_url = c.wiki_base_url
     self.may_revise = this_may_revise(c.page_obj)
     Templated.__init__(self)
コード例 #5
0
ファイル: jsontemplates.py プロジェクト: dkuznetsov/reddit
 def data(self, thing):
     edit_date = time.mktime(thing.edit_date.timetuple()) if thing.edit_date else None
     edit_by = None
     if thing.edit_by and not thing.edit_by._deleted:
          edit_by = Wrapped(thing.edit_by).render()
     return dict(content_md=thing.page_content_md,
                 content_html=wikimarkdown(thing.page_content_md),
                 revision_by=edit_by,
                 revision_date=edit_date,
                 may_revise=thing.may_revise)
コード例 #6
0
ファイル: jsontemplates.py プロジェクト: wal-f/reddit
 def data(self, thing):
     edit_date = time.mktime(thing.edit_date.timetuple()) if thing.edit_date else None
     edit_by = None
     if thing.edit_by and not thing.edit_by._deleted:
          edit_by = Wrapped(thing.edit_by).render()
     return dict(content_md=thing.page_content_md,
                 content_html=wikimarkdown(thing.page_content_md),
                 revision_by=edit_by,
                 revision_date=edit_date,
                 may_revise=thing.may_revise)
コード例 #7
0
ファイル: wiki.py プロジェクト: SovietMan/reddit
 def __init__(self, content, edit_by, edit_date, may_revise=False, page=None, diff=None, renderer="wiki"):
     self.page_content_md = content
     if renderer == "wiki":
         self.page_content = wikimarkdown(content)
     elif renderer == "reddit":
         self.page_content = safemarkdown(content)
     elif renderer == "stylesheet":
         self.page_content = SubredditStylesheetSource(content).render()
     self.renderer = renderer
     self.page = page
     self.diff = diff
     self.edit_by = edit_by
     self.may_revise = may_revise
     self.edit_date = edit_date
     self.base_url = c.wiki_base_url
     Templated.__init__(self)
コード例 #8
0
 def __init__(self, content, edit_by, edit_date, may_revise=False,
              page=None, diff=None, renderer='wiki'):
     self.page_content_md = content
     if renderer == 'wiki':
         self.page_content = wikimarkdown(content)
     elif renderer == 'reddit':
         self.page_content = safemarkdown(content)
     elif renderer == 'stylesheet':
         self.page_content = SubredditStylesheetSource(content).render()
     self.renderer = renderer
     self.page = page
     self.diff = diff
     self.edit_by = edit_by
     self.may_revise = may_revise
     self.edit_date = edit_date
     self.base_url = c.wiki_base_url
     Templated.__init__(self)
コード例 #9
0
ファイル: wiki.py プロジェクト: APerson241/reddit
 def __init__(self, content, edit_by, edit_date, may_revise=False,
              page=None, diff=None, renderer='wiki'):
     self.page_content_md = content
     if renderer == 'wiki':
         self.page_content = wikimarkdown(content)
     elif renderer == 'reddit':
         self.page_content = safemarkdown(content)
     elif renderer == 'stylesheet':
         self.page_content = SubredditStylesheetSource(content).render()
     elif renderer == "automoderator":
         self.page_content = AutoModeratorConfig(content).render()
     self.renderer = renderer
     self.page = page
     self.diff = diff
     self.edit_by = edit_by
     self.may_revise = may_revise
     self.edit_date = edit_date
     self.base_url = c.wiki_base_url
     Templated.__init__(self)