• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python hooks.get_hook函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中r2.lib.hooks.get_hook函数的典型用法代码示例。如果您正苦于以下问题:Python get_hook函数的具体用法?Python get_hook怎么用?Python get_hook使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_hook函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: cast_vote

def cast_vote(user, thing, direction, **data):
    """Register a vote and queue it for processing."""
    update_vote_lookups(user, thing, direction)

    vote_data = {
        "user_id": user._id,
        "thing_fullname": thing._fullname,
        "direction": direction,
        "date": int(epoch_timestamp(datetime.now(g.tz))),
    }

    data['ip'] = getattr(request, "ip", None)
    if data['ip'] is not None:
        data['org'] = organization_by_ips(data['ip'])
    vote_data['data'] = data

    hooks.get_hook("vote.get_vote_data").call(
        data=vote_data["data"],
        user=user,
        thing=thing,
        request=request,
        context=c,
    )

    # The vote event will actually be sent from an async queue processor, so
    # we need to pull out the context data at this point
    if not g.running_as_script:
        vote_data["event_data"] = {
            "context": Event.get_context_data(request, c),
            "sensitive": Event.get_sensitive_context_data(request, c),
        }

    amqp.add_item(thing.vote_queue_name, json.dumps(vote_data))
开发者ID:Arinzeokeke,项目名称:reddit,代码行数:33,代码来源:voting.py


示例2: use

    def use(self):
        hooks.get_hook("js_preload.use").call(js_preload=self)

        if self.data:
            return js.DataSource.use(self)
        else:
            return ''
开发者ID:DreamRivulet,项目名称:reddit,代码行数:7,代码来源:template_helpers.py


示例3: void_campaign

def void_campaign(link, campaign):
    transactions = get_transactions(link, [campaign])
    bid_record = transactions.get(campaign._id)
    if bid_record:
        a = Account._byID(link.author_id)
        authorize.void_transaction(a, bid_record.transaction, campaign._id)
    hooks.get_hook('campaign.void').call(link=link, campaign=campaign)
开发者ID:Alex-Quinn,项目名称:reddit,代码行数:7,代码来源:promote.py


示例4: accept_promotion

def accept_promotion(link):
    """
    Accepting is campaign agnostic.  Accepting the ad just means that
    it is allowed to run if payment has been processed.

    If a campagn is able to run, this also requeues it.
    """
    PromotionLog.add(link, 'status update: accepted')
    # update the query queue

    set_promote_status(link, PROMOTE_STATUS.accepted)

    # campaigns that should be live now must be updated
    now = promo_datetime_now(0)
    if link._fullname in set(l.thing_name for l in
                             PromotionWeights.get_campaigns(now)):
        PromotionLog.add(link, 'Marked promotion for acceptance')
        charge_pending(0) # campaign must be charged before it will go live
        queue_changed_promo(link, "accepted")

    # campaigns that were charged and will go live in the future must be updated
    future_campaigns = [camp for camp in PromoCampaign._by_link(link._id)
                        if camp.start_date > now]
    transactions = get_transactions(link, future_campaigns)
    charged_campaigns = [camp for camp in future_campaigns
                         if (transactions.get(camp._id) and
                             transactions.get(camp._id).is_charged())]
    for campaign in charged_campaigns:
        hooks.get_hook('campaign.edit').call(link=link, campaign=campaign)

    if link._spam:
        link._spam = False
        link._commit()
    emailer.accept_promo(link)
开发者ID:Hmaal,项目名称:reddit,代码行数:34,代码来源:promote.py


示例5: charge_pending

def charge_pending(offset=1):
    for l, camp, weight in accepted_campaigns(offset=offset):
        user = Account._byID(l.author_id)
        try:
            if charged_or_not_needed(camp):
                continue

            charge_succeeded = authorize.charge_transaction(user, camp.trans_id,
                                                            camp._id)

            if not charge_succeeded:
                continue

            hooks.get_hook('promote.new_charge').call(link=l, campaign=camp)

            if is_promoted(l):
                emailer.queue_promo(l, camp.bid, camp.trans_id)
            else:
                set_promote_status(l, PROMOTE_STATUS.pending)
                emailer.queue_promo(l, camp.bid, camp.trans_id)
            text = ('auth charge for campaign %s, trans_id: %d' %
                    (camp._id, camp.trans_id))
            PromotionLog.add(l, text)
        except:
            print "Error on %s, campaign %s" % (l, camp._id)
开发者ID:AD42,项目名称:reddit,代码行数:25,代码来源:promote.py


示例6: charge_campaign

def charge_campaign(link, campaign):
    if charged_or_not_needed(campaign):
        return

    user = Account._byID(link.author_id)
    success, reason = authorize.charge_transaction(user, campaign.trans_id,
                                                   campaign._id)

    if not success:
        if reason == authorize.TRANSACTION_NOT_FOUND:
            # authorization hold has expired
            original_trans_id = campaign.trans_id
            campaign.trans_id = NO_TRANSACTION
            campaign._commit()
            text = ('voided expired transaction for %s: (trans_id: %d)'
                    % (campaign, original_trans_id))
            PromotionLog.add(link, text)
        return

    hooks.get_hook('promote.edit_campaign').call(link=link, campaign=campaign)

    if not is_promoted(link):
        update_promote_status(link, PROMOTE_STATUS.pending)

    emailer.queue_promo(link, campaign.bid, campaign.trans_id)
    text = ('auth charge for campaign %s, trans_id: %d' %
            (campaign._id, campaign.trans_id))
    PromotionLog.add(link, text)
开发者ID:APerson241,项目名称:reddit,代码行数:28,代码来源:promote.py


示例7: POST_update

    def POST_update(self, form, jquery, text):
        if form.has_errors("body", errors.NO_TEXT,
                                   errors.TOO_LONG):
            return

        # create and store the new update
        update = LiveUpdate(data={
            "author_id": c.user._id,
            "body": text,
            "_spam": c.user._spam,
        })

        hooks.get_hook("liveupdate.update").call(update=update)

        LiveUpdateStream.add_update(c.liveupdate_event, update)

        # tell the world about our new update
        builder = LiveUpdateBuilder(None)
        wrapped = builder.wrap_items([update])[0]
        rendered = wrapped.render(style="api")
        _broadcast(type="update", payload=rendered)

        # Queue up parsing any embeds
        queue_parse_embeds(c.liveupdate_event, update)

        # reset the submission form
        t = form.find("textarea")
        t.attr('rows', 3).html("").val("")
开发者ID:hubwub,项目名称:reddit-plugin-liveupdate,代码行数:28,代码来源:controllers.py


示例8: apply_effects

    def apply_effects(self):
        """Apply the effects of the vote to the thing that was voted on."""
        # remove the old vote
        if self.previous_vote and self.previous_vote.affected_thing_attr:
            self.thing._incr(self.previous_vote.affected_thing_attr, -1)

        if (self.previous_vote and not self.previous_vote.effects.affects_score and
            self.previous_vote.is_self_vote):
            self.thing._incr('_ups', -1)

        # add the new vote
        if self.affected_thing_attr:
            self.thing._incr(self.affected_thing_attr, 1)

        if self.effects.affects_karma:
            change = self.effects.karma_change
            if self.previous_vote:
                change -= self.previous_vote.effects.karma_change

            if change:
                self.thing.author_slow.incr_karma(
                    kind=self.thing.affects_karma_type,
                    sr=self.thing.subreddit_slow,
                    amt=change,
                )

        hooks.get_hook("vote.apply_effects").call(vote=self)
开发者ID:judys-io,项目名称:reddit,代码行数:27,代码来源:vote.py


示例9: accept_promotion

def accept_promotion(link):
    """
    Accepting is campaign agnostic.  Accepting the ad just means that
    it is allowed to run if payment has been processed.

    If a campagn is able to run, this also requeues it.
    """
    # update the query queue
    set_promote_status(link, PROMOTE_STATUS.accepted)

    # campaigns that should be live now must be updated
    now = promo_datetime_now(0)
    promotion_weights = PromotionWeights.get_campaigns(now)
    live_campaigns = {pw.promo_idx for pw in promotion_weights if pw.thing_name == link._fullname}
    if live_campaigns:
        campaigns = PromoCampaign._byID(live_campaigns, data=True, return_dict=False)
        PromotionLog.add(link, "has live campaigns, forcing live")
        charge_pending(0)  # campaign must be charged before it will go live
        for campaign in campaigns:
            hooks.get_hook("campaign.edit").call(link=link, campaign=campaign)
        queue_changed_promo(link, "accepted")

    # campaigns that were charged and will go live in the future must be updated
    future_campaigns = [camp for camp in PromoCampaign._by_link(link._id) if camp.start_date > now]
    transactions = get_transactions(link, future_campaigns)
    charged_campaigns = [
        camp for camp in future_campaigns if (transactions.get(camp._id) and transactions.get(camp._id).is_charged())
    ]
    for campaign in charged_campaigns:
        hooks.get_hook("campaign.edit").call(link=link, campaign=campaign)

    if link._spam:
        link._spam = False
        link._commit()
    emailer.accept_promo(link)
开发者ID:Kingofhearts102,项目名称:reddit,代码行数:35,代码来源:promote.py


示例10: edit_campaign

def edit_campaign(link, campaign, dates, bid, cpm, sr, priority):
    sr_name = sr.name if sr else ""  # empty string means target to all
    try:
        # if the bid amount changed, cancel any pending transactions
        if campaign.bid != bid:
            void_campaign(link, campaign)

        # update the schedule
        PromotionWeights.reschedule(link, campaign._id, sr_name, dates[0], dates[1], bid)

        # update values in the db
        campaign.update(dates[0], dates[1], bid, cpm, sr_name, campaign.trans_id, priority, commit=True)

        if campaign.priority.cpm:
            # record the transaction
            text = "updated campaign %s. (bid: %0.2f)" % (campaign._id, bid)
            PromotionLog.add(link, text)

            # make it a freebie, if applicable
            author = Account._byID(link.author_id, True)
            if getattr(author, "complimentary_promos", False):
                free_campaign(link, campaign, c.user)

        hooks.get_hook("campaign.edit").call(link=link, campaign=campaign)

    except Exception, e:  # record error and rethrow
        g.log.error("Failed to update PromoCampaign %s on link %d. Error was: %r" % (campaign._id, link._id, e))
        try:  # wrapped in try/except so orig error won't be lost if commit fails
            text = "update FAILED. (campaign: %s, bid: %.2f)" % (campaign._id, bid)
            PromotionLog.add(link, text)
        except:
            pass
        raise e
开发者ID:Kingofhearts102,项目名称:reddit,代码行数:33,代码来源:promote.py


示例11: accept

    def accept(cls, things, correct=True):
        from r2.lib.db import queries

        things = tup(things)

        things_by_cls = {}
        for thing in things:
            things_by_cls.setdefault(thing.__class__, []).append(thing)

        for thing_cls, cls_things in things_by_cls.iteritems():
            to_clear = []
            # look up all of the reports for each thing
            rel_cls = cls.rel(Account, thing_cls)
            thing_ids = [t._id for t in cls_things]
            rels = list(rel_cls._query(rel_cls.c._thing2_id == thing_ids))
            for r in rels:
                if r._name == '0':
                    r._name = '1' if correct else '-1'
                    r._commit()

            for thing in cls_things:
                if thing.reported > 0:
                    thing.reported = 0
                    thing._commit()
                    to_clear.append(thing)

            queries.clear_reports(to_clear, rels)

            if correct:
                hooks.get_hook("report.accept").call(reports=rels)
            else:
                hooks.get_hook("report.reject").call(reports=rels)
开发者ID:zeantsoi,项目名称:reddit,代码行数:32,代码来源:report.py


示例12: edit_campaign

def edit_campaign(link, campaign, dates, bid, cpm, sr, priority):
    sr_name = sr.name if sr else '' # empty string means target to all

    # if the bid amount changed, cancel any pending transactions
    if campaign.bid != bid:
        void_campaign(link, campaign)

    # update the schedule
    PromotionWeights.reschedule(link, campaign._id, sr_name,
                                dates[0], dates[1], bid)

    # update values in the db
    campaign.update(dates[0], dates[1], bid, cpm, sr_name,
                    campaign.trans_id, priority, commit=True)

    if campaign.priority.cpm:
        # record the transaction
        text = 'updated campaign %s. (bid: %0.2f)' % (campaign._id, bid)
        PromotionLog.add(link, text)

        # make it a freebie, if applicable
        author = Account._byID(link.author_id, True)
        if getattr(author, "complimentary_promos", False):
            free_campaign(link, campaign, c.user)

    hooks.get_hook('promote.edit_campaign').call(link=link, campaign=campaign)
开发者ID:Lax100,项目名称:reddit,代码行数:26,代码来源:promote.py


示例13: toggle_pause_campaign

def toggle_pause_campaign(link, campaign, should_pause):
    campaign.paused = should_pause
    campaign._commit()

    action = "paused" if should_pause else "resumed"
    PromotionLog.add(link, "%s campaign %s" % (action, campaign._id))

    hooks.get_hook("promote.edit_campaign").call(link=link, campaign=campaign)
开发者ID:travmi,项目名称:reddit,代码行数:8,代码来源:promote.py


示例14: _on_create

    def _on_create(self):
        hooks.get_hook("oauth2.create_token").call(token=self)

        # update the by-user view
        if self.user_id:
            self._by_user_view()._set_values(str(self.user_id), {self._id: ''})

        return super(OAuth2AccessToken, self)._on_create()
开发者ID:AppleBetas,项目名称:reddit,代码行数:8,代码来源:token.py


示例15: js_config

def js_config(extra_config=None):
    logged = c.user_is_loggedin and c.user.name
    gold = bool(logged and c.user.gold)

    config = {
        # is the user logged in?
        "logged": logged,
        # the subreddit's name (for posts)
        "post_site": c.site.name if not c.default_sr else "",
        # the user's voting hash
        "modhash": c.modhash or False,
        # the current rendering style
        "renderstyle": c.render_style,

        # they're welcome to try to override this in the DOM because we just
        # disable the features server-side if applicable
        'store_visits': gold and c.user.pref_store_visits,

        # current domain
        "cur_domain": get_domain(cname=c.frameless_cname, subreddit=False, no_www=True),
        # where do ajax requests go?
        "ajax_domain": get_domain(cname=c.authorized_cname, subreddit=False),
        "extension": c.extension,
        "https_endpoint": is_subdomain(request.host, g.domain) and g.https_endpoint,
        # does the client only want to communicate over HTTPS?
        "https_forced": c.user.https_forced,
        # debugging?
        "debug": g.debug,
        "send_logs": g.live_config["frontend_logging"],
        "server_time": math.floor(time.time()),
        "status_msg": {
          "fetching": _("fetching title..."),
          "submitting": _("submitting..."),
          "loading": _("loading...")
        },
        "is_fake": isinstance(c.site, FakeSubreddit),
        "fetch_trackers_url": g.fetch_trackers_url,
        "adtracker_url": g.adtracker_url,
        "clicktracker_url": g.clicktracker_url,
        "uitracker_url": g.uitracker_url,
        "static_root": static(''),
        "over_18": bool(c.over18),
        "new_window": bool(c.user.pref_newwindow),
        "vote_hash": c.vote_hash,
        "gold": gold,
        "has_subscribed": logged and c.user.has_subscribed,
    }

    if g.uncompressedJS:
        config["uncompressedJS"] = True

    if extra_config:
        config.update(extra_config)

    hooks.get_hook("js_config").call(config=config)

    return config
开发者ID:JingyanZ,项目名称:reddit,代码行数:57,代码来源:template_helpers.py


示例16: toggle_pause_campaign

def toggle_pause_campaign(link, campaign, should_pause):
    campaign.paused = should_pause
    campaign._commit()

    action = 'paused' if should_pause else 'resumed'
    PromotionLog.add(link, '%s campaign %s' % (action, campaign._id))

    hooks.get_hook('promote.edit_campaign').call(link=link,
        campaign=campaign)
开发者ID:pra85,项目名称:reddit,代码行数:9,代码来源:promote.py


示例17: review_fraud

def review_fraud(link, is_fraud):
    link.fraud = is_fraud
    link._commit()
    PromotionLog.add(link, "marked as fraud" if is_fraud else "resolved as not fraud")
    queries.unset_payment_flagged_link(link)

    if is_fraud:
        reject_promotion(link, "fraud")
        hooks.get_hook("promote.fraud_identified").call(link=link, sponsor=c.user)
开发者ID:APerson241,项目名称:reddit,代码行数:9,代码来源:promote.py


示例18: edit_campaign

def edit_campaign(link, campaign, dates, bid, cpm, target, priority, location,
                  platform='desktop', mobile_os=None):
    changed = {}
    if bid != campaign.bid:
         # if the bid amount changed, cancel any pending transactions
        void_campaign(link, campaign, reason='changed_bid')
        changed['bid'] = ("$%0.2f" % campaign.bid, "$%0.2f" % bid)
        hooks.get_hook('promote.edit_bid').call(
            link=link,campaign=campaign, previous=campaign.bid, current=bid)
        campaign.bid = bid
    if dates[0] != campaign.start_date or dates[1] != campaign.end_date:
        original = '%s to %s' % (campaign.start_date, campaign.end_date)
        edited = '%s to %s' % (dates[0], dates[1])
        changed['dates'] = (original, edited)
        campaign.start_date = dates[0]
        campaign.end_date = dates[1]
    if cpm != campaign.cpm:
        changed['cpm'] = (campaign.cpm, cpm)
        campaign.cpm = cpm
    if target != campaign.target:
        changed['target'] = (campaign.target, target)
        campaign.target = target
    if priority != campaign.priority:
        changed['priority'] = (campaign.priority.name, priority.name)
        campaign.priority = priority
    if location != campaign.location:
        changed['location'] = (campaign.location, location)
        campaign.location = location
    if platform != campaign.platform:
        changed["platform"] = (campaign.platform, platform)
        campaign.platform = platform
    if mobile_os != campaign.mobile_os:
        changed["mobile_os"] = (campaign.mobile_os, mobile_os)
        campaign.mobile_os = mobile_os

    change_strs = map(lambda t: '%s: %s -> %s' % (t[0], t[1][0], t[1][1]),
                      changed.iteritems())
    change_text = ', '.join(change_strs)
    campaign._commit()

    # update the index
    PromotionWeights.reschedule(link, campaign)

    if campaign.priority.cpm:
        # make it a freebie, if applicable
        author = Account._byID(link.author_id, True)
        if getattr(author, "complimentary_promos", False):
            free_campaign(link, campaign, c.user)

    # record the changes
    if change_text:
        PromotionLog.add(link, 'edited %s: %s' % (campaign, change_text))

    hooks.get_hook('promote.edit_campaign').call(link=link, campaign=campaign)
开发者ID:rizha,项目名称:reddit,代码行数:54,代码来源:promote.py


示例19: run_trylater

def run_trylater():
    our_hooks = (key[len(PREFIX):] for key in all_hooks().keys()
                 if key.startswith(PREFIX))
    with TryLater.multi_handle(our_hooks) as handleable:
        for system, data in handleable.iteritems():
            hook_name = "trylater.%s" % system
            g.log.info("Trying %s", system)

            get_hook(hook_name).call(data=data)

    amqp.worker.join()
开发者ID:AjaxGb,项目名称:reddit,代码行数:11,代码来源:trylater.py


示例20: new_campaign

def new_campaign(link, dates, bid, cpm, target, priority, location, platform, mobile_os):
    campaign = PromoCampaign.create(link, target, bid, cpm, dates[0], dates[1], priority, location, platform, mobile_os)
    PromotionWeights.add(link, campaign)
    PromotionLog.add(link, "campaign %s created" % campaign._id)

    if campaign.priority.cpm:
        author = Account._byID(link.author_id, data=True)
        if getattr(author, "complimentary_promos", False):
            free_campaign(link, campaign, c.user)

    hooks.get_hook("promote.new_campaign").call(link=link, campaign=campaign)
    return campaign
开发者ID:karthikv,项目名称:reddit,代码行数:12,代码来源:promote.py



注:本文中的r2.lib.hooks.get_hook函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python jsontemplates.is_api函数代码示例发布时间:2022-05-26
下一篇:
Python hardcachebackend.HardCacheBackend类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap