Add 'Front' to top bar.

This commit is contained in:
Neil Williams
2012-04-12 22:15:17 -07:00
parent 1b7384591f
commit e7e153577a
4 changed files with 12 additions and 8 deletions

View File

@@ -30,7 +30,7 @@ from r2.lib.utils import http_utils, is_subdomain, UniqueIterator, ip_and_slash1
from r2.lib.cache import LocalCache, make_key, MemcachedError
import random as rand
from r2.models.account import valid_cookie, FakeAccount, valid_feed, valid_admin_cookie
from r2.models.subreddit import Subreddit
from r2.models.subreddit import Subreddit, Frontpage
from r2.models import *
from errors import ErrorSet
from validator import *
@@ -249,13 +249,12 @@ def set_subreddit():
can_stale = request.method.upper() in ('GET','HEAD')
default_sr = DefaultSR()
c.site = default_sr
c.site = Frontpage
if not sr_name:
#check for cnames
sub_domain = request.environ.get('sub_domain')
if sub_domain and not sub_domain.endswith(g.media_domain):
c.site = Subreddit._by_domain(sub_domain) or default_sr
c.site = Subreddit._by_domain(sub_domain) or Frontpage
elif sr_name == 'r':
#reddits
c.site = Sub

View File

@@ -324,10 +324,14 @@ class OffsiteButton(NavButton):
return [('path', self.path), ('title', self.title)]
class SubredditButton(NavButton):
from r2.models.subreddit import Frontpage, Mod
# TRANSLATORS: these refer to /r/mod and the front page.
name_overrides = {Mod: _("mod"),
Frontpage: _("front")}
def __init__(self, sr):
from r2.models.subreddit import Mod
self.path = sr.path
name = 'mod' if sr == Mod else sr.name
name = self.name_overrides.get(sr, sr.name)
NavButton.__init__(self, name, sr.path, False,
isselected = (c.site == sr))

View File

@@ -22,7 +22,7 @@
from r2.lib.wrapped import Wrapped, Templated, CachedTemplate
from r2.models import Account, FakeAccount, DefaultSR, make_feedurl
from r2.models import FakeSubreddit, Subreddit, Ad, AdSR
from r2.models import Friends, All, Sub, NotFound, DomainSR, Random, Mod, RandomNSFW, MultiReddit, ModSR
from r2.models import Friends, All, Sub, NotFound, DomainSR, Random, Mod, RandomNSFW, MultiReddit, ModSR, Frontpage
from r2.models import Link, Printable, Trophy, bidding, PromotionWeights, Comment
from r2.models import Flair, FlairTemplate, FlairTemplateBySubredditIndex
from r2.models import USER_FLAIR, LINK_FLAIR
@@ -1409,7 +1409,7 @@ class SubredditTopBar(CachedTemplate):
css_class = 'sr-bar', _id = 'sr-bar')
def special_reddits(self):
reddits = [All, Random]
reddits = [Frontpage, All, Random]
if getattr(c.site, "over_18", False):
reddits.append(RandomNSFW)
if c.user_is_loggedin:

View File

@@ -985,6 +985,7 @@ class DomainSR(FakeSubreddit):
# switched over to use the non-_old variety.
return queries.get_domain_links(self.domain, sort, time)
Frontpage = DefaultSR()
Sub = SubSR()
Friends = FriendsSR()
Mod = ModSR()