Пример #1
0
    def get_subsciteit(self):
        """checks if the current url refers to a subsciteit and returns
        that subsciteit object.  The cases here are:

          * the hostname is unset or is g.domain, in which case it
            looks for /r/XXXX or /sciteits.  The default in this case
            is Default.
          * the hostname is a cname to a known subsciteit.

        On failure to find a subsciteit, returns None.
        """
        from pylons import g
        from r2.models import Subsciteit, Sub, NotFound, DefaultSR
        try:
            if not self.hostname or self.hostname.startswith(g.domain):
                if self.path.startswith('/r/'):
                    return Subsciteit._by_name(self.path.split('/')[2])
                elif self.path.startswith('/sciteits/'):
                    return Sub
                else:
                    return DefaultSR()
            elif self.hostname:
                return Subsciteit._by_domain(self.hostname)
        except NotFound:
            pass
        return None