Beispiel #1
0
 def advanced_search(cls, params):
     query = cls.query
     columns = cls.__table__.columns.keys()
     for attr in params:
         if params[attr] != "" and attr in columns:
             query = query.filter(getattr(cls, attr) == params[attr])
         elif params[attr] != "":
             if attr == 'eco_number_query':
                 formatted_query = format_match_query(
                     params['eco_number_query_type'],
                     params['eco_number_query'])
                 query = query.filter(cls.key.ilike(formatted_query))
             elif attr == 'text_fields_query':
                 formatted_query = format_match_query(
                     'includes', params['text_fields_query'])
                 query = query.filter(
                     cls.name.ilike(formatted_query)
                     | cls.summary.ilike(formatted_query))
             elif attr == 'created_on_start':
                 query = query.filter(
                     cls.created_at >= params['created_on_start'])
             elif attr == 'created_on_end':
                 query = query.filter(
                     cls.created_at <= params['created_on_end'])
             elif attr == 'in_open_state':
                 query = query.filter(
                     cls.state.in_(cls.workflow.open_states))
             elif attr == 'exclude_obsolete':
                 query = query.filter(
                     cls.state != cls.workflow.obsolete_state)
     return query.all()
Beispiel #2
0
    def advanced_search(cls, params):
        from pid.anomaly.models import Anomaly
        query = cls.query
        columns = cls.__table__.columns.keys()

        for attr in params:
            if params[attr] != "" and attr in columns:
                query = query.filter(getattr(cls, attr) == params[attr])
            elif params[attr] != "":
                if attr == 'part_number_query':
                    formatted_query = format_match_query(params['part_number_query_type'], params['part_number_query'])
                    query = query.filter(cls.part_number.ilike(formatted_query))
                elif attr == 'text_fields_query':
                    formatted_query = format_match_query('includes', params['text_fields_query'])
                    query = query.filter(cls.name.ilike(formatted_query) | cls.notes.ilike(formatted_query) |
                                         cls.summary.ilike(formatted_query))
                elif attr == 'open_anomalies':
                    query = query.filter(cls.anomalies.any(Anomaly.state.in_(Anomaly.workflow.open_states)))
                elif attr == 'created_on_start':
                    query = query.filter(cls.created_at >= params['created_on_start'])
                elif attr == 'created_on_end':
                    query = query.filter(cls.created_at <= params['created_on_end'])
                elif attr == 'in_open_state':
                    query = query.filter(cls.state.in_(cls.workflow.open_states))
                elif attr =='exclude_obsolete':
                    query = query.filter(cls.state != cls.workflow.obsolete_state)
        if 'open_anomalies' not in params:
            query = query.distinct(cls.part_number)
        return query.order_by(cls.part_number.desc()).all()
Beispiel #3
0
 def advanced_search(cls, params):
     query = cls.query
     columns = cls.__table__.columns.keys()
     for attr in params:
         if params[attr] != "" and attr in columns:
             query = query.filter(getattr(cls, attr) == params[attr])
         elif params[attr] != "":
             if attr == 'spec_number_match':
                 formatted_query = Utils.format_match_query(
                     params['spec_number_match_type'],
                     params['spec_number_match'])
                 query = query.filter(
                     cls.specification_number.ilike(formatted_query))
             elif attr == 'text_fields_query':
                 formatted_query = Utils.format_match_query(
                     'includes', params['text_fields_query'])
                 query = query.filter(
                     cls.name.ilike(formatted_query)
                     | cls.scope.ilike(formatted_query)
                     | cls.summary.ilike(formatted_query))
             elif attr == 'created_on_start':
                 query = query.filter(
                     cls.created_at >= params['created_on_start'])
             elif attr == 'created_on_end':
                 query = query.filter(
                     cls.created_at <= params['created_on_end'])
             elif attr == 'in_open_state':
                 query = query.filter(
                     cls.state.in_(cls.workflow.open_states))
             elif attr == 'exclude_obsolete':
                 query = query.filter(
                     cls.state != cls.workflow.obsolete_state)
     return query.distinct(cls.specification_number).order_by(
         cls.specification_number.desc(), cls.revision.desc()).all()
Beispiel #4
0
 def advanced_search(cls, params):
     from pid.product.models import Discrepancy
     query = cls.query
     columns = cls.__table__.columns.keys()
     for attr in params:
         if params[attr] != "" and attr in columns:
             query = query.filter(getattr(cls, attr) == params[attr])
         elif params[attr] != "":
             if attr == 'vprod_part_number_query':
                 formatted_query = format_match_query(params['vprod_part_number_query_type'], params['vprod_part_number_query'])
                 query = query.filter(cls.vendor_part.has(VendorPart.part_number.ilike(formatted_query)))
             elif attr == 'vprod_serial_number_query':
                 formatted_query = format_match_query(params['vprod_serial_number_query_type'], params['vprod_serial_number_query'])
                 query = query.filter(cls.serial_number.ilike(formatted_query))
             elif attr == 'text_fields_query':
                 formatted_query = format_match_query('includes', params['text_fields_query'])
                 query = query.filter(cls.summary.ilike(formatted_query) | cls.notes.ilike(formatted_query))
             elif attr == 'open_discrepancies':
                 query = query.filter(cls.discrepancies.any(Discrepancy.state.in_(['Open'])))
             elif attr == 'created_on_start':
                 query = query.filter(cls.created_at >= params['created_on_start'])
             elif attr == 'created_on_end':
                 query = query.filter(cls.created_at <= params['created_on_end'])
             elif attr == 'in_open_state':
                 query = query.filter(cls.state.in_(cls.workflow.open_states))
             elif attr =='exclude_obsolete':
                 query = query.filter(cls.state != cls.workflow.obsolete_state)
             elif attr == 'vendor_id':
                 query = query.filter(cls.vendor_part.has(VendorPart.vendor_id == params[attr]))
             elif attr == 'material_id':
                 query = query.filter(cls.vendor_part.has(VendorPart.material_id == params[attr]))
     return query.all()
Beispiel #5
0
 def advanced_search(cls, params):
     from pid.part.models import Part
     from pid.design.models import Design
     from pid.vendorpart.models import VendorPart
     query = cls.query
     columns = cls.__table__.columns.keys()
     for attr in params:
         if params[attr] != "" and attr in columns:
             query = query.filter(getattr(cls, attr) == params[attr])
         elif params[attr] != "":
             if attr == 'proc_number_query':
                 formatted_query = Utils.format_match_query(
                     params['proc_number_query_type'],
                     params['proc_number_query'])
                 query = query.filter(
                     cls.procedure_number.ilike(formatted_query))
             elif attr == 'part_number_query':
                 formatted_query = Utils.format_match_query(
                     params['part_number_query_type'],
                     params['part_number_query'])
                 query = query.filter(
                     cls.parts.any(
                         Part.design.has(
                             Design.design_number.ilike(formatted_query)))
                     | cls.vendor_parts.any(
                         VendorPart.part_number.ilike(formatted_query)))
             elif attr == 'text_fields_query':
                 formatted_query = Utils.format_match_query(
                     'includes', params['text_fields_query'])
                 query = query.filter(
                     cls.name.ilike(formatted_query)
                     | cls.summary.ilike(formatted_query))
             elif attr == 'created_on_start':
                 query = query.filter(
                     cls.created_at >= params['created_on_start'])
             elif attr == 'created_on_end':
                 query = query.filter(
                     cls.created_at <= params['created_on_end'])
             elif attr == 'in_open_state':
                 query = query.filter(
                     cls.state.in_(cls.workflow.open_states))
             elif attr == 'exclude_obsolete':
                 query = query.filter(
                     cls.state != cls.workflow.obsolete_state)
     return query.distinct(cls.procedure_number).order_by(
         cls.procedure_number.desc(), cls.revision.desc()).all()