Permalink
Browse files

Spotlight handles campaigns better.

  • Loading branch information...
1 parent 820cf02 commit 238a790807210c01c28a0905e3f4e36058a8750e @bsimpson63 bsimpson63 committed Feb 25, 2013
Showing with 21 additions and 14 deletions.
  1. +7 −7 r2/r2/controllers/api.py
  2. +14 −7 r2/r2/public/static/js/spotlight.js
View
@@ -3115,18 +3115,18 @@ def POST_removetrophy(self, form, jquery, secret_used, trophy):
Trophy.by_award(award, _update=True)
- @validatedForm(link=nop('link'),
- campaign=nop('campaign'))
- def GET_fetch_promo(self, form, jquery, link, campaign):
+ @validate(link=nop('link'),
+ campaign=nop('campaign'))
+ def GET_fetch_promo(self, link, campaign):
promo_tuples = [promote.PromoTuple(link, 1., campaign)]
builder = CampaignBuilder(promo_tuples,
wrap=default_thing_wrapper(),
keep_fn=promote.is_promoted)
promoted_links = builder.get_items()[0]
- listing = SpotlightListing(organic_links=[],
- promoted_links=promoted_links,
- interestbar=None).listing()
- jquery(".content").replace_things(listing)
+ if promoted_links:
+ s = SpotlightListing(promoted_links=promoted_links).listing()
+ item = s.things[0]
+ return spaceCompress(item.render())
@noresponse(VUser(),
@@ -30,10 +30,15 @@ r.spotlight.init = function() {
.shuffle()
.unshift(selectedThing)
.map(function(el) {
- var fullname = $(el).data('fullname')
+ var fullname = $(el).data('fullname'),
+ campaign = $(el).data('cid')
if (fullname) {
// convert things with ids to queries to handle stub replacement
- return '.id-' + fullname
+ if (campaign) {
+ return '[data-cid="' + campaign + '"]'
+ } else {
+ return '.id-' + fullname
+ }
} else {
return el
}
@@ -82,7 +87,7 @@ r.spotlight.chooseRandom = function() {
&& Math.random() < this.promotion_prob) {
var campaign_name = this.weighted_lottery(this.weights),
link_name = this.link_by_camp[campaign_name]
- return listing.find('.id-' + link_name)
+ return listing.find('[data-cid="' + campaign_name + '"]')
} else if (Math.random() < this.interest_prob) {
return listing.find('.interestbar')
} else {
@@ -102,12 +107,14 @@ r.spotlight._advance = function(dir) {
campaign = next.data('cid')
r.debug('fetching promo %s from campaign %s', fullname, campaign)
- next = $.getJSON('/api/fetch_promo', {
+ next = $.get('/api/fetch_promo', {
link: fullname,
campaign: campaign
- }).pipe(function(resp) {
- $.handleResponse('fetch_promo')(resp)
- return listing.find('.id-' + fullname)
+ }).pipe(function (data) {
+ var oldNext = $('[data-cid="' + campaign + '"]'),
+ newNext = $(data)
+ oldNext.replaceWith(newNext)
+ return newNext
})
}

0 comments on commit 238a790

Please sign in to comment.