Add multireddit subreddits to the submit page.

This commit is contained in:
Max Goodman
2013-07-12 16:39:31 -07:00
parent 7dd403178b
commit 4df1ae542e
7 changed files with 48 additions and 33 deletions

View File

@@ -116,6 +116,8 @@ def make_map():
where='overview')
mc('/user/:username/m/:multipath', controller='hot', action='listing')
mc('/user/:username/m/:multipath/submit', controller='front',
action='submit')
mc('/user/:username/m/:multipath/:sort', controller='browse', sort='top',
action='listing', requirements=dict(sort='top|controversial'))
mc('/user/:username/m/:multipath/:controller', action='listing',

View File

@@ -940,6 +940,13 @@ class FrontController(RedditController, OAuth2ResourceController):
captcha = Captcha() if c.user.needs_captcha() else None
extra_subreddits = []
if isinstance(c.site, MultiReddit):
extra_subreddits.append((
_('%s subreddits') % c.site.name,
c.site.srs
))
newlink = NewLink(
url=url or '',
title=title or '',
@@ -948,6 +955,7 @@ class FrontController(RedditController, OAuth2ResourceController):
captcha=captcha,
resubmit=resubmit,
default_sr=c.site if not c.default_sr else None,
extra_subreddits=extra_subreddits,
show_link=c.default_sr or c.site.link_type != 'self',
show_self=((c.default_sr or c.site.link_type != 'link')
and not request.get.get('no_self')),

View File

@@ -414,19 +414,20 @@ class Reddit(Templated):
show_icon=False))
else:
fake_sub = isinstance(c.site, FakeSubreddit)
is_multi = isinstance(c.site, MultiReddit)
if c.site.link_type != 'self':
ps.append(SideBox(title=c.site.submit_link_label or
strings.submit_link_label,
css_class="submit submit-link",
link="/submit",
sr_path=not fake_sub,
sr_path=not fake_sub or is_multi,
show_cover=True))
if c.site.link_type != 'link':
ps.append(SideBox(title=c.site.submit_text_label or
strings.submit_text_label,
css_class="submit submit-text",
link="/submit?selftext=true",
sr_path=not fake_sub,
sr_path=not fake_sub or is_multi,
show_cover=True))
no_ads_yet = True
@@ -2296,7 +2297,7 @@ class NewLink(Templated):
"""Render the link submission form"""
def __init__(self, captcha=None, url='', title='', text='', selftext='',
then='comments', resubmit=False, default_sr=None,
show_link=True, show_self=True):
extra_subreddits=None, show_link=True, show_self=True):
self.show_link = show_link
self.show_self = show_self
@@ -2331,6 +2332,7 @@ class NewLink(Templated):
self.resubmit = resubmit
self.default_sr = default_sr
self.extra_subreddits = extra_subreddits
Templated.__init__(self, captcha = captcha, url = url,
title = title, text = text, then = then)
@@ -4187,17 +4189,30 @@ class SubscribeButton(Templated):
class SubredditSelector(Templated):
def __init__(self, subreddits=None, default_sr=None, required=False):
def __init__(self, default_sr=None, extra_subreddits=None, required=False):
Templated.__init__(self)
if subreddits:
self.subreddits = subreddits
if extra_subreddits:
self.subreddits = extra_subreddits
else:
self.subreddits = (Subreddit.submit_sr_names(c.user) or
Subreddit.submit_sr_names(None))
self.subreddits = []
self.subreddits.append((
_('popular choices'),
Subreddit.user_subreddits(c.user, ids=False)
))
self.default_sr = default_sr
self.required = required
self.sr_searches = simplejson.dumps(
popular_searches(include_over_18=c.over18)
)
@property
def subreddit_names(self):
groups = []
for title, subreddits in self.subreddits:
names = [sr.name for sr in subreddits if sr.can_submit(c.user)]
names.sort(key=str.lower)
groups.append((title, names))
return groups

View File

@@ -812,20 +812,6 @@ class Subreddit(Thing, Printable, BaseSite):
user.has_subscribed = True
user._commit()
@classmethod
def submit_sr_names(cls, user):
"""subreddit names that appear in a user's submit page. basically a
sorted/rearranged version of user_subreddits()."""
srs = cls.user_subreddits(user, ids = False)
names = [s.name for s in srs if s.can_submit(user)]
names.sort(key=str.lower)
if c.lang in names:
names.remove(c.lang)
names.insert(0, c.lang)
return names
def keep_item(self, wrapped):
if c.user_is_admin:
return True

View File

@@ -3811,8 +3811,10 @@ ul#image-preview-list .description pre {
font-size: small;
}
#suggested-reddits ul {
#suggested-reddits h3 {
font-size: 1em;
font-weight: normal;
margin-top: .5em;
}
#suggested-reddits li {

View File

@@ -99,7 +99,7 @@ ${thing.formtabs_menu}
<div class="spacer">
<%utils:round_field title="${_('choose a subreddit')}" id="reddit-field">
${SubredditSelector(thing.default_sr, required=True)}
${SubredditSelector(thing.default_sr, extra_subreddits=thing.extra_subreddits, required=True)}
</%utils:round_field>
</div>

View File

@@ -33,12 +33,14 @@ ${error_field("SUBREDDIT_NOTALLOWED", "sr", "div")}
${error_field("SUBREDDIT_REQUIRED", "sr", "div")}
<div id="suggested-reddits">
<span>${_("popular choices")}&#32;</span>
<ul>
%for name in thing.subreddits:
<li>
<a href="#" tabindex="100" onclick="set_sr_name(this); return false">${name}</a>&#32;
</li>
%endfor
</ul>
% for title, subreddits in thing.subreddit_names:
<h3>${title}</h3>
<ul>
%for name in subreddits:
<li>
<a href="#" tabindex="100" onclick="set_sr_name(this); return false">${name}</a>&#32;
</li>
%endfor
</ul>
% endfor
</div>