Exemple #1
0
def update_anomaly():
    id = request.form['pk']
    # UID for field will be ala [fieldname]-[classname]-[id]-editable, field name will be first section always
    field = request.form['name'].split('-')[0]
    field_value = request.form['value']
    original_value = None
    anomaly = Anomaly.get_by_id(id)

    if field == 'name':
        original_value = anomaly.name
        anomaly.update(name=field_value)
    elif field == 'summary':
        original_value = anomaly.summary
        anomaly.update(summary=field_value)
    elif field == 'analysis':
        original_value = anomaly.analysis
        anomaly.update(analysis=field_value)
    elif field == 'software_version':
        original_value = anomaly.software_version
        anomaly.update(software_version=field_value)
    elif field == 'criticality':
        if anomaly.criticality:
            original_value = anomaly.criticality.name
        criticality = Criticality.get_by_id(field_value)
        anomaly.update(criticality=criticality)
        field_value = criticality.name if criticality else None
    elif field == 'corrective_action':
        original_value = anomaly.corrective_action
        anomaly.update(corrective_action=field_value)
    elif field == 'project':
        if anomaly.project:
            original_value = anomaly.project.name
        project = Project.get_by_id(field_value)
        anomaly.update(project=project)
        field_value = project.name if project else None
    elif field == 'owner':
        if anomaly.owner:
            original_value = anomaly.owner.get_name()
            if anomaly.owner.padawan:
                for approver in anomaly.approvers:
                    if approver.approver == anomaly.owner.supervisor and approver.capacity == 'Supervisor':
                        anomaly.approvers.remove(approver)
                        approver.delete()
        owner = User.get_by_id(field_value)
        if owner.padawan:
            approver = Approver.create(approver_id=owner.supervisor_id, capacity='Supervisor')
            anomaly.approvers.append(approver)
        anomaly.update(owner=owner)
        field_value = owner.get_name() if owner else None
    elif field == 'thumbnail_id':
        thumbnail_id = None if field_value == 'default' else field_value
        anomaly.update(thumbnail_id=thumbnail_id)
        return render_template('shared/thumbnail_return.html', record=anomaly)

    anomaly.add_change_log_entry(action='Edit', field=field.title().replace('_', ' '),
                                 original_value=original_value, new_value=field_value)

    return jsonify({'success': True}), 200, {'ContentType': 'application/json'}
Exemple #2
0
def update_product():
    id = request.form['pk']
    # UID for field will be ala [fieldname]-[classname]-[id]-editable, field name will be first section always
    field = request.form['name'].split('-')[0]
    field_value = request.form['value']
    # TODO: Check if product exists
    product = Product.get_by_id(id)
    original_value = None

    if field == 'hardware_type':
        if product.hardware_type:
            original_value = product.hardware_type.name
        hardware_type = HardwareType.get_by_id(field_value)
        product.update(hardware_type=hardware_type)
        field_value = hardware_type.name if hardware_type else None
    elif field == 'measured_mass':
        original_value = product.measured_mass
        product.update(measured_mass=float(field_value))
    elif field == 'owner':
        if product.owner:
            original_value = product.owner.get_name()
            if product.owner.padawan:
                for approver in product.approvers:
                    if approver.approver == product.owner.supervisor and approver.capacity == 'Supervisor':
                        product.approvers.remove(approver)
                        approver.delete()
        owner = User.get_by_id(field_value)
        if owner.padawan:
            approver = Approver.create(approver_id=owner.supervisor_id, capacity='Supervisor')
            product.approvers.append(approver)
        product.update(owner=owner)
        field_value = owner.get_name() if owner else None
    elif field == 'project':
        if product.project:
            original_value = product.project.name
        project = Project.get_by_id(field_value)
        product.update(project=project)
        field_value = project.name if project else None
    elif field == 'notes':
        original_value = product.notes
        product.update(notes=field_value)
    elif field == 'summary':
        original_value = product.summary
        product.update(summary=field_value)
    elif field == 'thumbnail_id':
        thumbnail_id = None if field_value == 'default' else field_value
        product.update(thumbnail_id=thumbnail_id)
        return render_template('shared/thumbnail_return.html', record=product)

    product.add_change_log_entry(action='Edit', field=field.title().replace('_', ' '), original_value=original_value,
                                 new_value=field_value)

    return jsonify({'success': True}), 200, {'ContentType': 'application/json'}
Exemple #3
0
def update_vendor_part():
    # TODO: Check that field should actually be allowed to change. As in, don't change design number for instance
    id = request.form['pk']
    # UID for field will be ala [fieldname]-[classname]-[id]-editable, field name will be first section always
    field = request.form['name'].split('-')[0]
    field_value = request.form['value']
    original_value = None
    # TODO: Check if design exists
    vendor_part = VendorPart.get_by_id(id)

    if field == 'name':
        original_value = vendor_part.name
        vendor_part.update(name=field_value)
    elif field == 'summary':
        original_value = vendor_part.summary
        vendor_part.update(summary=field_value)
    elif field == 'project':
        if vendor_part.project:
            original_value = vendor_part.project.name
        project = Project.get_by_id(field_value)
        vendor_part.update(project=project)
        field_value = project.name if project else None
    elif field == 'owner':
        if vendor_part.owner:
            original_value = vendor_part.owner.get_name()
            if vendor_part.owner.padawan:
                for approver in vendor_part.approvers:
                    if approver.approver == vendor_part.owner.supervisor and approver.capacity == 'Supervisor':
                        vendor_part.approvers.remove(approver)
                        approver.delete()
        owner = User.get_by_id(field_value)
        if owner.padawan:
            approver = Approver.create(approver_id=owner.supervisor_id,
                                       capacity='Supervisor')
            vendor_part.approvers.append(approver)
        vendor_part.update(owner=owner)
        field_value = owner.get_name() if owner else None
    elif field == 'vendor':
        if vendor_part.vendor:
            original_value = vendor_part.vendor.name
        vendor = Company.get_by_id(field_value)
        vendor_part.update(vendor=vendor)
        field_value = vendor.name if vendor else None
    elif field == 'notes':
        original_value = vendor_part.notes
        vendor_part.update(notes=field_value)
    elif field == 'material':
        original_material = None
        original_material_spec = None
        if vendor_part.material:
            original_material = vendor_part.material.name
        if vendor_part.material_specification:
            original_material_spec = vendor_part.material_specification.name
        material = Material.get_by_id(field_value)
        vendor_part.update(
            material=material, material_specification=None
        )  # To ensure we don't have a mat_spec linked with old material
        material_name = None
        material_specifications = None
        if material:
            material_name = material.name
            material_specifications = material.specifications
        vendor_part.add_change_log_entry(action='Edit',
                                         field='Material',
                                         original_value=original_material,
                                         new_value=material_name)
        if original_material_spec:
            vendor_part.add_change_log_entry(
                action='Edit',
                field='Material Specification',
                original_value=original_material_spec)
        variables = {
            'vendor_part': vendor_part,
            'material_specifications': material_specifications
        }
        return render_template(
            'vendorpart/ajax_select_material_specification.html', **variables)
    elif field == 'material_specification':
        if vendor_part.material_specification:
            original_value = vendor_part.material_specification.name
        material_specification = MaterialSpecification.get_by_id(field_value)
        vendor_part.update(material_specification=material_specification)
        field_value = material_specification.name if material_specification else None
    elif field == 'thumbnail_id':
        thumbnail_id = None if field_value == 'default' else field_value
        vendor_part.update(thumbnail_id=thumbnail_id)
        return render_template('shared/thumbnail_return.html',
                               record=vendor_part)
    elif field == 'current_best_estimate':
        original_value = vendor_part.current_best_estimate
        original_predicted_best_estimate = vendor_part.predicted_best_estimate
        current_best_estimate = float(field_value)
        predicted_best_estimate = current_best_estimate * (
            1 + (vendor_part.uncertainty / 100))  # PBE = CBE * (1+%Unc)
        vendor_part.update(current_best_estimate=current_best_estimate,
                           predicted_best_estimate=predicted_best_estimate)
        vendor_part.update_parents_mass(
        )  # Updates parts where this is a component
        vendor_part.add_change_log_entry(action='Edit',
                                         field='Current Best Estimate',
                                         original_value=original_value,
                                         new_value=current_best_estimate)
        vendor_part.add_change_log_entry(
            action='Edit',
            field='Predicted Best Estimate',
            original_value=original_predicted_best_estimate,
            new_value=predicted_best_estimate)
        return render_template('vendorpart/mass_fields.html',
                               vendor_part=vendor_part)
    elif field == 'uncertainty':
        original_value = vendor_part.uncertainty
        original_predicted_best_estimate = vendor_part.predicted_best_estimate
        uncertainty = float(field_value)
        predicted_best_estimate = vendor_part.current_best_estimate * (
            1 + (uncertainty / 100))  # PBE = CBE * (1+%Unc)
        vendor_part.update(uncertainty=uncertainty,
                           predicted_best_estimate=predicted_best_estimate)
        vendor_part.update_parents_mass(
        )  # Updates parts where this is a component
        vendor_part.add_change_log_entry(action='Edit',
                                         field='Uncertainty',
                                         original_value=original_value,
                                         new_value=uncertainty)
        vendor_part.add_change_log_entry(
            action='Edit',
            field='Predicted Best Estimate',
            original_value=original_predicted_best_estimate,
            new_value=predicted_best_estimate)
        return render_template('vendorpart/mass_fields.html',
                               vendor_part=vendor_part)

    vendor_part.add_change_log_entry(action='Edit',
                                     field=field.title().replace('_', ' '),
                                     original_value=original_value,
                                     new_value=field_value)

    return jsonify({'success': True}), 200, {'ContentType': 'application/json'}
Exemple #4
0
def update_vendor_product():
    id = request.form['pk']
    # UID for field will be ala [fieldname]-[classname]-[id]-editable, field name will be first section always
    field = request.form['name'].split('-')[0]
    field_value = request.form['value']
    # TODO: Check if product exists
    vendor_product = VendorProduct.get_by_id(id)
    original_value = None
    jsonData = {}
    if field == 'hardware_type':
        if vendor_product.hardware_type:
            original_value = vendor_product.hardware_type.name
        hardware_type = HardwareType.get_by_id(field_value)
        vendor_product.update(hardware_type=hardware_type)
        field_value = hardware_type.name if hardware_type else None
    elif field == 'measured_mass':
        original_value = vendor_product.measured_mass
        vendor_product.update(measured_mass=float(field_value))
        vendor_product.add_change_log_entry(action='Edit', field='Measured Mass', original_value=original_value,
                                            new_value=field_value)
        variables = {'vendor_product': vendor_product}
        return render_template('vendorproduct/mass_field.html', **variables)
    elif field == 'owner':
        if vendor_product.owner:
            original_value = vendor_product.owner.get_name()
            if vendor_product.owner.padawan:
                for approver in vendor_product.approvers:
                    if approver.approver == vendor_product.owner.supervisor and approver.capacity == 'Supervisor':
                        vendor_product.approvers.remove(approver)
                        approver.delete()
        owner = User.get_by_id(field_value)
        if owner.padawan:
            approver = Approver.create(approver_id=owner.supervisor_id, capacity='Supervisor')
            vendor_product.approvers.append(approver)
        vendor_product.update(owner=owner)
        field_value = owner.get_name() if owner else None
    elif field == 'project':
        if vendor_product.project:
            original_value = vendor_product.project.name
        project = Project.get_by_id(field_value)
        vendor_product.update(project=project)
        field_value = project.name if project else None
    elif field == 'notes':
        original_value = vendor_product.notes
        vendor_product.update(notes=field_value)
    elif field == 'summary':
        original_value = vendor_product.summary
        vendor_product.update(summary=field_value)
    elif field == 'thumbnail_id':
        thumbnail_id = None if field_value == 'default' else field_value
        vendor_product.update(thumbnail_id=thumbnail_id)
        return render_template('shared/thumbnail_return.html', record=vendor_product)
    elif field == 'serial_number':
        original_value = vendor_product.serial_number
        try:
            vendor_product.update(serial_number=field_value)
        except:
            return jsonify(jsonData), 500, {'ContentType': 'application/json'}
        jsonData = {'url': vendor_product.get_url()}  # Return URL to reload page with new S/N

    vendor_product.add_change_log_entry(action='Edit', field=field.title().replace('_', ' '),
                                        original_value=original_value, new_value=field_value)

    return jsonify(jsonData), 200, {'ContentType': 'application/json'}