Exemplo n.º 1
0
    def make_permalink(self, sr, force_domain = False,criticism=False):
        from r2.lib.template_helpers import get_domain
	if criticism:
        	p = "criticisms/%s/%s/" % (self._id36, title_to_url(self.title))
	else:
        	p = "comments/%s/%s/" % (self._id36, title_to_url(self.title))
        # promoted links belong to a separate subsciteit and shouldn't
        # include that in the path
        if self.promoted is not None:
            if force_domain:
                res = "http://%s/%s" % (get_domain(cname = False,
                                                   subsciteit = False), p)
            else:
                res = "/%s" % p
        elif not c.cname and not force_domain:
            res = "/r/%s/%s" % (sr.name, p)
        elif sr != c.site or force_domain:
            if(c.cname and sr == c.site):
                res = "http://%s/%s" % (get_domain(cname = True,
                                                    subsciteit = False),p)
            else:
                res = "http://%s/r/%s/%s" % (get_domain(cname = False,
                                                    subsciteit = False),sr.name,p)
        else:
            res = "/%s" % p

        # WARNING: If we ever decide to add any ?foo=bar&blah parameters
        # here, Comment.make_permalink will need to be updated or else
        # it will fail.

        return res
Exemplo n.º 2
0
    def GET_oldinfo(self, article, type, dest, rest=None, comment=''):
        """Legacy: supporting permalink pages from '06,
           and non-search-engine-friendly links"""
        if not (dest in ('comments','related','details')):
                dest = 'comments'
        if type == 'ancient':
            #this could go in config, but it should never change
            max_link_id = 10000000
            new_id = max_link_id - int(article._id)
            return self.redirect('/info/' + to36(new_id) + '/' + rest)
        if type == 'old':
            new_url = "/%s/%s/%s" % \
                      (dest, article._id36, 
                       quote_plus(title_to_url(article.title).encode('utf-8')))
            if not c.default_sr:
                new_url = "/r/%s%s" % (c.site.name, new_url)
            if comment:
                new_url = new_url + "/%s" % comment._id36
            if c.extension:
                new_url = new_url + "/.%s" % c.extension

            new_url = new_url + query_string(request.get)

            # redirect should be smarter and handle extensions, etc.
            return self.redirect(new_url, code=301)
Exemplo n.º 3
0
    def GET_oldinfo(self, article, type, dest, rest=None, comment=''):
        """Legacy: supporting permalink pages from '06,
           and non-search-engine-friendly links"""
        if not (dest in ('comments', 'related', 'details')):
            dest = 'comments'
        if type == 'ancient':
            #this could go in config, but it should never change
            max_link_id = 10000000
            new_id = max_link_id - int(article._id)
            return self.redirect('/info/' + to36(new_id) + '/' + rest)
        if type == 'old':
            new_url = "/%s/%s/%s" % \
                      (dest, article._id36,
                       quote_plus(title_to_url(article.title).encode('utf-8')))
            if not c.default_sr:
                new_url = "/r/%s%s" % (c.site.name, new_url)
            if comment:
                new_url = new_url + "/%s" % comment._id36
            if c.extension:
                new_url = new_url + "/.%s" % c.extension

            new_url = new_url + query_string(request.get)

            # redirect should be smarter and handle extensions, etc.
            return self.redirect(new_url, code=301)
Exemplo n.º 4
0
    def make_permalink(self, sr, force_domain=False):
        from r2.lib.template_helpers import get_domain
        p = "comments/%s/%s/" % (self._id36, title_to_url(self.title))
        # promoted links belong to a separate subreddit and shouldn't
        # include that in the path
        if self.promoted is not None:
            if force_domain:
                res = "http://%s/%s" % (get_domain(cname=False,
                                                   subreddit=False), p)
            else:
                res = "/%s" % p
        elif not c.cname and not force_domain:
            res = "/r/%s/%s" % (sr.name, p)
        elif sr != c.site or force_domain:
            if (c.cname and sr == c.site):
                res = "http://%s/%s" % (get_domain(cname=True,
                                                   subreddit=False), p)
            else:
                res = "http://%s/r/%s/%s" % (get_domain(
                    cname=False, subreddit=False), sr.name, p)
        else:
            res = "/%s" % p

        # WARNING: If we ever decide to add any ?foo=bar&blah parameters
        # here, Comment.make_permalink will need to be updated or else
        # it will fail.

        return res
Exemplo n.º 5
0
def _comment_page_links(comment_page_data):
    for comment_info in comment_page_data:
        path = u"/r/{0}/comments/{1}/{2}/".format(
            comment_info.subreddit,
            to36(int(comment_info.thing_id)),
            urllib.quote(title_to_url(comment_info.title).encode("utf-8")),
        )
        yield _absolute_url(path)
Exemplo n.º 6
0
Arquivo: link.py Projeto: vin/reddit
 def make_permalink(self, sr, force_domain = False):
     from r2.lib.template_helpers import get_domain
     p = "comments/%s/%s/" % (self._id36, title_to_url(self.title))
     if not c.cname:
         res = "/r/%s/%s" % (sr.name, p)
     elif sr != c.site or force_domain:
         res = "http://%s/%s" % (get_domain(cname = (c.cname and sr == c.site),
                                            subreddit = not c.cname), p)
     else:
         res = "/%s" % p
     return res
Exemplo n.º 7
0
 def make_permalink(self, sr, force_domain=False, sr_path=False):
     from r2.lib.template_helpers import get_domain
     p = "lw/%s/%s/" % (self._id36, title_to_url(self.title))
     if c.default_sr and not sr_path:
         res = "/%s" % p
     elif sr and not c.cname:
         res = "/r/%s/%s" % (sr.name, p)
     elif sr != c.site or force_domain:
         res = "http://%s/%s" % (get_domain(
             cname=(c.cname and sr == c.site), subreddit=not c.cname), p)
     else:
         res = "/%s" % p
     return res
Exemplo n.º 8
0
        def slug():
            """
            Retrieves the original URL slug (if any) to prevent the
            URL from changing when the article title is updated.
            """
            # This could probably just check for `self.url == None`.
            if not isinstance(self.url, basestring):
                return self.title

            regex = re.compile("""
              /ea                   # subreddit
              /[^/]+                # ID
              /(?P<title>[^/]+)/    # title
            """, re.X)
            match = regex.match(self.url)
            if match:
                return match.group("title")
            else:
                return title_to_url(self.title)
Exemplo n.º 9
0
Arquivo: pages.py Projeto: vin/reddit
    def build_toolbars(self):
        base_path = "/%s/%s/" % (self.link._id36, title_to_url(self.link.title))
        if isinstance(base_path, unicode):
            base_path = base_path.encode('utf-8')
        def info_button(name):
            return NamedButton(name, dest = '/%s%s' % (name, base_path),
                               aliases = ['/%s/%s' % (name, self.link._id36)])
        
        buttons = [info_button('comments'),
                   info_button('related')]

        if c.user_is_admin:
            buttons += [info_button('details')]

        toolbar = [NavMenu(buttons, base_path = "", type="tabmenu")]

        if c.site != Default and not c.cname:
            toolbar.insert(0, PageNameNav('subreddit'))

        return toolbar
Exemplo n.º 10
0
        def slug():
            """
            Retrieves the original URL slug (if any) to prevent the
            URL from changing when the article title is updated.
            """
            # This could probably just check for `self.url == None`.
            if not isinstance(self.url, basestring):
                return self.title

            regex = re.compile(
                """
              /ea                   # subreddit
              /[^/]+                # ID
              /(?P<title>[^/]+)/    # title
            """, re.X)
            match = regex.match(self.url)
            if match:
                return match.group("title")
            else:
                return title_to_url(self.title)
Exemplo n.º 11
0
 def canonical_url(self):
     from r2.lib.template_helpers import get_domain
     p = "lw/%s/%s/" % (self._id36, title_to_url(self.title))
     return "http://%s/%s" % (get_domain(subreddit = False), p)
Exemplo n.º 12
0
def _comment_page_links(comment_page_data):
    for comment_info in comment_page_data:
        path = u'/r/{0}/comments/{1}/{2}/'.format(
            comment_info.subreddit, to36(int(comment_info.thing_id)),
            urllib.quote(title_to_url(comment_info.title).encode('utf-8')))
        yield _absolute_url(path)
Exemplo n.º 13
0
 def canonical_url(self):
     from r2.lib.template_helpers import get_domain
     p = "lw/%s/%s/" % (self._id36, title_to_url(self.title))
     return "http://%s/%s" % (get_domain(subreddit=False), p)