promotecontroller: Automated whitespace cleanup

This commit is contained in:
Keith Mitchell
2013-01-07 15:26:55 -08:00
committed by Neil Williams
parent 3e95419468
commit 83f424c8d9

View File

@@ -120,7 +120,7 @@ class PromoteController(ListingController):
return queries.get_promoted_links(c.user._id)
@validate(VSponsor())
def GET_listing(self, sort = "", **env):
def GET_listing(self, sort="", **env):
if not c.user_is_loggedin or not c.user.email_verified:
return self.redirect("/ad_inq")
self.sort = sort
@@ -130,39 +130,39 @@ class PromoteController(ListingController):
@validate(VSponsor())
def GET_new_promo(self):
return PromotePage('content', content = PromoteLinkForm()).render()
return PromotePage('content', content=PromoteLinkForm()).render()
@validate(VSponsor('link'),
link = VLink('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)
rendered = wrap_links(link, wrapper=promote.sponsor_wrapper,
skip=False)
form = PromoteLinkForm(link = link,
listing = rendered,
timedeltatext = "")
form = PromoteLinkForm(link=link,
listing=rendered,
timedeltatext="")
page = PromotePage('new_promo', content = form)
page = PromotePage('new_promo', content=form)
return page.render()
# For development. Should eventually replace GET_edit_promo
@validate(VSponsor('link'),
link = VLink('link'))
link=VLink('link'))
def GET_edit_promo_cpm(self, link):
if not link or link.promoted is None:
return self.abort404()
rendered = wrap_links(link, wrapper = promote.sponsor_wrapper,
skip = False)
rendered = wrap_links(link, wrapper=promote.sponsor_wrapper,
skip=False)
form = PromoteLinkFormCpm(link = link,
listing = rendered,
timedeltatext = "")
form = PromoteLinkFormCpm(link=link,
listing=rendered,
timedeltatext="")
page = PromotePage('new_promo', content = form)
page = PromotePage('new_promo', content=form)
return page.render()
@@ -188,16 +188,16 @@ class PromoteController(ListingController):
return c.response
return PromotePage("admingraph", content=content).render()
def GET_inventory(self, sr_name):
'''
Return available inventory data as json for use in ajax calls
'''
inv_start_date = promote.promo_datetime_now()
inv_end_date = inv_start_date + timedelta(60)
inventory = promote.get_available_impressions(sr_name,
inv_start_date,
inv_end_date,
inventory = promote.get_available_impressions(sr_name,
inv_start_date,
inv_end_date,
fuzzed=(not c.user_is_admin))
dates = []
impressions = []
@@ -208,21 +208,21 @@ class PromoteController(ListingController):
max_imps = max(max_imps, imps)
return json.dumps({'sr':sr_name,
'dates': dates,
'imps':impressions,
'imps':impressions,
'max_imps':max_imps})
### POST controllers below
# ## POST controllers below
@validatedForm(VSponsorAdmin(),
link = VLink("link_id"),
campaign = VPromoCampaign("campaign_id36"))
link=VLink("link_id"),
campaign=VPromoCampaign("campaign_id36"))
def POST_freebie(self, form, jquery, link, campaign):
if promote.is_promo(link) and campaign:
promote.free_campaign(link, campaign, c.user)
form.redirect(promote.promo_edit_url(link))
@validatedForm(VSponsorAdmin(),
link = VByName("link"),
note = nop("note"))
link=VByName("link"),
note=nop("note"))
def POST_promote_note(self, form, jquery, link, note):
if promote.is_promo(link):
text = PromotionLog.add(link, note)
@@ -231,42 +231,42 @@ class PromoteController(ListingController):
@noresponse(VSponsorAdmin(),
thing = VByName('id'))
thing=VByName('id'))
def POST_promote(self, thing):
if promote.is_promo(thing):
promote.accept_promotion(thing)
@noresponse(VSponsorAdmin(),
thing = VByName('id'),
reason = nop("reason"))
thing=VByName('id'),
reason=nop("reason"))
def POST_unpromote(self, thing, reason):
if promote.is_promo(thing):
promote.reject_promotion(thing, reason = reason)
promote.reject_promotion(thing, reason=reason)
@validatedForm(VSponsor('link_id'),
VModhash(),
VRatelimit(rate_user = True,
rate_ip = True,
prefix = 'create_promo_'),
l = VLink('link_id'),
title = VTitle('title'),
url = VUrl('url', allow_self = False, lookup = False),
ip = ValidIP(),
disable_comments = VBoolean("disable_comments"),
set_clicks = VBoolean("set_maximum_clicks"),
max_clicks = VInt("maximum_clicks", min = 0),
set_views = VBoolean("set_maximum_views"),
max_views = VInt("maximum_views", min = 0),
media_width = VInt("media-width", min = 0),
media_height = VInt("media-height", min = 0),
media_embed = VLength("media-embed", 1000),
media_override = VBoolean("media-override"),
domain_override = VLength("domain", 100)
VRatelimit(rate_user=True,
rate_ip=True,
prefix='create_promo_'),
l=VLink('link_id'),
title=VTitle('title'),
url=VUrl('url', allow_self=False, lookup=False),
ip=ValidIP(),
disable_comments=VBoolean("disable_comments"),
set_clicks=VBoolean("set_maximum_clicks"),
max_clicks=VInt("maximum_clicks", min=0),
set_views=VBoolean("set_maximum_views"),
max_views=VInt("maximum_views", min=0),
media_width=VInt("media-width", min=0),
media_height=VInt("media-height", min=0),
media_embed=VLength("media-embed", 1000),
media_override=VBoolean("media-override"),
domain_override=VLength("domain", 100)
)
def POST_edit_promo(self, form, jquery, ip, l, title, url,
disable_comments,
set_clicks, max_clicks,
set_views, max_views,
set_views, max_views,
media_height, media_width, media_embed,
media_override, domain_override):
@@ -286,7 +286,7 @@ class PromoteController(ListingController):
# demangle URL in canonical way
if url:
if isinstance(url, (unicode, str)):
form.set_inputs(url = url)
form.set_inputs(url=url)
elif isinstance(url, tuple) or isinstance(url[0], Link):
# there's already one or more links with this URL, but
# we're allowing mutliple submissions, so we really just
@@ -294,7 +294,7 @@ class PromoteController(ListingController):
url = url[0].url
# users can change the disable_comments on promoted links
if ((not l or not promote.is_promoted(l)) and
if ((not l or not promote.is_promoted(l)) and
(form.has_errors('title', errors.NO_TEXT,
errors.TOO_LONG) or
form.has_errors('url', errors.NO_URL, errors.BAD_URL) or
@@ -330,10 +330,10 @@ class PromoteController(ListingController):
l.disable_comments = disable_comments
if c.user_is_sponsor or c.user.trusted_sponsor:
if media_embed and media_width and media_height:
l.media_object = dict(height = media_height,
width = media_width,
content = media_embed,
type = 'custom')
l.media_object = dict(height=media_height,
width=media_width,
content=media_embed,
type='custom')
else:
l.media_object = None
@@ -346,16 +346,16 @@ class PromoteController(ListingController):
@validate(VSponsorAdmin())
def GET_roadblock(self):
return PromotePage('content', content = Roadblocks()).render()
return PromotePage('content', content=Roadblocks()).render()
@validatedForm(VSponsorAdmin(),
VModhash(),
dates = VDateRange(['startdate', 'enddate'],
future = 1,
reference_date = promote.promo_datetime_now,
business_days = False,
sponsor_override = True),
sr = VSubmitSR('sr', promotion=True))
dates=VDateRange(['startdate', 'enddate'],
future=1,
reference_date=promote.promo_datetime_now,
business_days=False,
sponsor_override=True),
sr=VSubmitSR('sr', promotion=True))
def POST_add_roadblock(self, form, jquery, dates, sr):
if (form.has_errors('startdate', errors.BAD_DATE,
errors.BAD_FUTURE_DATE) or
@@ -373,12 +373,12 @@ class PromoteController(ListingController):
@validatedForm(VSponsorAdmin(),
VModhash(),
dates = VDateRange(['startdate', 'enddate'],
future = 1,
reference_date = promote.promo_datetime_now,
business_days = False,
sponsor_override = True),
sr = VSubmitSR('sr', promotion=True))
dates=VDateRange(['startdate', 'enddate'],
future=1,
reference_date=promote.promo_datetime_now,
business_days=False,
sponsor_override=True),
sr=VSubmitSR('sr', promotion=True))
def POST_rm_roadblock(self, form, jquery, dates, sr):
if dates and sr:
sd, ed = dates
@@ -387,22 +387,22 @@ class PromoteController(ListingController):
@validatedForm(VSponsor('link_id'),
VModhash(),
dates = VDateRange(['startdate', 'enddate'],
future = 1,
reference_date = promote.promo_datetime_now,
business_days = False,
sponsor_override = True),
l = VLink('link_id'),
bid = VFloat('bid', min=0, max=g.max_promote_bid,
dates=VDateRange(['startdate', 'enddate'],
future=1,
reference_date=promote.promo_datetime_now,
business_days=False,
sponsor_override=True),
l=VLink('link_id'),
bid=VFloat('bid', min=0, max=g.max_promote_bid,
coerce=False, error=errors.BAD_BID),
sr = VSubmitSR('sr', promotion=True),
campaign_id36 = nop("campaign_id36"),
targeting = VLength("targeting", 10))
sr=VSubmitSR('sr', promotion=True),
campaign_id36=nop("campaign_id36"),
targeting=VLength("targeting", 10))
def POST_edit_campaign(self, form, jquery, l, campaign_id36,
dates, bid, sr, targeting):
if not l:
return
start, end = dates or (None, None)
if start and end and not promote.is_accepted(l) and not c.user_is_sponsor:
@@ -412,11 +412,11 @@ class PromoteController(ListingController):
end = end.date()
now = promote.promo_datetime_now()
future = make_offset_date(now, g.min_promote_future,
business_days = True)
business_days=True)
if start < future.date():
c.errors.add(errors.BAD_FUTURE_DATE,
msg_params = dict(day=g.min_promote_future),
field = "startdate")
msg_params=dict(day=g.min_promote_future),
field="startdate")
if (form.has_errors('startdate', errors.BAD_DATE,
@@ -454,7 +454,7 @@ class PromoteController(ListingController):
# you cannot edit the bid of a live ad unless it's a freebie
try:
campaign = PromoCampaign._byID36(campaign_id36)
if (bid != campaign.bid and
if (bid != campaign.bid and
campaign.start_date < datetime.now(g.tz)
and not campaign.is_freebie()):
c.errors.add(errors.BID_LIVE, field='bid')
@@ -464,8 +464,8 @@ class PromoteController(ListingController):
pass
if bid is None or bid / duration < min_daily_bid:
c.errors.add(errors.BAD_BID, field = 'bid',
msg_params = {'min': min_daily_bid,
c.errors.add(errors.BAD_BID, field='bid',
msg_params={'min': min_daily_bid,
'max': g.max_promote_bid})
form.has_errors('bid', errors.BAD_BID)
return
@@ -479,8 +479,8 @@ class PromoteController(ListingController):
return
oversold = promote.is_roadblocked(sr.name, start, end)
if oversold and not c.user_is_sponsor:
c.errors.add(errors.OVERSOLD, field = 'sr',
msg_params = {"start": oversold[0].strftime('%m/%d/%Y'),
c.errors.add(errors.OVERSOLD, field='sr',
msg_params={"start": oversold[0].strftime('%m/%d/%Y'),
"end": oversold[1].strftime('%m/%d/%Y')})
form.has_errors('sr', errors.OVERSOLD)
return
@@ -501,8 +501,8 @@ class PromoteController(ListingController):
@validatedForm(VSponsor('link_id'),
VModhash(),
l = VLink('link_id'),
campaign = VPromoCampaign("campaign_id36"))
l=VLink('link_id'),
campaign=VPromoCampaign("campaign_id36"))
def POST_delete_campaign(self, form, jquery, l, campaign):
if l and campaign:
promote.delete_campaign(l, campaign)
@@ -510,8 +510,8 @@ class PromoteController(ListingController):
@validatedForm(VSponsor('container'),
VModhash(),
user = VExistingUname('name'),
thing = VByName('container'))
user=VExistingUname('name'),
thing=VByName('container'))
def POST_traffic_viewer(self, form, jquery, user, thing):
"""
Adds a user to the list of users allowed to view a promoted
@@ -519,7 +519,7 @@ class PromoteController(ListingController):
"""
if not form.has_errors("name",
errors.USER_DOESNT_EXIST, errors.NO_USER):
form.set_inputs(name = "")
form.set_inputs(name="")
form.set_html(".status:first", _("added"))
if promote.add_traffic_viewer(thing, user):
user_row = TrafficViewerList(thing).user_row('traffic', user)
@@ -530,11 +530,11 @@ class PromoteController(ListingController):
msg = user_added_messages['traffic']['pm']['msg']
subj = user_added_messages['traffic']['pm']['subject']
if msg and subj:
d = dict(url = thing.make_permalink_slow(),
traffic_url = promote.promo_traffic_url(thing),
title = thing.title)
d = dict(url=thing.make_permalink_slow(),
traffic_url=promote.promo_traffic_url(thing),
title=thing.title)
msg = msg % d
subk =msg % d
subk = msg % d
item, inbox_rel = Message._new(c.user, user,
subj, msg, request.ip)
if g.write_query_queue:
@@ -543,24 +543,24 @@ class PromoteController(ListingController):
@validatedForm(VSponsor('container'),
VModhash(),
iuser = VByName('id'),
thing = VByName('container'))
iuser=VByName('id'),
thing=VByName('container'))
def POST_rm_traffic_viewer(self, form, jquery, iuser, thing):
if thing and iuser:
promote.rm_traffic_viewer(thing, iuser)
@validatedForm(VSponsor('link'),
link = VByName("link"),
campaign = VPromoCampaign("campaign"),
customer_id = VInt("customer_id", min = 0),
pay_id = VInt("account", min = 0),
edit = VBoolean("edit"),
address = ValidAddress(
link=VByName("link"),
campaign=VPromoCampaign("campaign"),
customer_id=VInt("customer_id", min=0),
pay_id=VInt("account", min=0),
edit=VBoolean("edit"),
address=ValidAddress(
["firstName", "lastName", "company", "address",
"city", "state", "zip", "country", "phoneNumber"],
allowed_countries = g.allowed_pay_countries),
creditcard = ValidCard(["cardNumber", "expirationDate",
allowed_countries=g.allowed_pay_countries),
creditcard=ValidCard(["cardNumber", "expirationDate",
"cardCode"]))
def POST_update_pay(self, form, jquery, link, campaign, customer_id, pay_id,
edit, address, creditcard):
@@ -595,8 +595,8 @@ class PromoteController(ListingController):
_("failed to authenticate card. sorry."))
@validate(VSponsor("link"),
link = VLink("link"),
campaign = VPromoCampaign("campaign"))
link=VLink("link"),
campaign=VPromoCampaign("campaign"))
def GET_pay(self, link, campaign):
# no need for admins to play in the credit card area
if c.user_is_loggedin and c.user._id != link.author_id:
@@ -607,14 +607,14 @@ class PromoteController(ListingController):
if g.authorizenetapi:
data = get_account_info(c.user)
content = PaymentForm(link, campaign,
customer_id = data.customerProfileId,
profiles = data.paymentProfiles,
max_profiles = PROFILE_LIMIT)
customer_id=data.customerProfileId,
profiles=data.paymentProfiles,
max_profiles=PROFILE_LIMIT)
else:
content = None
res = LinkInfoPage(link = link,
content = content,
show_sidebar = False)
res = LinkInfoPage(link=link,
content=content,
show_sidebar=False)
return res.render()
def GET_link_thumb(self, *a, **kw):
@@ -624,12 +624,12 @@ class PromoteController(ListingController):
return "nothing to see here."
@validate(VSponsor("link_id"),
link = VByName('link_id'),
file = VLength('file', 500*1024))
link=VByName('link_id'),
file=VLength('file', 500 * 1024))
def POST_link_thumb(self, link=None, file=None):
if link and (not promote.is_promoted(link) or
c.user_is_sponsor or c.user.trusted_sponsor):
errors = dict(BAD_CSS_NAME = "", IMAGE_ERROR = "")
errors = dict(BAD_CSS_NAME="", IMAGE_ERROR="")
try:
# thumnails for promoted links can change and therefore expire
force_thumbnail(link, file, file_type=".jpg")
@@ -637,13 +637,13 @@ class PromoteController(ListingController):
# if the image doesn't clean up nicely, abort
errors["IMAGE_ERROR"] = _("bad image")
if any(errors.values()):
return UploadedImage("", "", "upload", errors = errors,
form_id = "image-upload").render()
return UploadedImage("", "", "upload", errors=errors,
form_id="image-upload").render()
else:
link._commit()
return UploadedImage(_('saved'), thumbnail_url(link), "",
errors = errors,
form_id = "image-upload").render()
errors=errors,
form_id="image-upload").render()
@validate(VSponsorAdmin(),
launchdate=VDate('ondate'),
@@ -655,4 +655,4 @@ class PromoteController(ListingController):
start=dates[0],
end=dates[1]).render()