本文整理汇总了Python中r2.models.PromoCampaign._by_fullname方法的典型用法代码示例。如果您正苦于以下问题:Python PromoCampaign._by_fullname方法的具体用法?Python PromoCampaign._by_fullname怎么用?Python PromoCampaign._by_fullname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r2.models.PromoCampaign
的用法示例。
在下文中一共展示了PromoCampaign._by_fullname方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _handle_adzerk
# 需要导入模块: from r2.models import PromoCampaign [as 别名]
# 或者: from r2.models.PromoCampaign import _by_fullname [as 别名]
def _handle_adzerk(msg):
data = json.loads(msg.body)
g.log.debug('data: %s' % data)
action = data.get('action')
if action == 'deactivate_link':
link = Link._by_fullname(data['link'], data=True)
_deactivate_link(link)
elif action == 'deactivate_campaign':
link = Link._by_fullname(data['link'], data=True)
campaign = PromoCampaign._by_fullname(data['campaign'], data=True)
_deactivate_campaign(link, campaign)
elif action == 'update_adzerk':
link = Link._by_fullname(data['link'], data=True)
campaign = PromoCampaign._by_fullname(data['campaign'], data=True)
_update_adzerk(link, campaign)
示例2: query
# 需要导入模块: from r2.models import PromoCampaign [as 别名]
# 或者: from r2.models.PromoCampaign import _by_fullname [as 别名]
def query(self):
if c.user_is_sponsor:
if self.sort == "future_promos":
return queries.get_all_unapproved_links()
elif self.sort == "pending_promos":
return queries.get_all_accepted_links()
elif self.sort == "unpaid_promos":
return queries.get_all_unpaid_links()
elif self.sort == "rejected_promos":
return queries.get_all_rejected_links()
elif self.sort == "live_promos" and self.sr:
return self.live_by_subreddit(self.sr)
elif self.sort == 'live_promos':
return queries.get_all_live_links()
elif self.sort == 'underdelivered':
q = queries.get_underdelivered_campaigns()
campaigns = PromoCampaign._by_fullname(list(q), data=True,
return_dict=False)
link_ids = [camp.link_id for camp in campaigns]
return [Link._fullname_from_id36(to36(id)) for id in link_ids]
elif self.sort == 'reported':
return queries.get_reported_links(get_promote_srid())
return queries.get_all_promoted_links()
else:
if self.sort == "future_promos":
return queries.get_unapproved_links(c.user._id)
elif self.sort == "pending_promos":
return queries.get_accepted_links(c.user._id)
elif self.sort == "unpaid_promos":
return queries.get_unpaid_links(c.user._id)
elif self.sort == "rejected_promos":
return queries.get_rejected_links(c.user._id)
elif self.sort == "live_promos":
return queries.get_live_links(c.user._id)
return queries.get_promoted_links(c.user._id)
示例3: _handle_adzerk
# 需要导入模块: from r2.models import PromoCampaign [as 别名]
# 或者: from r2.models.PromoCampaign import _by_fullname [as 别名]
def _handle_adzerk(msg):
data = json.loads(msg.body)
g.log.debug('data: %s' % data)
action = data.get('action')
if action == 'deactivate_orphaned_flight':
_deactivate_orphaned_flight(data['flight'])
return
link = Link._by_fullname(data['link'], data=True)
if data['campaign']:
campaign = PromoCampaign._by_fullname(data['campaign'], data=True)
else:
campaign = None
if action == 'update_adzerk':
if 'triggered_by' in data and data['triggered_by'] is not None:
triggered_by = Account._by_fullname(data['triggered_by'], data=True)
else:
triggered_by = None
_update_adzerk(link, campaign, triggered_by)
elif action == 'deactivate_overdelivered':
_deactivate_overdelivered(link, campaign)
示例4: _handle_deactivate
# 需要导入模块: from r2.models import PromoCampaign [as 别名]
# 或者: from r2.models.PromoCampaign import _by_fullname [as 别名]
def _handle_deactivate(payload):
campaign_ids = payload["campaigns"] and payload["campaigns"].split(",")
if not campaign_ids:
return
campaigns = PromoCampaign._by_fullname(campaign_ids, data=True)
lineitems_service.deactivate(campaign_ids)
示例5: update_served
# 需要导入模块: from r2.models import PromoCampaign [as 别名]
# 或者: from r2.models.PromoCampaign import _by_fullname [as 别名]
def update_served(items):
for item in items:
if not item.promoted:
continue
campaign = PromoCampaign._by_fullname(item.campaign)
if not campaign.has_served:
campaign.has_served = True
campaign._commit()
示例6: _handle_upsert_campaign
# 需要导入模块: from r2.models import PromoCampaign [as 别名]
# 或者: from r2.models.PromoCampaign import _by_fullname [as 别名]
def _handle_upsert_campaign(payload):
link = Link._by_fullname(payload["link"], data=True)
campaign = PromoCampaign._by_fullname(payload["campaign"], data=True)
owner = Account._byID(campaign.owner_id)
lineitem = lineitems_service.upsert_lineitem(owner, campaign)
creative = creatives_service.get_creative(link)
lineitems_service.associate_with_creative(
lineitem=lineitem, creative=creative)
示例7: filter_campaigns
# 需要导入模块: from r2.models import PromoCampaign [as 别名]
# 或者: from r2.models.PromoCampaign import _by_fullname [as 别名]
def filter_campaigns(date, fullnames):
campaigns = PromoCampaign._by_fullname(fullnames, data=True, return_dict=False)
# filter out campaigns that shouldn't be live
pc_date = datetime.datetime(date.year, date.month, date.day, 0, 0, tzinfo=g.tz)
campaigns = [camp for camp in campaigns if camp.start_date <= pc_date <= camp.end_date]
# check for links with targeted campaigns - we can't handle them now
has_targeted = [camp.link_id for camp in campaigns if camp.sr_name != ""]
return [camp for camp in campaigns if camp.link_id not in has_targeted]
示例8: _handle_adzerk
# 需要导入模块: from r2.models import PromoCampaign [as 别名]
# 或者: from r2.models.PromoCampaign import _by_fullname [as 别名]
def _handle_adzerk(msg):
data = json.loads(msg.body)
g.log.debug('data: %s' % data)
action = data.get('action')
link = Link._by_fullname(data['link'], data=True)
if data['campaign']:
campaign = PromoCampaign._by_fullname(data['campaign'], data=True)
else:
campaign = None
if action == 'update_adzerk':
_update_adzerk(link, campaign)
elif action == 'deactivate_overdelivered':
_deactivate_overdelivered(link, campaign)
示例9: _handle_upsert_campaign
# 需要导入模块: from r2.models import PromoCampaign [as 别名]
# 或者: from r2.models.PromoCampaign import _by_fullname [as 别名]
def _handle_upsert_campaign(payload):
link = Link._by_fullname(payload["link"], data=True)
campaign = PromoCampaign._by_fullname(payload["campaign"], data=True)
owner = Account._byID(campaign.owner_id)
author = Account._byID(link.author_id)
try:
lineitem = lineitems_service.upsert_lineitem(owner, campaign)
except ValueError as e:
g.log.error("unable to upsert lineitem: %s" % e)
return
creative = creatives_service.upsert_creative(author, link)
lineitems_service.associate_with_creative(
lineitem=lineitem, creative=creative)
示例10: make_daily_promotions
# 需要导入模块: from r2.models import PromoCampaign [as 别名]
# 或者: from r2.models.PromoCampaign import _by_fullname [as 别名]
def make_daily_promotions(offset=0, test=False):
"""
Arguments:
offset - number of days after today to get the schedule for
test - if True, new schedule will be generated but not launched
Raises Exception with list of campaigns that had errors if there were any
"""
scheduled_adweights, error_campaigns = get_scheduled(offset)
current_adweights_byid = get_live_promotions([LiveAdWeights.ALL_ADS])
current_adweights = current_adweights_byid[LiveAdWeights.ALL_ADS]
link_names = [aw.link for aw in itertools.chain(scheduled_adweights,
current_adweights)]
links = Link._by_fullname(link_names, data=True)
camp_names = [aw.campaign for aw in itertools.chain(scheduled_adweights,
current_adweights)]
campaigns = PromoCampaign._by_fullname(camp_names, data=True)
srs = Subreddit._by_name([camp.sr_name for camp in campaigns.itervalues()
if camp.sr_name])
expired_links = ({aw.link for aw in current_adweights} -
{aw.link for aw in scheduled_adweights})
for link_name in expired_links:
link = links[link_name]
if is_promoted(link):
if test:
print "unpromote", link_name
else:
# update the query queue
set_promote_status(link, PROMOTE_STATUS.finished)
emailer.finished_promo(link)
by_srid = defaultdict(list)
for adweight in scheduled_adweights:
link = links[adweight.link]
campaign = campaigns[adweight.campaign]
if campaign.sr_name:
sr = srs[campaign.sr_name]
sr_id = sr._id
sr_over_18 = sr.over_18
else:
sr_id = ''
sr_over_18 = False
if sr_over_18:
if test:
print "over18", link._fullname
else:
link.over_18 = True
link._commit()
if is_accepted(link) and not is_promoted(link):
if test:
print "promote2", link._fullname
else:
# update the query queue
set_promote_status(link, PROMOTE_STATUS.promoted)
emailer.live_promo(link)
by_srid[sr_id].append(adweight)
if not test:
set_live_promotions(by_srid)
_mark_promos_updated()
else:
print by_srid
finalize_completed_campaigns(daysago=offset+1)
hooks.get_hook('promote.make_daily_promotions').call(offset=offset)
# after launching as many campaigns as possible, raise an exception to
# report any error campaigns. (useful for triggering alerts in irc)
if error_campaigns:
raise Exception("Some scheduled campaigns could not be added to daily "
"promotions: %r" % error_campaigns)
示例11: _handle_deactivate_campaign
# 需要导入模块: from r2.models import PromoCampaign [as 别名]
# 或者: from r2.models.PromoCampaign import _by_fullname [as 别名]
def _handle_deactivate_campaign(payload):
campaign = PromoCampaign._by_fullname(payload["campaign"])
lineitem = lineitems_service.get_lineitem(campaign)
if lineitem:
lineitems_service.deactivate(lineitem)