Skip to content

Commit a401bad

Browse files
committed
New pay_worker_extra() function for convenience
1 parent 3b353d0 commit a401bad

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

web2py/applications/utility/models/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -579,16 +579,16 @@ def sample_from_conditions(conditions, string):
579579
580580
'''
581581
result = {}
582-
for i,(k,v) in enumerate(conditions.items()):
582+
for i,(key,value) in enumerate(conditions.items()):
583583
# Make sure each iteration gets different hash by prepending
584584
# with str(i). By attaching to front, it won't get cut off in
585585
# the substring operation [:7] in hash_to_bucket
586586
s = str(i) + string
587587

588-
if is_singleton(v):
589-
result[k] = singleton(v)
590-
elif isinstance(v, list):
591-
result[k] = hash_to_bucket(s, v)
588+
if is_singleton(value):
589+
result[key] = singleton(value)
590+
elif isinstance(value, list):
591+
result[key] = hash_to_bucket(s, value)
592592
else:
593593
soft_assert(False, 'Bad condition')
594594
return result

web2py/applications/utility/models/utiliscope/maintenance.py

+12
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ def update_ass_conditions():
129129

130130

131131
# ============== From When Shit Hit Fans =============
132+
def pay_worker_extra(workerid, amount, reason):
133+
''' Finds a recent assignment that the worker completed and pays
134+
him with it'''
135+
ass = db((db.actions.workerid==workerid)
136+
&(db.actions.action=='finished')).select(orderby=~db.actions.time,
137+
limitby=(0,1)).first()
138+
if not ass or not ass.assid:
139+
log('No assignment for worker %s' % workerid)
140+
return
141+
142+
return turk.give_bonus(ass.assid, workerid, amount, reason)
143+
132144
def pay_poor_souls():
133145
poor_souls = db((db.hits_log.creation_time < datetime(2009, 12, 28))
134146
& (db.hits_log.creation_time > datetime(2009, 11, 1))

0 commit comments

Comments
 (0)