How to use on_accept method in ATX

Best Python code snippet using ATX

badges.py

Source:badges.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3 solace.badges4 ~~~~~~~~~~~~~5 This module implements the badge system.6 :copyright: (c) 2009 by Plurk Inc., see AUTHORS for more details.7 :license: BSD, see LICENSE for more details.8"""9from operator import attrgetter10from solace.i18n import lazy_gettext, _11from solace.utils.remoting import RemoteObject12def try_award(event, *args):13 """Tries to avard a badge for the given event. The events correspond14 to the `on_X` callbacks on the badges, just without the `on_` prefix.15 """16 lookup = attrgetter('on_' + event)17 for badge in badge_list:18 cb = lookup(badge)19 if cb is None:20 continue21 user = cb(*args)22 if user is not None:23 if isinstance(user, tuple):24 user, payload = user25 else:26 payload = None27 if badge.single_awarded and badge in user.badges:28 continue29 user._badges.append(UserBadge(badge, payload))30 # inactive or banned users don't get messages.31 if user.is_active and not user.is_banned:32 UserMessage(user, _(u'You earned the “%s” badge') % badge.name)33_numeric_levels = dict(zip(('bronce', 'silver', 'gold', 'platin'),34 range(4)))35class Badge(RemoteObject):36 """Represents a badge.37 It can react to the following events::38 on_vote = lambda user, post, delta39 on_accept = lambda user, post, answer40 on_reply = lambda user, post41 on_new_topic = lambda user, topic42 on_edit = lambda user, post43 """44 remote_object_type = 'solace.badge'45 public_fields = ('level', 'identifier', 'name', 'description')46 def __init__(self, level, identifier, name, description=None,47 single_awarded=False,48 on_vote=None, on_accept=None, on_reply=None,49 on_new_topic=None, on_edit=None):50 assert level in ('bronce', 'silver', 'gold', 'platin')51 assert len(identifier) <= 3052 self.level = level53 self.identifier = identifier54 self.name = name55 self.single_awarded = single_awarded56 self.description = description57 self.on_vote = on_vote58 self.on_accept = on_accept59 self.on_reply = on_reply60 self.on_new_topic = on_new_topic61 self.on_edit = on_edit62 @property63 def numeric_level(self):64 return _numeric_levels[self.level]65 def get_url_values(self):66 return 'badges.show_badge', {'identifier': self.identifier}67 def __repr__(self):68 return '<%s \'%s\' (%s)>' % (69 type(self).__name__,70 self.name.encode('utf-8'),71 ('bronce', 'silver', 'gold', 'platin')[self.numeric_level]72 )73def _try_award_special_answer(post, badge, votes_required):74 """Helper for nice and good answer."""75 pid = str(post.id)76 user = post.author77 for user_badge in user._badges:78 if user_badge.badge == badge and \79 user_badge.payload == pid:80 return81 if post.is_answer and post.votes >= votes_required:82 return user, pid83def _try_award_self_learner(post):84 """Helper for the self learner badge."""85 pid = str(post.id)86 user = post.author87 for user_badge in user._badges:88 if user_badge.badge == SELF_LEARNER and \89 user_badge.payload == pid:90 return91 if post.is_answer and post.author == post.topic.author \92 and post.votes >= 3:93 return user, pid94def _try_award_reversal(post):95 """Helper for the reversal badge."""96 pid = str(post.id)97 user = post.author98 for user_badge in user._badges:99 if user_badge.badge == REVERSAL and \100 user_badge.payload == pid:101 return102 if post.is_answer and post.votes >= 20 and \103 post.topic.votes <= -5:104 return user, pid105CRITIC = Badge('bronce', 'critic', lazy_gettext(u'Critic'),106 lazy_gettext(u'First down vote'),107 single_awarded=True,108 on_vote=lambda user, post, delta:109 user if delta < 0 and user != post.author else None110)111SELF_CRITIC = Badge('silver', 'self-critic', lazy_gettext(u'Self-Critic'),112 lazy_gettext(u'First downvote on own reply or question'),113 single_awarded=True,114 on_vote=lambda user, post, delta:115 user if delta < 0 and user == post.author else None116)117EDITOR = Badge('bronce', 'editor', lazy_gettext(u'Editor'),118 lazy_gettext(u'First edited post'),119 single_awarded=True,120 on_edit=lambda user, post: user121)122INQUIRER = Badge('bronce', 'inquirer', lazy_gettext(u'Inquirer'),123 lazy_gettext(u'First asked question'),124 single_awarded=True,125 on_new_topic=lambda user, topic: user126)127TROUBLESHOOTER = Badge('silver', 'troubleshooter',128 lazy_gettext(u'Troubleshooter'),129 lazy_gettext(u'First answered question'),130 single_awarded=True,131 on_accept=lambda user, topic, post: post.author if post else None132)133NICE_ANSWER = Badge('bronce', 'nice-answer', lazy_gettext(u'Nice Answer'),134 lazy_gettext(u'Answer was upvoted 10 times'),135 on_accept=lambda user, topic, post: _try_award_special_answer(post,136 NICE_ANSWER, 10) if post else None,137 on_vote=lambda user, post, delta: _try_award_special_answer(post,138 NICE_ANSWER, 10)139)140GOOD_ANSWER = Badge('silver', 'good-answer', lazy_gettext(u'Good Answer'),141 lazy_gettext(u'Answer was upvoted 25 times'),142 on_accept=lambda user, topic, post: _try_award_special_answer(post,143 GOOD_ANSWER, 25) if post else None,144 on_vote=lambda user, post, delta: _try_award_special_answer(post,145 GOOD_ANSWER, 25)146)147GREAT_ANSWER = Badge('gold', 'great-answer', lazy_gettext(u'Great Answer'),148 lazy_gettext(u'Answer was upvoted 75 times'),149 on_accept=lambda user, topic, post: _try_award_special_answer(post,150 GOOD_ANSWER, 75) if post else None,151 on_vote=lambda user, post, delta: _try_award_special_answer(post,152 GOOD_ANSWER, 75)153)154UNIQUE_ANSWER = Badge('platin', 'unique-answer', lazy_gettext(u'Unique Answer'),155 lazy_gettext(u'Answer was upvoted 150 times'),156 on_accept=lambda user, topic, post: _try_award_special_answer(post,157 GOOD_ANSWER, 150) if post else None,158 on_vote=lambda user, post, delta: _try_award_special_answer(post,159 GOOD_ANSWER, 150)160)161REVERSAL = Badge('gold', 'reversal', lazy_gettext(u'Reversal'),162 lazy_gettext(u'Provided answer of +20 score to a question of -5 score'),163 on_accept=lambda user, topic, post: _try_award_reversal(post) if post else None,164 on_vote=lambda user, post, delta: _try_award_reversal(post)165)166SELF_LEARNER = Badge('silver', 'self-learner', lazy_gettext(u'Self-Learner'),167 lazy_gettext(u'Answered your own question with at least 4 upvotes'),168 on_accept=lambda user, topic, post: _try_award_self_learner(post) if post else None,169 on_vote=lambda user, post, delta: _try_award_self_learner(post)170)171#: list of all badges172badge_list = [CRITIC, EDITOR, INQUIRER, TROUBLESHOOTER, NICE_ANSWER,173 GOOD_ANSWER, SELF_LEARNER, SELF_CRITIC, GREAT_ANSWER,174 UNIQUE_ANSWER, REVERSAL]175#: all the badges by key176badges_by_id = dict((x.identifier, x) for x in badge_list)177# circular dependencies...

Full Screen

Full Screen

desktop_file_dialogs.py

Source:desktop_file_dialogs.py Github

copy

Full Screen

...45 self._validate_initial_directory()46 def show(self):47 path = self.show_dialog(**self.args)48 if(path):49 self.on_accept(path)50 else:51 self.on_cancel()52 def _validate_initial_directory(self):53 if not(self.initial_directory):54 self.initial_directory = os.path.abspath(os.sep)55 else:56 if not(os.path.isdir(self.initial_directory)):57 raise ValueError(f"\n\t_invalid Directory: '{self.initial_directory}'")58########################################################################################################################################################################################################################################################################################################~{#59#//////| Dialogs |//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////g2#60########################################################################################################################################################################################################################################################################################################~}#61class Desktop_FolderDialog(Desktop_FileDialog_Base):62 @property63 def args(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ATX automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful