def enable_label_for_sub_task(subTaskId, labelId): rec = m.ShadowedLabel.query.get((subTaskId, labelId)) if rec: SS.delete(rec) return jsonify( message=_('label {0} has been enabled for sub task {1}').format( labelId, subTaskId))
def delete_sub_task_qa_settings(subTaskId): subTask = m.SubTask.query.get(subTaskId) if not subTask: raise InvalidUsage(_('sub task {0} not found').format(subTaskId)) if subTask.qaConfig: SS.delete(subTask.qaConfig) message = _('deleted default QA settings of sub task {0}').format( subTaskId) else: message = _('sub task {0} does not have default QA settings').format( subTaskId) return jsonify({ 'message': message, })
def delete_label_group(labelSetId, labelGroupId): ''' deletes specified label group ''' labelGroup = m.LabelGroup.query.get(labelGroupId) if not labelGroup or labelGroup.labelSetId != labelSetId: raise InvalidUsage( _('label group {0} not found').format(labelGroupId), 404) for i in labelGroup.labels: i.labelGroup = None name = labelGroup.name SS.delete(labelGroup) return jsonify({ 'message': _('deleted label group {0} sucessfully').format(name), })
def collapse_payable_events(task=None): q_keys = SS.query(m.PayableEvent.rawPieceId, m.PayableEvent.workEntryId, m.PayableEvent.batchId, m.PayableEvent.pageId).group_by( m.PayableEvent.rawPieceId, m.PayableEvent.workEntryId, m.PayableEvent.batchId, m.PayableEvent.pageId).having(func.count('*') > 1) for rawPieceId, workEntryId, batchId, pageId in q_keys.all(): events = m.PayableEvent.query.filter( m.PayableEvent.rawPieceId == rawPieceId).filter( m.PayableEvent.workEntryId == workEntryId).filter( m.PayableEvent.batchId == batchId).filter( m.PayableEvent.pageId == pageId).order_by( m.PayableEvent.created).all() while events: ev = events.pop(0) # delete event if it is neither paid nor the latest if ev.calculatedPaymentId is None and events: SS.delete(ev)
def dismiss_all_batches(subTaskId): subTask = m.SubTask.query.get(subTaskId) if not subTask: raise InvalidUsage(_('sub task {0} not found').format(subTaskId), 404) batches = m.Batch.query.filter_by(subTaskId=subTaskId).all() itemCount = 0 for b in batches: for p in b.pages: itemCount += len(p.memberEntries) for memberEntry in p.memberEntries: SS.delete(memberEntry) SS.delete(p) SS.delete(b) me = session['current_user'] now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) # add tracking information tracking_event = m.TrackingEvent(eventType='unbatch_all', userId=me.userId, tTriggeredAt=now, hostIp=request.environ['REMOTE_ADDR'], details=dict(taskId=subTask.taskId, subTaskId=subTaskId, count=len(batches))) SS.add(tracking_event) # add rework content event content_event = m.SubTaskContentEvent(subTaskId=subTaskId, isAdding=False, tProcessedAt=now, itemCount=itemCount, operator=me.userId) SS.add(content_event) SS.flush() return jsonify({ 'message': _('deleted {0} batches from sub task {1}').format( len(batches), subTaskId), })
def webservices_update_payments(): data = MyForm( Field('payroll_id', is_mandatory=True, normalizer=lambda data, key, value: int(value), validators=[ check_payroll_existence, ]), Field( 'calculated_payments', is_mandatory=True, normalizer=normalize_calculated_payments, ), Field( 'non_calculated_payments', is_mandatory=True, normalizer=normalize_non_calculated_payments, ), ).get_data(is_json=False, copy=True) payrollId = data['payroll_id'] updated = set() for d in data['calculated_payments']: cp = m.CalculatedPayment.query.get(d['calculatedPaymentId']) if not cp or cp.payrollId != payrollId: continue if cp.amount != d['amount']: cp.amount = d['amount'] updated.add(cp.taskId) existingByReceiptId = dict([ (i.identifier, i) for i in m.OtherPayment.query.filter_by(payrollId=payrollId) ]) confirmedByReceiptId = dict([(i['identifier'], i) for i in data['non_calculated_payments']]) existing = set(existingByReceiptId) confirmed = set(confirmedByReceiptId) to_delete = existing - confirmed to_add = confirmed - existing to_update = existing & confirmed for i in to_update: ncp = existingByReceiptId[i] d = confirmedByReceiptId[i] if ncp.amount != d['amount']: ncp.amount = d['amount'] updated.add(ncp.taskId) for i in to_delete: ncp = existingByReceiptId[i] updated.add(ncp.taskId) SS.delete(ncp) taskIds = set([i[0] for i in SS.query(m.Task.taskId)]) paymentTypeByName = dict([(i.name, i.paymentTypeId) for i in m.PaymentType.query]) for i in to_add: d = confirmedByReceiptId[i] user = _get_user(d['userId']) if not user: raise InvalidUsage(_('user {0} not found').format(d['userId'])) if d['taskId'] not in taskIds: # TODO: raise Error instead of ignoring it # raise RuntimeError(_('task {0} not found').format(d['taskId'])) continue paymentTypeId = paymentTypeByName.get(d['paymentType']) if paymentTypeId is None: raise InvalidUsage( _('payment type \'{0}\' not found').format(d['paymentType'])) ncp = m.OtherPayment(payrollId=payrollId, identifier=d['identifier'], paymentTypeId=paymentTypeId, taskId=d['taskId'], userId=d['userId'], amount=d['amount']) updated.add(d['taskId']) SS.add(ncp) # update impacted entries in t_costperutterance if updated: for taskId in updated: existingRecord = m.TaskPaymentRecord.query.get((taskId, payrollId)) if existingRecord: SS.delete(existingRecord) newRecord = calculate_task_payment_record(taskId, payrollId) SS.add(newRecord) return dict(entries=['success'])
def enable_tag_for_sub_task(subTaskId, tagId): rec = m.ShadowedTag.query.get((subTaskId, tagId)) if rec: SS.delete(rec) return jsonify(message=_( 'tag {0} has been enabled for sub task {1}').format(tagId, subTaskId))