diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 94ee98e5a..b9462d85c 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -1325,15 +1325,13 @@ class ApiController(RedditController): sr = VSubmitSR('sr'), subscribers_only = VBoolean('subscribers_only'), disable_comments = VBoolean('disable_comments'), - disable_expire = VBoolean('disable_expire'), - timelimit = VBoolean('timelimit'), + expire = VOneOf('expire', ['nomodify', 'expirein', 'cancel']), timelimitlength = VInt('timelimitlength',1,1000), timelimittype = VOneOf('timelimittype',['hours','days','weeks'])) def POST_edit_promo(self, res, ip, title, url, sr, subscribers_only, disable_comments, - timelimit = None, timelimitlength = None, timelimittype = None, - disable_expire = None, + expire = None, timelimitlength = None, timelimittype = None, l = None): res._update('status', innerHTML = '') if isinstance(url, str): @@ -1352,7 +1350,7 @@ class ApiController(RedditController): res._focus('url') elif res._chk_error(errors.SUBREDDIT_NOEXIST): res._focus('sr') - elif timelimit and res._chk_error(errors.BAD_NUMBER): + elif expire == 'expirein' and res._chk_error(errors.BAD_NUMBER): res._focus('timelimitlength') elif l: l.title = title @@ -1361,9 +1359,9 @@ class ApiController(RedditController): l.promoted_subscribersonly = subscribers_only l.disable_comments = disable_comments - if disable_expire: + if expire == 'cancel': l.promote_until = None - elif timelimit and timelimitlength and timelimittype: + elif expire == 'expirein' and timelimitlength and timelimittype: l.promote_until = timefromnow("%d %s" % (timelimitlength, timelimittype)) l._commit() @@ -1377,7 +1375,7 @@ class ApiController(RedditController): lang = sr.lang, ip = ip) - if timelimit and timelimitlength and timelimittype: + if expire == 'expirein' and timelimitlength and timelimittype: promote_until = timefromnow("%d %s" % (timelimitlength, timelimittype)) else: promote_until = None diff --git a/r2/r2/controllers/promotecontroller.py b/r2/r2/controllers/promotecontroller.py index c172d4e2b..bb096987d 100644 --- a/r2/r2/controllers/promotecontroller.py +++ b/r2/r2/controllers/promotecontroller.py @@ -24,10 +24,14 @@ from pylons.i18n import _ from r2.models import * from r2.lib.pages import * from r2.lib.menus import * +from r2.controllers import ListingController from r2.controllers.reddit_base import RedditController -from r2.lib import promote +from r2.lib.promote import get_promoted, promote_builder_wrapper +from r2.lib.utils import timetext + +from datetime import datetime class PromoteController(RedditController): @validate(VSponsor()) @@ -36,12 +40,16 @@ class PromoteController(RedditController): @validate(VSponsor()) def GET_current_promos(self): - current_list = promote.get_promoted() + current_list = get_promoted() b = IDBuilder(current_list) render_list = b.get_items()[0] + for x in render_list: + if x.promote_until: + x.promote_expires = timetext(datetime.now(g.tz) - x.promote_until) + page = PromotePage('current_promos', content = PromotedLinks(render_list)) @@ -58,7 +66,21 @@ class PromoteController(RedditController): def GET_edit_promo(self, link): sr = Subreddit._byID(link.sr_id) - form = PromoteLinkForm(sr = sr, link = link) + names = [link._fullname] + builder = IDBuilder(names, + wrap = promote_builder_wrapper(ListingController.builder_wrapper)) + listing = LinkListing(builder, + show_nums = False, nextprev = False) + rendered = listing.listing().render() + + timedeltatext = '' + if link.promote_until: + timedeltatext = timetext(link.promote_until - datetime.now(g.tz), + resultion=2) + + form = PromoteLinkForm(sr = sr, link = link, + listing = rendered, + timedeltatext = timedeltatext) page = PromotePage('new_promo', content = form) return page.render() diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 90f29fbe9..372a7b401 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -1196,10 +1196,14 @@ class PromotedLinks(Wrapped): def __init__(self, current_list, *a, **kw): self.things = current_list - Wrapped.__init__(self, *a, **kw) + Wrapped.__init__(self, datefmt = datefmt, *a, **kw) class PromoteLinkForm(Wrapped): - def __init__(self, sr = None, link = None, *a, **kw): + def __init__(self, sr = None, link = None, listing = '', + timedeltatext = '', *a, **kw): Wrapped.__init__(self, sr = sr, link = link, - datefmt = datefmt, *a, **kw) + datefmt = datefmt, + timedeltatext = timedeltatext, + listing = listing, + *a, **kw) diff --git a/r2/r2/templates/link.html b/r2/r2/templates/link.html index 8313df2b0..46cd703ba 100644 --- a/r2/r2/templates/link.html +++ b/r2/r2/templates/link.html @@ -140,7 +140,7 @@ <%def name="child()"> %def> -<%def name="buttons(comments=True,delete=True,report=True,ban=True)"> +<%def name="buttons(comments=True,delete=True,report=True,ban=True,additional='')"> <% fullname = thing._fullname %> %if comments: <% @@ -181,6 +181,7 @@ %endif ${parent.delete_or_report_buttons(delete=delete,report=report)} ${parent.buttons(ban=ban)} + ${additional} ${self.media_embed()} %def> diff --git a/r2/r2/templates/linkpromoteinfobar.html b/r2/r2/templates/linkpromoteinfobar.html index 27111aa98..d21a84c49 100644 --- a/r2/r2/templates/linkpromoteinfobar.html +++ b/r2/r2/templates/linkpromoteinfobar.html @@ -20,12 +20,10 @@ ## CondeNet, Inc. All Rights Reserved. ################################################################################ <%! - from r2.lib.utils import to36 from datetime import datetime %> <%namespace file="printable.html" import="yes_no_button" /> -<%namespace file="utils.html" import="plain_link" /> %if thing.a.promoted:
| - | - ${plain_link("go to the comments page", thing.link.make_permalink_slow())} - | -
|---|---|
| - | - ${yes_no_button("unpromote", thing.link._fullname, _("unpromote"), \ - "return deletetoggle(this,'unpromote');", _("unpromoted"))} - | -