def get_subdigg(self): """checks if the current url refers to a subdigg and returns that subdigg object. The cases here are: * the hostname is unset or is g.domain, in which case it looks for /r/XXXX or /diggs. The default in this case is Default. * the hostname is a cname to a known subdigg. On failure to find a subdigg, returns None. """ from pylons import g from r2.models import Subdigg, Sub, NotFound, Default try: if not self.hostname or self.hostname.startswith(g.domain): if self.path.startswith('/r/'): return Subdigg._by_name(self.path.split('/')[2]) elif self.path.startswith('/diggs/'): return Sub else: return Default elif self.hostname: return Subdigg._by_domain(self.hostname) except NotFound: pass return None