diff --git a/r2/r2/controllers/front.py b/r2/r2/controllers/front.py index 4b084e5de..7bd973383 100755 --- a/r2/r2/controllers/front.py +++ b/r2/r2/controllers/front.py @@ -939,8 +939,6 @@ class FrontController(RedditController, OAuth2ResourceController): abort(403, "forbidden") captcha = Captcha() if c.user.needs_captcha() else None - sr_names = (Subreddit.submit_sr_names(c.user) or - Subreddit.submit_sr_names(None)) never_show_self = request.get.get('no_self') @@ -951,7 +949,6 @@ class FrontController(RedditController, OAuth2ResourceController): title=title or '', text=text or '', selftext=selftext or '', - subreddits=sr_names, captcha=captcha, resubmit=resubmit, never_show_self=never_show_self, diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index eb02eff67..604e8b0cd 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -2295,7 +2295,7 @@ class FrameToolbar(Wrapped): class NewLink(Templated): """Render the link submission form""" def __init__(self, captcha = None, url = '', title= '', text = '', selftext = '', - subreddits = (), then = 'comments', resubmit=False, never_show_self=False): + then = 'comments', resubmit=False, never_show_self=False): self.show_link = self.show_self = False @@ -2329,8 +2329,6 @@ class NewLink(Templated): self.formtabs_menu = JsNavMenu(buttons, type = 'formtab') - self.sr_searches = simplejson.dumps(popular_searches(include_over_18=c.over18)) - self.resubmit = resubmit if c.default_sr: self.default_sr = None @@ -2338,8 +2336,7 @@ class NewLink(Templated): self.default_sr = c.site Templated.__init__(self, captcha = captcha, url = url, - title = title, text = text, subreddits = subreddits, - then = then) + title = title, text = text, then = then) class ShareLink(CachedTemplate): def __init__(self, link_name = "", emails = None): @@ -3328,11 +3325,6 @@ class PromoteLinkForm(Templated): self.link = None if link: - self.sr_searches = simplejson.dumps(popular_searches()) - self.subreddits = (Subreddit.submit_sr_names(c.user) or - Subreddit.submit_sr_names(None)) - self.default_sr = (self.subreddits[0] if self.subreddits - else g.default_sr) self.link = promote.wrap_promoted(link) campaigns = PromoCampaign._by_link(link._id) self.campaigns = promote.get_renderable_campaigns(link, campaigns) @@ -3429,11 +3421,7 @@ class Roadblocks(Templated): self.startdate = startdate.strftime("%m/%d/%Y") self.enddate = enddate .strftime("%m/%d/%Y") - self.sr_searches = simplejson.dumps(popular_searches()) - self.subreddits = (Subreddit.submit_sr_names(c.user) or - Subreddit.submit_sr_names(None)) - self.default_sr = self.subreddits[0] if self.subreddits \ - else g.default_sr + class TabbedPane(Templated): def __init__(self, tabs, linkable=False): @@ -4199,3 +4187,26 @@ class SubscribeButton(Templated): def __init__(self, sr): Templated.__init__(self) self.sr = sr + + +class SubredditSelector(Templated): + def __init__(self, subreddits=None, default_sr=None, required=False): + Templated.__init__(self) + + if subreddits: + self.subreddits = subreddits + else: + self.subreddits = (Subreddit.submit_sr_names(c.user) or + Subreddit.submit_sr_names(None)) + + if default_sr: + self.default_sr = default_sr + elif subreddits: + self.default_sr = subreddits[0] + else: + self.default_sr = None + + self.required = required + self.sr_searches = simplejson.dumps( + popular_searches(include_over_18=c.over18) + ) diff --git a/r2/r2/templates/newlink.html b/r2/r2/templates/newlink.html index 02ec952a9..2992ef9bd 100755 --- a/r2/r2/templates/newlink.html +++ b/r2/r2/templates/newlink.html @@ -22,11 +22,11 @@ <%! from r2.lib.strings import strings - from r2.lib.pages import UserText + from r2.lib.pages import SubredditSelector, UserText from r2.lib.template_helpers import add_sr %> -<%namespace file="utils.html" import="error_field, submit_form, _a_buffered, reddit_selector, text_with_links"/> +<%namespace file="utils.html" import="error_field, submit_form, _a_buffered, text_with_links"/> <%namespace name="utils" file="utils.html"/> <% @@ -99,7 +99,7 @@ ${thing.formtabs_menu}
<%utils:round_field title="${_('choose a subreddit')}" id="reddit-field"> - ${reddit_selector(thing.default_sr.name if thing.default_sr else None, thing.sr_searches, thing.subreddits, required=True)} + ${SubredditSelector(thing.default_sr, required=True)}
diff --git a/r2/r2/templates/promotelinkform.html b/r2/r2/templates/promotelinkform.html index 7d9e360ac..cc1a8406a 100644 --- a/r2/r2/templates/promotelinkform.html +++ b/r2/r2/templates/promotelinkform.html @@ -25,13 +25,14 @@ from r2.lib.media import thumbnail_url from r2.lib.template_helpers import static from r2.lib import promote + from r2.lib.pages import SubredditSelector from r2.lib.strings import strings from r2.models import Account from r2.lib import js import simplejson %> <%namespace file="utils.html" - import="error_field, checkbox, image_upload, reddit_selector" /> + import="error_field, checkbox, image_upload" /> <%namespace name="utils" file="utils.html"/> ${unsafe(js.use('sponsored'))} @@ -193,7 +194,7 @@ ${self.javascript_setup()}
  • You can only target one subreddit per campaign. If you would like to submit to more than one subreddit, add a new campaign (its easy, you just fill this form out again).
  • ${error_field("OVERSOLD", "sr", "div")} - ${reddit_selector(thing.default_sr, thing.sr_searches, thing.subreddits)} + ${SubredditSelector()}
    diff --git a/r2/r2/templates/roadblocks.html b/r2/r2/templates/roadblocks.html index b8b5dc216..138c86f7e 100644 --- a/r2/r2/templates/roadblocks.html +++ b/r2/r2/templates/roadblocks.html @@ -21,13 +21,14 @@ ############################################################################### <%! + from r2.lib.pages import SubredditSelector from r2.lib.template_helpers import static from r2.lib import js %> <%namespace name="utils" file="utils.html"/> <%namespace file="promotelinkform.html" name="p" /> <%namespace file="utils.html" - import="error_field, checkbox, image_upload, reddit_selector" /> + import="error_field, checkbox, image_upload" /> ${unsafe(js.use('sponsored'))} @@ -77,7 +78,7 @@ ${unsafe(js.use('sponsored'))} })
    - ${reddit_selector(thing.default_sr, thing.sr_searches, thing.subreddits)} + ${SubredditSelector()}
    diff --git a/r2/r2/templates/subredditselector.html b/r2/r2/templates/subredditselector.html new file mode 100644 index 000000000..7069d5d24 --- /dev/null +++ b/r2/r2/templates/subredditselector.html @@ -0,0 +1,44 @@ +<%namespace file="utils.html" import="error_field"/> + +<%doc> + Fires custom event when subreddit selection changes. Add handler like: + $("#sr-autocomplete").bind("sr-changed", function() { dostuff; }) + + +
    + +
      +
    • nothin
    • +
    +
    + +${error_field("SUBREDDIT_NOEXIST", "sr", "div")} +${error_field("SUBREDDIT_NOTALLOWED", "sr", "div")} +${error_field("SUBREDDIT_REQUIRED", "sr", "div")} + +
    + ${_("popular choices")} +
      + %for name in thing.subreddits: +
    • + ${name} +
    • + %endfor +
    +
    diff --git a/r2/r2/templates/utils.html b/r2/r2/templates/utils.html index b20c1ab17..f0afc167c 100755 --- a/r2/r2/templates/utils.html +++ b/r2/r2/templates/utils.html @@ -529,49 +529,6 @@ ${unsafe(txt)} -<%def name="reddit_selector(default_sr, sr_searches, subreddits, required=False)"> - <%doc> - Fires custom event when subreddit selection changes. Add handler like: - $("#sr-autocomplete").bind("sr-changed", function() { dostuff; }) - - -
    - -
      -
    • nothin
    • -
    -
    - - ${error_field("SUBREDDIT_NOEXIST", "sr", "div")} - ${error_field("SUBREDDIT_NOTALLOWED", "sr", "div")} - ${error_field("SUBREDDIT_REQUIRED", "sr", "div")} - -
    - ${_("popular choices")} -
      - %for name in subreddits: -
    • - ${name} -
    • - %endfor -
    -
    - - <%def name="timestamp(date, since=None)"> ## todo: use pubdate attribute once things are
    tags. ## note: comment and link templates will pass a CachedVariable stub as since.