Example #1
0
def update_label(labelSetId, labelId):
    '''
	updates label settings
	'''
    labelSet = m.LabelSet.query.get(labelSetId)
    if not labelSet:
        raise InvalidUsage(
            _('label set {0} not found').format(labelSetId), 404)
    label = m.Label.query.get(labelId)
    if not label or label.labelSetId != labelSetId:
        raise InvalidUsage(_('label {0} not found').format(lableId), 404)

    data = MyForm(
        Field('name',
              validators=[
                  (check_label_name_uniqueness, (labelSetId, labelId)),
              ]),
        Field('description'),
        Field('shortcutKey',
              validators=[
                  (validators.is_string, (), dict(length=1)),
                  check_label_shortcut_key_non_space,
                  (check_label_shortcut_key_uniqueness, (labelSetId, labelId)),
              ]),
        Field('extract',
              validators=[
                  validators.non_blank,
                  (check_label_extract_uniqueness, (labelSetId, labelId)),
              ]),
        Field('labelGroupId',
              validators=[
                  (check_label_group_existence, (labelSetId, )),
              ]),
        Field('enabled', validators=[
            validators.is_bool,
        ]),
    ).get_data()
    # data['labelSetId'] = labelSetId

    for key in data.keys():
        value = data[key]
        if getattr(label, key) != value:
            setattr(label, key, value)
        else:
            del data[key]
    SS.flush()
    return jsonify({
        'message':
        _('updated label {0} successfully').format(labelId),
        'updatedFields':
        data.keys(),
        'label':
        m.Label.dump(label),
    })
Example #2
0
def update_label_group(labelSetId, labelGroupId):
    '''
	updates label group settings
	'''
    labelSet = m.LabelSet.query.get(labelSetId)
    if not labelSet:
        raise InvalidUsage(
            _('label set {0} not found').format(labelSetId), 404)
    labelGroup = m.LabelGroup.query.get(labelGroupId)
    if not labelGroup or labelGroup.labelSetId != labelSetId:
        raise InvalidUsage(
            _('label group {0} not found').format(labelGroupId), 404)

    data = MyForm(
        Field('name',
              validators=[
                  validators.is_string,
                  (check_label_group_name_uniqueness, (labelSetId,
                                                       labelGroupId)),
              ]),
        Field('dropDownDisplay', validators=[
            validators.is_bool,
        ]),
        Field('isMandatory', validators=[
            validators.is_bool,
        ]),
    ).get_data()

    for key in data.keys():
        value = data[key]
        if getattr(labelGroup, key) != value:
            setattr(labelGroup, key, value)
        else:
            del data[key]
    SS.flush()
    return jsonify({
        'message':
        _('updated label group {0} successfully').format(labelGroup.name),
        'labelGroup':
        m.LabelGroup.dump(labelGroup),
        'updatedFields':
        data.keys(),
    })
Example #3
0
def update_sub_task(subTaskId):
    subTask = m.SubTask.query.get(subTaskId)
    if not subTask:
        raise InvalidUsage(_('sub task {0} not found').format(subTaskId), 404)

    taskId = subTask.taskId

    # TODO: implement this
    data = MyForm(
        Field('name',
              is_mandatory=True,
              validators=[
                  validators.non_blank,
                  (check_sub_task_name_uniqueness, (taskId,
                                                    subTask.subTaskId)),
              ]),
        Field('taskId',
              is_mandatory=True,
              default=taskId,
              normalizer=lambda data, key, value: taskId),
        Field('workTypeId',
              is_mandatory=True,
              validators=[
                  check_work_type_existence,
              ]),
        Field('maxPageSize',
              default=20,
              validators=[
                  (validators.is_number, (), dict(min_value=1)),
              ]),
        Field('dstDir',
              is_mandatory=True,
              default='ltr',
              validators=[
                  (validators.enum, ('ltr', 'rtl')),
              ]),
        Field('modeId',
              is_mandatory=True,
              validators=[
                  check_batching_mode_existence,
              ]),
        Field('getPolicy',
              is_mandatory=True,
              default='nolimit',
              validators=[
                  (validators.enum, ('nolimit', 'oneonly')),
              ]),
        Field('expiryPolicy',
              is_mandatory=True,
              default='noextend',
              validators=[
                  (validators.enum, ('noextend', )),
              ]),
        Field('allowPageSkip',
              is_mandatory=True,
              default=True,
              validators=[
                  validators.is_bool,
              ]),
        Field('needItemContext',
              is_mandatory=False,
              default=False,
              validators=[
                  validators.is_bool,
              ]),
        Field('allowEditing',
              is_mandatory=True,
              default=True,
              validators=[
                  validators.is_bool,
              ]),
        Field('allowAbandon',
              is_mandatory=True,
              default=False,
              validators=[
                  validators.is_bool,
              ]),
        Field('lookAhead',
              is_mandatory=True,
              default=0,
              validators=[
                  (validators.is_number, (), dict(min_value=0)),
              ]),
        Field('lookBehind',
              is_mandatory=True,
              default=0,
              validators=[
                  (validators.is_number, (), dict(min_value=0)),
              ]),
        Field('allowCheckout',
              is_mandatory=True,
              default=False,
              validators=[
                  validators.is_bool,
              ]),
        Field('isSecondPassQa', validators=[
            validators.is_bool,
        ]),
        Field('defaultLeaseLife',
              is_mandatory=True,
              default=7 * 24 * 60 * 60,
              normalizer=normalize_interval_as_seconds,
              validators=[
                  (check_lease_life_minimal_length,
                   (datetime.timedelta(seconds=300), )),
              ]),
        Field('needDynamicTagSet',
              default=False,
              validators=[
                  validators.is_bool,
              ]),
        Field('instructionPage'),
        Field('useQaHistory', default=False, validators=[
            validators.is_bool,
        ]),
        Field('hideLabels', default=False, validators=[
            validators.is_bool,
        ]),
        Field('validators', validators=[
            validators.is_string,
        ]),
        Field('useWorkRate', validators=[
            validators.is_bool,
        ]),
        Field("enforceCheckingCriteria", validators=[
            validators.is_bool,
        ]),
    ).get_data()

    updated_fields = []

    for key in data.keys():
        value = data[key]
        if hasattr(subTask, key) and getattr(subTask, key) != value:
            setattr(subTask, key, value)
            updated_fields.append(key)

    if "enforceCheckingCriteria" in data:
        subTask.enforce_checking_criteria = data["enforceCheckingCriteria"]
        updated_fields.append("enforceCheckingCriteria")

    SS.flush()
    return jsonify({
        'message':
        _('updated sub task {0} successfully').format(subTaskId),
        'subTask':
        m.SubTask.dump(subTask, context={}),
        'updatedFields':
        updated_fields,
    })
Example #4
0
def update_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.workType != m.WorkType.WORK:
        raise InvalidUsage(
            _('only {0} sub tasks can have default QA settings').format(
                m.WorkType.WORK))

    data = MyForm(
     Field('workSubTaskId', is_mandatory=True, default=lambda: subTaskId,
      normalizer=lambda data, key, value: subTaskId,
     ),
     Field('samplingError', is_mandatory=True,
      normalizer=lambda data, key, value: float(value),
      validators=[
       (validators.is_number, (), dict(gt=0, le=0.1)),
     ]),
     Field('defaultExpectedAccuracy', is_mandatory=True,
      normalizer=lambda data, key, value: float(value),
      validators=[
       (validators.is_number, (), dict(gt=0, lt=1)),
     ]),
     Field('confidenceInterval', is_mandatory=True,
      normalizer=lambda data, key, value: float(value),
      validators=[
       (validators.is_number, (), dict(ge=0.9, lt=1)),
     ]),
     Field('qaSubTaskId', is_mandatory=True, validators=[
      check_sub_task_existence,
      (check_sub_task_attribute, (), dict(taskId=subTask.taskId)),
      (check_sub_task_type_in, (m.WorkType.QA,)),
     ]),
     # TODO: add in conditional check based on value of populateRework
     Field('populateRework', validators=[validators.is_bool]),
     Field('reworkSubTaskId', normalizer=lambda data, key, value:\
       int(value) if data['populateRework'] else None,
      validators=[
       (check_rework_sub_task_id, (), dict(taskId=subTask.taskId)),
     ]),
     Field('accuracyThreshold', normalizer=lambda data, key, value:\
       float(value) if data['populateRework'] else None,
      validators=[
       (validators.is_number, (), dict(gt=0, lt=1)),
     ]),
    ).get_data(with_view_args=False)

    me = session['current_user']
    if subTask.qaConfig:
        qaConfig = subTask.qaConfig
        for key in data.keys():
            value = data[key]
            if getattr(qaConfig, key) != value:
                setattr(qaConfig, key, value)
            else:
                del data[key]
        message = _('updated default QA settings for sub task {0}').format(
            subTaskId)
    else:
        qaConfig = m.QaConfig(updatedBy=me.userId, **data)
        SS.add(qaConfig)
        message = _('added default QA settings for sub task {0}').format(
            subTaskId)
    SS.flush()
    return jsonify({
        'message': message,
        'qaConfig': m.QaConfig.dump(qaConfig),
        'updatedFields': data.keys(),
    })