Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Campaign url that redirects to edit_promo page

New route that takes the id36 of a promocampaign as a param and redirects to
the edit_promo page for the associated promoted link. Useful for looking up a
campaign without having to open paster shell.
  • Loading branch information...
commit a2f560cb6389081449cb4ba746c20a9883585eda 1 parent 829b0a3
@shlurbee shlurbee authored kemitche committed
2  r2/r2/config/
@@ -143,6 +143,8 @@ def make_map():
controller='promote', action='edit_promo')
+ mc('/promoted/edit_promo/pc/:campaign', controller='promote', # admin only
+ action='edit_promo_campaign')
controller='promote', action='pay')
9 r2/r2/controllers/
@@ -92,6 +92,15 @@ def GET_edit_promo(self, link):
return page.render()
+ # admin only because the route might change
+ @validate(VSponsorAdmin('campaign'),
+ campaign=VPromoCampaign('campaign'))
+ def GET_edit_promo_campaign(self, campaign):
+ if not campaign:
+ return self.abort404()
+ link = Link._byID(campaign.link_id)
+ return self.redirect(promote.promo_edit_url(link))
def GET_graph(self):
content = Promote_Graph()
27 r2/r2/controllers/validator/
@@ -347,6 +347,10 @@ class VLink(VThing):
def __init__(self, param, redirect = True, *a, **kw):
VThing.__init__(self, param, Link, redirect=redirect, *a, **kw)
+class VPromoCampaign(VThing):
+ def __init__(self, param, redirect = True, *a, **kw):
+ VThing.__init__(self, param, PromoCampaign, *a, **kw)
class VCommentByID(VThing):
def __init__(self, param, redirect = True, *a, **kw):
VThing.__init__(self, param, Comment, redirect=redirect, *a, **kw)
@@ -734,18 +738,31 @@ def run(self, link_id = None):
class VSponsor(VVerifiedUser):
Not intended to be used as a check for c.user_is_sponsor, but
- rather is the user allowed to use the sponsored link system and,
- if there is a link passed in, is the user allowed to edit the link
- in question.
+ rather is the user allowed to use the sponsored link system.
+ If a link or campaign is passed in, it also checks whether the user is
+ allowed to edit that particular sponsored link.
def user_test(self, thing):
return (thing.author_id == c.user._id)
- def run(self, link_id = None):
+ def run(self, link_id=None, campaign_id=None):
+ assert not (link_id and campaign_id), 'Pass link or campaign, not both'
if c.user_is_sponsor:
- elif link_id:
+ elif campaign_id:
+ pc = None
+ try:
+ if '_' in campaign_id:
+ pc = PromoCampaign._by_fullname(campaign_id, data=True)
+ else:
+ pc = PromoCampaign._byID36(campaign_id, data=True)
+ except (NotFound, ValueError):
+ pass
+ if pc:
+ link_id = pc.link_id
+ if link_id:
if '_' in link_id:
t = Link._by_fullname(link_id, True)
Please sign in to comment.
Something went wrong with that request. Please try again.