Esempio n. 1
0
def update_design():
    eco_id = request.values['eco_id']
    old_design_id = request.values['old_design_id']
    new_design_id = request.values['new_design_id']
    eco = ECO.get_by_id(eco_id)
    old_design = Design.get_by_id(old_design_id)
    new_design = Design.get_by_id(new_design_id)
    eco.designs.remove(old_design)
    eco.designs.append(new_design)
    eco.add_change_log_entry(action='Edit',
                             field='Design',
                             original_value=old_design.get_descriptive_url(),
                             new_value=new_design.get_descriptive_url())
    eco.save()
    variables = {'eco': eco, 'design': new_design}
    return render_template('eco/eco_design_row.html', **variables)
Esempio n. 2
0
def get_eco_modal():
    form = CreateECOForm(request.form)
    variables = {'form': form}
    design_id = request.form.get('design_id', None)
    if design_id:
        variables['designs'] = [Design.get_by_id(design_id)]
    return render_template('eco/create_eco.html', **variables)
Esempio n. 3
0
def create_eco():
    """Create new ECO."""
    form = CreateECOForm(request.form)
    validated = form.validate_on_submit()

    design_ids = form.designs.data.split(',')
    designs = []
    for design_id in design_ids:
        design = Design.get_by_id(design_id)
        if design != None:
            designs.append(design)

    if validated:
        variables = {
            'name': form.name.data,
            'owner': form.owner.data,
            'project': designs[0].project
        }
        eco = ECO.create(**variables)
        for design in designs:
            eco.designs.append(design)
        eco.save()
        jsonData = {'success': True, 'ecoId': eco.id, 'url': eco.get_url()}
        return jsonify(jsonData), 200, {'ContentType': 'application/json'}
    else:
        return make_response(
            render_template('eco/create_eco.html', form=form, designs=designs),
            500)
Esempio n. 4
0
def create_part():
    type = request.form.get('part_type')
    form = CreatePartForm(request.form)
    validated = form.validate_on_submit()

    design_id = request.form['design_id']
    design = Design.get_by_id(design_id)

    if validated:
        variables = {
            'design': design,
            'part_identifier': form.part_identifier.data,
            'owner': design.owner,
            'name':
            form.name.data if not design.name == form.name.data else None
        }
        if type == 'inseparable':
            variables['inseparable_component'] = True
        part = Part.create(**variables)
        materials = Material.query.all()
        variables = {'part': part, 'materials': materials}
        return render_template('part/view_part.html', **variables)
    else:
        if type == 'inseparable':
            next_part_number = design.find_next_inseparable_part_number()
        else:
            next_part_number = design.find_next_part_number()
        variables = {
            'design': design,
            'next_part_number': next_part_number,
            'form': form,
            'type': type
        }
        return make_response(
            render_template('part/create_part.html', **variables), 500)
Esempio n. 5
0
def update_design():
    anomaly_id = request.values['anomaly_id']
    old_design_id = request.values['old_design_id']
    new_design_id = request.values['new_design_id']
    anomaly = Anomaly.get_by_id(anomaly_id)
    old_design = Design.get_by_id(old_design_id)
    new_design = Design.get_by_id(new_design_id)
    anomaly.designs.remove(old_design)
    anomaly.designs.append(new_design)
    anomaly.add_change_log_entry(action='Edit', field='Design', original_value=old_design.get_descriptive_url(),
                                 new_value=new_design.get_descriptive_url())
    anomaly.save()
    variables = {
        'anomaly': anomaly,
        'design': new_design
    }
    return render_template('anomaly/anomaly_design_row.html', **variables)
Esempio n. 6
0
def remove_design():
    eco_id = request.values['eco_id']
    eco = ECO.get_by_id(eco_id)
    design_id = request.values['design_id']
    design = Design.get_by_id(design_id)
    eco.designs.remove(design)
    eco.add_change_log_entry(action='Remove',
                             field='Design',
                             original_value=design.get_descriptive_url())
    eco.save()
    return jsonify({'success': True}), 200, {'ContentType': 'application/json'}
Esempio n. 7
0
def add_design():
    eco_id = request.values['eco_id']
    design_id = request.values['design_id']
    eco = ECO.get_by_id(eco_id)
    design = Design.get_by_id(design_id)
    eco.designs.append(design)
    eco.add_change_log_entry(action='Add',
                             field='Design',
                             new_value=design.get_descriptive_url())
    eco.save()
    variables = {'eco': eco, 'design': design}
    return render_template('eco/eco_design_row.html', **variables)
Esempio n. 8
0
def get_anomaly_modal():
    form = CreateAnomalyForm(request.form)
    variables = {
        'form': form,
        'designs': [],
        'vendor_parts': [],
        'as_runs': []
    }
    record_id = request.form.get('record_id', None)
    record_class = request.form.get('record_class', None)
    if record_id:
        if record_class == Design.get_class_name():
            variables['designs'] = [Design.get_by_id(record_id)]
            form.affected.data = 'design'
        elif record_class == VendorPart.get_class_name():
            variables['vendor_parts'] = [VendorPart.get_by_id(record_id)]
            form.affected.data = 'design'
        elif record_class == AsRun.get_class_name():
            variables['as_runs'] = [AsRun.get_by_id(record_id)]
            form.affected.data = 'asrun'
    return render_template('anomaly/create_anomaly.html', **variables)
Esempio n. 9
0
 def get_url_to(self):
     from pid.design.models import Design
     from pid.procedure.models import Procedure
     from pid.specification.models import Specification
     reference_object = self.get_reference_object_to()
     if reference_object.get_class_name() in [
             Design.get_class_name(),
             Procedure.get_class_name(),
             Specification.get_class_name()
     ]:
         return reference_object.get_latest_revision_url()
     return reference_object.get_url()
Esempio n. 10
0
def remove_design():
    anomaly_id = request.values['anomaly_id']
    anomaly = Anomaly.get_by_id(anomaly_id)
    design_id = request.values['design_id']
    design_class = request.values['design_class']
    record = None
    if design_class == 'design':
        record = Design.get_by_id(design_id)
        anomaly.designs.remove(record)
    elif design_class == 'vendorpart':
        record = VendorPart.get_by_id(design_id)
        anomaly.vendor_parts.remove(record)
    anomaly.add_change_log_entry(action='Remove', field='Design/Part', original_value=record.get_descriptive_url())
    anomaly.save()
    return jsonify({'success': True}), 200, {'ContentType': 'application/json'}
Esempio n. 11
0
def get_create_part_modal():
    design_id = request.form.get('design_id')
    part_type = request.form.get('part_type')
    form = CreatePartForm(request.form)
    design = Design.get_by_id(design_id)
    next_part_number = design.find_next_inseparable_part_number(
    ) if part_type == 'inseparable' else design.find_next_part_number()

    variables = {
        'design': design,
        'next_part_number': next_part_number,
        'form': form,
        'type': part_type
    }
    return render_template('part/create_part.html', **variables)
Esempio n. 12
0
def get_record_by_id_and_class(record_id, record_class):
    # TODO: Try to find a better way that doesn't involve so much dynamic loading
    record = None
    record_class = record_class.lower()  # Just in case
    if record_class == 'anomaly':
        from pid.anomaly.models import Anomaly
        record = Anomaly.get_by_id(record_id)
    elif record_class == 'asrun':
        from pid.asrun.models import AsRun
        record = AsRun.get_by_id(record_id)
    elif record_class == 'build':
        from pid.product.models import Build
        record = Build.get_by_id(record_id)
    elif record_class == 'design':
        from pid.design.models import Design
        record = Design.get_by_id(record_id)
    elif record_class == 'eco':
        from pid.eco.models import ECO
        record = ECO.get_by_id(record_id)
    elif record_class == 'part':
        from pid.part.models import Part
        record = Part.get_by_id(record_id)
    elif record_class == 'procedure':
        from pid.procedure.models import Procedure
        record = Procedure.get_by_id(record_id)
    elif record_class == 'product':
        from pid.product.models import Product
        record = Product.get_by_id(record_id)
    elif record_class == 'specification':
        from pid.specification.models import Specification
        record = Specification.get_by_id(record_id)
    elif record_class == 'task':
        from pid.task.models import Task
        record = Task.get_by_id(record_id)
    elif record_class == 'vendorbuild':
        from pid.vendorproduct.models import VendorBuild
        record = VendorBuild.get_by_id(record_id)
    elif record_class == 'vendorpart':
        from pid.vendorpart.models import VendorPart
        record = VendorPart.get_by_id(record_id)
    elif record_class == 'vendorproduct':
        from pid.vendorproduct.models import VendorProduct
        record = VendorProduct.get_by_id(record_id)
    return record
Esempio n. 13
0
def add_design():
    anomaly_id = request.values['anomaly_id']
    design_id = request.values['design_id']
    vendor_part_id = request.values['vendor_part_id']
    anomaly = Anomaly.get_by_id(anomaly_id)
    record = None
    if design_id:
        record = Design.get_by_id(design_id)
        anomaly.designs.append(record)
    elif vendor_part_id:
        record = VendorPart.get_by_id(vendor_part_id)
        anomaly.vendor_parts.append(record)
    anomaly.add_change_log_entry(action='Add', field='Design/Part', new_value=record.get_descriptive_url())
    anomaly.save()
    variables = {
        'anomaly': anomaly,
        'design': record
    }
    return render_template('anomaly/anomaly_design_row.html', **variables)
Esempio n. 14
0
def dashboard():
    user = current_user
    # TODO: Add prefix option to forms so form field ids are unique

    anomalies_for_user = Anomaly.find_all_anomalies_for_user(user)
    as_runs_for_user = AsRun.find_all_as_runs_for_user(user)
    designs_for_user = Design.find_all_designs_for_user(user)
    ecos_for_user = ECO.find_all_ecos_for_user(user)
    products_for_user = Product.find_all_products_for_user(user)
    vendor_products_for_user = VendorProduct.find_all_vendor_products_for_user(
        user)
    vendor_parts_for_user = VendorPart.find_all_vendor_parts_for_user(user)
    procedures_for_user = Procedure.find_all_distinct_procedures_for_user(user)
    specifications = Specification.find_all_distinct_specifications()
    records_awaiting_approval = []
    for record_list in [
            anomalies_for_user, as_runs_for_user, designs_for_user,
            ecos_for_user, procedures_for_user, products_for_user,
            specifications, vendor_parts_for_user, vendor_products_for_user
    ]:
        for record in record_list:
            if record.state == record.workflow.get_approval_state():
                records_awaiting_approval.append(record)
    variables = {
        'anomalies_for_user': anomalies_for_user,
        'designs_for_user': designs_for_user,
        'ecos_for_user': ecos_for_user,
        'products_for_user': products_for_user,
        'vendor_products_for_user': vendor_products_for_user,
        'vendor_parts_for_user': vendor_parts_for_user,
        'procedures_for_user': procedures_for_user,
        'specifications': specifications,
        'users': User.query.all(),
        'bookmarks': process_bookmarks(user),
        'saved_searches': user.saved_searches,
        'settings': Settings.get_settings(),
        'approvals': Approver.get_open_approvals_for_user(user),
        'records_awaiting_approval': records_awaiting_approval
    }
    return render_template('backend/dashboard.html', **variables)
Esempio n. 15
0
def create_anomaly():
    """Create new anomaly."""
    form = CreateAnomalyForm(request.form)
    validated = form.validate_on_submit()
    if validated:
        variables = {
            'name': form.name.data,
            'criticality': form.criticality.data,
            'owner': form.owner.data,
            'anomaly_type': form.affected.data
        }
        anomaly = Anomaly.create(**variables)
        if form.affected.data == 'design':
            for design_id in form.designs.data.split(','):
                design = Design.get_by_id(design_id)
                if design != None:
                    anomaly.designs.append(design)
                    design.anomalies.append(anomaly)
                    design.save()
            for vendor_part_id in form.vendor_parts.data.split(','):
                vendor_part = VendorPart.get_by_id(vendor_part_id)
                if vendor_part != None:
                    anomaly.vendor_parts.append(vendor_part)
                    vendor_part.anomalies.append(anomaly)
                    vendor_part.save()
            anomaly.save()
        elif form.affected.data == 'asrun':
            for as_run_id in form.as_runs.data.split(','):
                as_run = AsRun.get_by_id(as_run_id)
                if as_run != None:
                    anomaly.as_runs.append(as_run)
                    as_run.anomalies.append(anomaly)
                    as_run.save()
            anomaly.save()
        jsonData = {
            'success': True,
            'url': anomaly.get_url()
        }
        return jsonify(jsonData), 200, {'ContentType': 'application/json'}
    else:
        designs = []
        vendor_parts = []
        as_runs = []
        print(form.designs.data)
        for design_id in form.designs.data.split(','):
            design = Design.get_by_id(design_id)
            if design != None:
                designs.append(design)
        for vendor_part_id in form.vendor_parts.data.split(','):
            vendor_part = VendorPart.get_by_id(vendor_part_id)
            if vendor_part != None:
                vendor_parts.append(vendor_part)
        for as_run_id in form.as_runs.data.split(','):
            as_run = AsRun.get_by_id(as_run_id)
            if as_run != None:
                as_runs.append(as_run)
        variables = {
            'form': form,
            'designs': designs,
            'vendor_parts': vendor_parts,
            'as_runs': as_runs
        }
        return make_response(render_template('anomaly/create_anomaly.html', **variables), 500)