Simplify the form for promoting links a bit

This commit is contained in:
ketralnis
2008-12-17 11:01:45 -08:00
parent ae6ba7a78e
commit 3248275029
8 changed files with 105 additions and 74 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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)

View File

@@ -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>

View File

@@ -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:
<tr>
@@ -60,20 +58,6 @@
% dict(subreddit = c.site.name))}</td>
</tr>
%endif
<tr>
<th></th>
<td>
${yes_no_button("unpromote", thing.a._fullname, _("unpromote"), \
"return deletetoggle(this,'unpromote');", _("unpromoted"))}
</td>
</tr>
<tr>
<td></td>
<td>
${plain_link(_('edit promotion'),'/promote/edit_promo/%s' % to36(thing.a._id),
_sr_path = False)}
</td>
</tr>
%else:
<tr>
<th></th>

View File

@@ -19,14 +19,34 @@
## All portions of the code written by CondeNet are Copyright (c) 2006-2008
## CondeNet, Inc. All Rights Reserved.
################################################################################
<%!
from r2.lib.utils import to36
%>
<%inherit file="link.html"/>
<%namespace file="printable.html" import="yes_no_button" />
<%namespace file="utils.html" import="plain_link" />
<%def name="tagline()">
</%def>
<%def name="unpromote_button()" buffered="True" filter="unsafe">
<li>
${plain_link(_('edit'),'/promote/edit_promo/%s' % to36(thing._id),
_sr_path = False)}
</li>
<li>
${yes_no_button("unpromote", thing._fullname, _("unpromote"), \
"return deletetoggle(this,'unpromote');", _("unpromoted"))}
</li>
</%def>
<%def name="buttons()">
${parent.buttons(comments=not thing.disable_comments,
report=False,ban=False)}
report=False,
ban=False,
additional=unpromote_button())}
</%def>
<%def name="entry()">

View File

@@ -32,7 +32,12 @@
<ul class="promoted-list">
%for t in thing.things:
<li class="entry">
${plain_link(t.title,'/promote/edit_promo/%s' % to36(t._id))}&nbsp;
${plain_link(t.title,'/promote/edit_promo/%s' % to36(t._id))} &nbsp;
%if t.promote_until:
${(_("(until %(until)s)")
% dict(until = t.promote_until.strftime(thing.datefmt)))}
&nbsp;
%endif
<ul class="buttons" style="display: inline;">
<li>
${yes_no_button("unpromote", t._fullname, _("unpromote"), \

View File

@@ -23,8 +23,11 @@
from r2.lib.utils import to36
from r2.lib.media import thumbnail_url
%>
<%namespace file="utils.html" import="error_field, checkbox, plain_link, image_upload" />
<%namespace file="printable.html" import="yes_no_button" />
<%namespace file="utils.html" import="error_field, checkbox, image_upload" />
%if thing.link:
${thing.listing}
%endif
<form class="content pretty-form" method="POST" action="/post/new_promo"
id="promo_form" onsubmit="return post_form(this, 'edit_promo', null, null, true)">
@@ -57,15 +60,17 @@
<th><label for="sr">${_("reddit")}</label></th>
<td>
%if thing.link:
<b>${thing.sr.name}</b>
<input name="sr" type="hidden" value="${thing.sr.name}"/>
${checkbox("subscribers_only",
(_("show only to subscribers of %(reddit)s")
% dict(reddit = thing.sr.name)),
thing.link.promoted_subscribersonly)}
<input type="hidden" name="sr" value="${thing.sr.name}" />
%else:
<input name="sr" type="text" value="${g.default_sr}"/>
<input type="text" name="sr" value="${g.default_sr}" /> <br />
${checkbox("subscribers_only",
_("show only to subscribers of this reddit"),
False)}
%endif
<br />
${checkbox("subscribers_only",
_("show only to subscribers of this reddit"),
thing.link.promoted_subscribersonly if thing.link else False)}
</td>
<td class="error">
${error_field("SUBREDDIT_NOEXIST")}
@@ -84,23 +89,31 @@
<th><label for="timelimit">${_("duration")}</label></th>
<td>
%if thing.link and thing.link.promote_until:
${(_("will expire on %(expires_on)s")
% dict(expires_on = thing.link.promote_until.strftime(thing.datefmt)))}
${checkbox("disable_expire",
_("disable automatic expiration"),
False)}
<input type="radio" name="expire" value="nomodify" checked="checked" />
${(_('expire in %(timedelta)s (%(expires_at)s)')
% dict(timedelta = thing.timedeltatext,
expires_at = thing.link.promote_until.strftime(thing.datefmt)))} <br />
<input type="radio" name="expire" value="expirein" />
${_("expire in")} &nbsp;
<input name="timelimitlength" size="3" />
<select name="timelimittype">
<option value="hours">${_("hours")}</option>
<option value="days" selected="selected">${_("days")}</option>
<option value="weeks">${_("weeks")}</option>
</select><br />
<input type="radio" name="expire" value="cancel" />
${_("don't expire")} <br />
%else:
${checkbox("timelimit",
_("automatically disable in"),
False)}
&nbsp;
<input name="timelimitlength" size="3" />
<select name="timelimittype">
<option value="hours">${_("hours")}</option>
<option value="days" selected="selected">${_("days")}</option>
<option value="weeks">${_("weeks")}</option>
</select>
<input type="radio" name="expire" value="nomodify" checked="checked" />
${_("don't expire")} <br />
<input type="radio" name="expire" value="expirein" />
${_("expire in")} &nbsp;
<input name="timelimitlength" size="3" />
<select name="timelimittype">
<option value="hours">${_("hours")}</option>
<option value="days" selected="selected">${_("days")}</option>
<option value="weeks">${_("weeks")}</option>
</select>
%endif
</td>
<td class="error">${error_field("BAD_NUMBER", "span")}</td>
@@ -121,22 +134,6 @@
<td id="img-status"></td>
</tr>
</table>
<table class="content preftable pretty-form">
<tr>
<th></th>
<td>
${plain_link("go to the comments page", thing.link.make_permalink_slow())}
</td>
</tr>
<tr>
<th></th>
<td>
${yes_no_button("unpromote", thing.link._fullname, _("unpromote"), \
"return deletetoggle(this,'unpromote');", _("unpromoted"))}
</td>
</tr>
</table>
%endif
<div class="save-button">