Ejemplo n.º 1
0
def get_as_run_modal():
    form = CreateAsRunForm(request.form)
    procedure_id = request.form.get('procedure_id')
    procedure = Procedure.get_by_id(procedure_id)
    as_run_instance = str(AsRun.find_next_as_run_number(procedure))
    return render_template('asrun/create_as_run.html',
                           form=form,
                           proc=procedure,
                           as_run_instance=as_run_instance)
Ejemplo n.º 2
0
def create_as_run():
    """Create new As-Run."""
    form = CreateAsRunForm(request.form)
    validated = form.validate_on_submit()

    if validated:
        procedure_id = request.form['procedure_id']
        procedure = Procedure.get_by_id(procedure_id)
        as_run_number = AsRun.find_next_as_run_number(procedure)
        variables = {
            'owner': form.owner.data,
            'procedure': procedure,
            'project': procedure.project,
            'as_run_number': as_run_number
        }
        as_run = AsRun.create(**variables)

        product_ids = [] if request.form['products'] == '' else request.form[
            'products'].split(',')
        for product_id in product_ids:
            product = Product.get_by_id(product_id)
            as_run.products.append(product)

        vendor_product_ids = [] if request.form[
            'vendor_products'] == '' else request.form[
                'vendor_products'].split(',')
        for vendor_product_id in vendor_product_ids:
            vendor_product = VendorProduct.get_by_id(vendor_product_id)
            as_run.vendor_products.append(vendor_product)

        as_run.save()

        jsonData = {'success': True, 'url': as_run.get_url()}
        return jsonify(jsonData), 200, {'ContentType': 'application/json'}
    else:
        procedure_id = request.form['procedure_id']
        procedure = Procedure.get_by_id(procedure_id)
        as_run_instance = str(
            AsRun.find_next_as_run_number(procedure)).zfill(3)
        return make_response(
            render_template('asrun/create_as_run.html',
                            form=form,
                            proc=procedure,
                            as_run_instance=as_run_instance), 500)
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
 def get_all_procedures(self):
     from pid.procedure.models import Procedure
     procedures = []
     for part in self.parts:
         part_procedures = defaultdict(str)
         for procedure in part.procedures:
             if part_procedures[procedure.procedure_number] < procedure.revision:
                 part_procedures[procedure.procedure_number] = procedure.revision
         for key, value in part_procedures.items():
             procedures.append(Procedure.get_by_procedure_number_and_revision(key, value))
     procedures.sort(key=lambda x: x.created_at, reverse=True)  # Sort by newest first
     return procedures
Ejemplo n.º 5
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
Ejemplo n.º 6
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)