Separate templates for creating and editing promoted links.

This commit is contained in:
bsimpson63
2013-05-06 19:15:10 -04:00
committed by Brian Simpson
parent 8b81270380
commit e8c6862936
4 changed files with 75 additions and 44 deletions

View File

@@ -44,6 +44,7 @@ from r2.lib.pages import (
PromotePage,
PromoteLinkForm,
PromoteLinkFormCpm,
PromoteLinkNew,
PromoteReport,
Reddit,
Roadblocks,
@@ -227,22 +228,16 @@ class PromoteController(ListingController):
@validate(VSponsor())
def GET_new_promo(self):
return PromotePage('content', content=PromoteLinkForm()).render()
return PromotePage('content', content=PromoteLinkNew()).render()
@validate(VSponsor('link'),
link=VLink('link'))
def GET_edit_promo(self, link):
if not link or link.promoted is None:
return self.abort404()
rendered = wrap_links(link, wrapper=promote.sponsor_wrapper,
skip=False)
form = PromoteLinkForm(link=link,
listing=rendered,
timedeltatext="")
rendered = wrap_links(link, wrapper=promote.sponsor_wrapper, skip=False)
form = PromoteLinkForm(link, rendered)
page = PromotePage('new_promo', content=form)
return page.render()

View File

@@ -3308,14 +3308,16 @@ class PromotePage(Reddit):
kw['show_sidebar'] = False
Reddit.__init__(self, title, nav_menus = nav_menus, *a, **kw)
class PromoteLinkNew(Templated): pass
class PromoteLinkForm(Templated):
def __init__(self, link=None, listing='', *a, **kw):
def __init__(self, link, listing, *a, **kw):
self.setup(link, listing)
Templated.__init__(self, *a, **kw)
def setup(self, link, listing):
self.bids = []
if c.user_is_sponsor and link:
if c.user_is_sponsor:
self.author = Account._byID(link.author_id)
try:
bids = bidding.Bid.lookup(thing_id=link._id)
@@ -3357,13 +3359,11 @@ class PromoteLinkForm(Templated):
self.mindate = mindate.strftime("%m/%d/%Y")
self.link = None
self.link = promote.wrap_promoted(link)
self.listing = listing
if link:
self.link = promote.wrap_promoted(link)
campaigns = PromoCampaign._by_link(link._id)
self.campaigns = promote.get_renderable_campaigns(link, campaigns)
self.promotion_log = PromotionLog.get(link)
campaigns = PromoCampaign._by_link(link._id)
self.campaigns = promote.get_renderable_campaigns(link, campaigns)
self.promotion_log = PromotionLog.get(link)
self.min_daily_bid = 0 if c.user_is_admin else g.min_promote_bid

View File

@@ -66,21 +66,15 @@ ${self.javascript_setup()}
<div class="create-promotion">
<h1>${_("create a promotion") if not thing.link else _("edit promotion")}</h1>
<h1>${_("edit promotion")}</h1>
%if thing.link:
${thing.listing}
%endif
${thing.listing}
<div class="create-promo">
%if thing.link:
${campaign_dashboard()}
%endif
${campaign_dashboard()}
<div class="pretty-form" id="promo-form">
%if thing.link:
<input type="hidden" name="link_id" value="${to36(thing.link._id)}"/>
%endif
<input type="hidden" name="link_id" value="${to36(thing.link._id)}"/>
<%
trusted = c.user_is_sponsor or c.user.trusted_sponsor
@@ -90,36 +84,23 @@ ${self.javascript_setup()}
${title_field(thing.link, editable=editable)}
${url_field(thing.link, editable=editable, enable_override=c.user_is_sponsor)}
%if thing.link and editable:
%if editable:
${image_field(thing.link)}
${commenting_field(thing.link)}
%if trusted:
${media_field(thing.link)}
%endif
%else:
<div class="rules">
By clicking "next" you agree to the&#32;<a href="http://www.reddit.com/wiki/selfservicepromotion">Self Serve Advertising Rules.</a>
</div>
%endif
<div class="save-button">
<%
if thing.link:
name = "save"
text = _("save options")
else:
name = "create"
text = _("next")
%>
${error_field("RATELIMIT", "ratelimit")}
&#32;
<span class="status error"></span>
${error_field("RATELIMIT", "ratelimit")}
<button name="${name}" class="btn fancybutton" type="button"
<button name="save" class="btn fancybutton" type="button"
onclick="return post_pseudo_form('#promo-form', 'edit_promo')">
${text}
${_("save options")}
</button>
</div>
@@ -454,7 +435,7 @@ ${self.javascript_setup()}
</%def>
<%def name="right_panel()">
%if thing.link and c.user_is_sponsor:
%if c.user_is_sponsor:
<div class="spacer bidding-history">
%if thing.bids:
<%utils:line_field title="${_('bidding history')}" css_class="rounded">

View File

@@ -0,0 +1,55 @@
## The contents of this file are subject to the Common Public Attribution
## License Version 1.0. (the "License"); you may not use this file except in
## compliance with the License. You may obtain a copy of the License at
## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
## License Version 1.1, but Sections 14 and 15 have been added to cover use of
## software over a computer network and provide for limited attribution for the
## Original Developer. In addition, Exhibit A has been modified to be
## consistent with Exhibit B.
##
## Software distributed under the License is distributed on an "AS IS" basis,
## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
## the specific language governing rights and limitations under the License.
##
## The Original Code is reddit.
##
## The Original Developer is the Initial Developer. The Initial Developer of
## the Original Code is reddit Inc.
##
## All portions of the code written by reddit are Copyright (c) 2006-2013
## reddit Inc. All Rights Reserved.
###############################################################################
<%namespace file="promotelinkform.html" import="title_field, url_field" />
<%namespace file="utils.html" import="error_field" />
<%namespace name="utils" file="utils.html"/>
<div class="create-promotion">
<h1>${_("create a promotion")}</h1>
<div class="create-promo">
<div class="pretty-form" id="promo-form">
${title_field(None, editable=True)}
${url_field(None, editable=True, enable_override=c.user_is_sponsor)}
<div class="rules">
By clicking "next" you agree to the&#32;<a href="http://www.reddit.com/wiki/selfservicepromotion">Self Serve Advertising Rules.</a>
</div>
<div class="save-button">
${error_field("RATELIMIT", "ratelimit")}
&#32;
<span class="status error"></span>
${error_field("RATELIMIT", "ratelimit")}
<button name="create" class="btn fancybutton" type="button"
onclick="return post_pseudo_form('#promo-form', 'edit_promo')">
${_("next")}
</button>
</div>
</div>
</div>
</div>