Created
October 6, 2011 22:39
-
-
Save ciferkey/1268910 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#In r2/config/routing.py | |
def make_map(global_conf={}, app_conf={}): | |
#Some other routing location | |
mc('/submit', controller='front', action='submit') | |
#So I need to go to /r2/controllers/front.py and find the GET_submit method (by Pylons naming convention) | |
from r2.lib.utils import query_string, UrlParser, link_from_url, link_duplicates | |
#tons of stuff | |
def GET_submit(self, url, title, then): | |
"""Submit form.""" | |
if url and not request.get.get('resubmit'): | |
links = link_from_url(url) | |
#So I need to go to /r2/lib/utils/utils.py and find the link_from_url method. | |
def link_from_url(path, filter_spam = False, multiple = True): | |
from pylons import c | |
from r2.models import IDBuilder, Link, Subreddit, NotFound | |
if not path: | |
return | |
try: | |
links = Link._by_url(path, c.site) | |
#So I need to go to /r2/models/link.py and find the _by_url method... | |
@classmethod | |
def _by_url(cls, url, sr): | |
from subreddit import FakeSubreddit | |
if isinstance(sr, FakeSubreddit): | |
sr = None | |
try: | |
lbu = LinksByUrl._byID(LinksByUrl._key_from_url(url)) | |
#Which leads me to the method _key_from_url in the class LinksByUrl in r2/models/link.py | |
class LinksByUrl(tdb_cassandra.View): | |
_use_db = True | |
@classmethod | |
def _key_from_url(cls, url): | |
if not utils.domain(url) in g.case_sensitive_domains: | |
keyurl = _force_utf8(UrlParser.base_url(url.lower())) | |
else: | |
# Convert only hostname to lowercase | |
up = UrlParser(url) | |
up.hostname = up.hostname.lower() | |
keyurl = _force_utf8(UrlParser.base_url(up.unparse())) | |
return keyurl | |
#Which calles a method from UrlParser. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment