Exemplo n.º 1
0
 def get(self, public_id):
     params = {}
     bom = Bom.query(Bom.public_id == public_id).get()
     if bom:
         parts = Part.query(ancestor=bom.key).order(-Part.create_time).fetch()
         rawparts = []
         for part in parts:
             raw = []
             quantity_units = ''
             if part.quantity_units:
                 quantity_units = ', units='+part.quantity_units
             raw.append(part.name+quantity_units+'   '+part.part_group+'\n')
             for note in part.note_list:
                 raw.append('   * '+note+'\n')
             for designator in part.designator_list:
                 raw.append('   # '+designator+'\n')
             for i in range(len(part.manufacturer_names)):
                 raw.append('   @ '+part.manufacturer_names[i]+
                            '   '+part.manufacturer_partnums[i]+
                            '\n')
             for i in range(len(part.supplier_names)):
                 raw.append('   $ '+part.supplier_names[i]+
                            '   '+part.supplier_ordernums[i])
                 package_count = part.supplier_packagecounts[i]
                 if package_count != 1:
                     if (package_count % 1) == 0:
                         package_count = '%0.0f' % package_count
                     else:
                         package_count = '%0.3f' % package_count
                     raw.append('   '+package_count)
                 raw.append('   '+part.supplier_currencies[i])
                 if part.supplier_countries[i]:
                     raw.append('   '+part.supplier_currencies[i])
                 raw.append(' %0.2f' % part.supplier_prices[i])
                 if part.supplier_urls[i]:
                     raw.append('   '+part.supplier_urls[i])                    
                 raw.append('\n')
             for i in range(len(part.subsystem_names)):
                 quantities = part.subsystem_quantities[i]
                 if (quantities % 1) == 0:
                     quantities = '%0.0f' % quantities
                 else:
                     quantities = '%0.2f' % quantities
                 raw.append('   '+quantities+
                            '   '+part.subsystem_names[i]+
                            '   '+part.subsystem_specificuses[i]+
                            '\n')
             rawparts.append({'id':part.key.id(), 'raw':''.join(raw)[:-1]})
         params = {
             "is_owner" : ndb.Key('User', long(self.user_id or 0)) in bom.owners,
             "public_id": public_id,
             "currency": "USD",
             "bom" : bom,
             "rawparts" : rawparts
         }
         # prime form
         # self.form.process(obj=bom)
         return self.render_template('bom_edit.html', **params)
     else:
         self.abort(404)
Exemplo n.º 2
0
 def get(self, public_id):
     params = {}
     bom = Bom.query(Bom.public_id == public_id).get()
     if bom:
         parts = Part.query(ancestor=bom.key).order(Part.name).fetch()
         raw = []
         for part in parts:
             quantity_units = ''
             if part.quantity_units:
                 quantity_units = ', units='+part.quantity_units
             raw.append(part.name+quantity_units+'   '+part.part_group+'\n')
             for note in part.note_list:
                 raw.append('   * '+note+'\n')
             for designator in part.designator_list:
                 raw.append('   # '+designator+'\n')
             for i in range(len(part.manufacturer_names)):
                 raw.append('   @ '+part.manufacturer_names[i]+
                            '   '+part.manufacturer_partnums[i]+
                            '\n')
             for i in range(len(part.supplier_names)):
                 raw.append('   $ '+part.supplier_names[i]+
                            '   '+part.supplier_ordernums[i])
                 package_count = part.supplier_packagecounts[i]
                 if package_count != 1:
                     if (package_count % 1) == 0:
                         package_count = '%0.0f' % package_count
                     else:
                         package_count = '%0.3f' % package_count
                     raw.append('   '+package_count)
                 raw.append('   '+part.supplier_currencies[i])
                 if part.supplier_countries[i]:
                     raw.append('   '+part.supplier_currencies[i])
                 raw.append(' %0.2f' % part.supplier_prices[i])
                 if part.supplier_urls[i]:
                     raw.append('   '+part.supplier_urls[i])                    
                 raw.append('\n')
             for i in range(len(part.subsystem_names)):
                 quantities = part.subsystem_quantities[i]
                 if (quantities % 1) == 0:
                     quantities = '%0.0f' % quantities
                 else:
                     quantities = '%0.2f' % quantities
                 raw.append('   '+quantities+
                            '   '+part.subsystem_names[i]+
                            '   '+part.subsystem_specificuses[i]+
                            '\n')
             raw.append('\n')
         params['raw'] = ''.join(raw)
         return self.render_template('bom_raw.html', **params)
     else:
         self.abort(404)
Exemplo n.º 3
0
 def get(self, public_id):
     params = {}
     bom = Bom.query(Bom.public_id == public_id).get()
     if bom:
         parts = Part.query(ancestor=bom.key).order(Part.name).fetch()
         raw = []
         for part in parts:
             quantity_units = ''
             if part.quantity_units:
                 quantity_units = ', units=' + part.quantity_units
             raw.append(part.name + quantity_units + '   ' +
                        part.part_group + '\n')
             for note in part.note_list:
                 raw.append('   * ' + note + '\n')
             for designator in part.designator_list:
                 raw.append('   # ' + designator + '\n')
             for i in range(len(part.manufacturer_names)):
                 raw.append('   @ ' + part.manufacturer_names[i] + '   ' +
                            part.manufacturer_partnums[i] + '\n')
             for i in range(len(part.supplier_names)):
                 raw.append('   $ ' + part.supplier_names[i] + '   ' +
                            part.supplier_ordernums[i])
                 package_count = part.supplier_packagecounts[i]
                 if package_count != 1:
                     if (package_count % 1) == 0:
                         package_count = '%0.0f' % package_count
                     else:
                         package_count = '%0.3f' % package_count
                     raw.append('   ' + package_count)
                 raw.append('   ' + part.supplier_currencies[i])
                 if part.supplier_countries[i]:
                     raw.append('   ' + part.supplier_currencies[i])
                 raw.append(' %0.2f' % part.supplier_prices[i])
                 if part.supplier_urls[i]:
                     raw.append('   ' + part.supplier_urls[i])
                 raw.append('\n')
             for i in range(len(part.subsystem_names)):
                 quantities = part.subsystem_quantities[i]
                 if (quantities % 1) == 0:
                     quantities = '%0.0f' % quantities
                 else:
                     quantities = '%0.2f' % quantities
                 raw.append('   ' + quantities + '   ' +
                            part.subsystem_names[i] + '   ' +
                            part.subsystem_specificuses[i] + '\n')
             raw.append('\n')
         params['raw'] = ''.join(raw)
         return self.render_template('bom_raw.html', **params)
     else:
         self.abort(404)
Exemplo n.º 4
0
def parse_and_add(bomfu, bom_id, user_id, part_ids=[]):
    """Parse a bomfu string and add Parts.

    If part_ids are specified only these parts are edited in place
    with any bomfu data. Parsing is limited to len(part_ids).

    Returns: error string on error, otherwise None
    """
    import bomfu_parser
    try:
        if part_ids:
            # limit parsing to how many part_ids we got
            bom_json = bomfu_parser.parse(bomfu, len(part_ids))
        else:
            bom_json = bomfu_parser.parse(bomfu)
    except bomfu_parser.ParseError as ex:
        return str(ex)
    i = 0
    for p in bom_json:
        if part_ids:
            if i >= len(part_ids):
                return "Parse error, got more part data than part_ids."
            # edit part
            part = ndb.Key('Bom', long(bom_id), 'Part', long(part_ids[i])).get()
            i += 1
        else:
            # add part
            part = Part.new(ndb.Key('Bom', long(bom_id)), '')

        if part:
            part.name = p[0]
            part.quantity_units = p[1]
            part.part_group = p[2]
            part.note_list = p[3]
            part.designator_list = p[4]
            part.manufacturer_names = []
            part.manufacturer_partnums = []
            for manu in p[5]:
                part.manufacturer_names.append(manu[0])
                part.manufacturer_partnums.append(manu[1])
            part.supplier_names = []
            part.supplier_ordernums = []
            part.supplier_packagecounts = []
            part.supplier_currencies = []
            part.supplier_countries = []
            part.supplier_prices = []
            part.supplier_urls = []
            for supplier in p[6]:
                part.supplier_names.append(supplier[0])
                part.supplier_ordernums.append(supplier[1])
                part.supplier_packagecounts.append(supplier[2])
                part.supplier_currencies.append(supplier[3])
                part.supplier_countries.append(supplier[4])
                part.supplier_prices.append(supplier[5])
                part.supplier_urls.append(supplier[6])
            part.subsystem_quantities = []
            part.subsystem_names = []
            part.subsystem_specificuses = []
            for subsys in p[7]:
                part.subsystem_quantities.append(subsys[0])
                part.subsystem_names.append(subsys[1])
                part.subsystem_specificuses.append(subsys[2])
            part.put(user_id)
        else:
            return "Failed to instance part."
Exemplo n.º 5
0
def parse_and_add(bomfu, bom_id, user_id, part_ids=[]):
    """Parse a bomfu string and add Parts.

    If part_ids are specified only these parts are edited in place
    with any bomfu data. Parsing is limited to len(part_ids).

    Returns: error string on error, otherwise None
    """
    import bomfu_parser
    try:
        if part_ids:
            # limit parsing to how many part_ids we got
            bom_json = bomfu_parser.parse(bomfu, len(part_ids))
        else:
            bom_json = bomfu_parser.parse(bomfu)
    except bomfu_parser.ParseError as ex:
        return str(ex)
    i = 0
    for p in bom_json:
        if part_ids:
            if i >= len(part_ids):
                return "Parse error, got more part data than part_ids."
            # edit part
            part = ndb.Key('Bom', long(bom_id), 'Part',
                           long(part_ids[i])).get()
            i += 1
        else:
            # add part
            part = Part.new(ndb.Key('Bom', long(bom_id)), '')

        if part:
            part.name = p[0]
            part.quantity_units = p[1]
            part.part_group = p[2]
            part.note_list = p[3]
            part.designator_list = p[4]
            part.manufacturer_names = []
            part.manufacturer_partnums = []
            for manu in p[5]:
                part.manufacturer_names.append(manu[0])
                part.manufacturer_partnums.append(manu[1])
            part.supplier_names = []
            part.supplier_ordernums = []
            part.supplier_packagecounts = []
            part.supplier_currencies = []
            part.supplier_countries = []
            part.supplier_prices = []
            part.supplier_urls = []
            for supplier in p[6]:
                part.supplier_names.append(supplier[0])
                part.supplier_ordernums.append(supplier[1])
                part.supplier_packagecounts.append(supplier[2])
                part.supplier_currencies.append(supplier[3])
                part.supplier_countries.append(supplier[4])
                part.supplier_prices.append(supplier[5])
                part.supplier_urls.append(supplier[6])
            part.subsystem_quantities = []
            part.subsystem_names = []
            part.subsystem_specificuses = []
            for subsys in p[7]:
                part.subsystem_quantities.append(subsys[0])
                part.subsystem_names.append(subsys[1])
                part.subsystem_specificuses.append(subsys[2])
            part.put(user_id)
        else:
            return "Failed to instance part."
Exemplo n.º 6
0
 def get(self, public_id):
     params = {}
     bom = Bom.query(Bom.public_id == public_id).get()
     if bom:
         parts = Part.query(
             ancestor=bom.key).order(-Part.create_time).fetch()
         rawparts = []
         for part in parts:
             raw = []
             quantity_units = ''
             if part.quantity_units:
                 quantity_units = ', units=' + part.quantity_units
             raw.append(part.name + quantity_units + '   ' +
                        part.part_group + '\n')
             for note in part.note_list:
                 raw.append('   * ' + note + '\n')
             for designator in part.designator_list:
                 raw.append('   # ' + designator + '\n')
             for i in range(len(part.manufacturer_names)):
                 raw.append('   @ ' + part.manufacturer_names[i] + '   ' +
                            part.manufacturer_partnums[i] + '\n')
             for i in range(len(part.supplier_names)):
                 raw.append('   $ ' + part.supplier_names[i] + '   ' +
                            part.supplier_ordernums[i])
                 package_count = part.supplier_packagecounts[i]
                 if package_count != 1:
                     if (package_count % 1) == 0:
                         package_count = '%0.0f' % package_count
                     else:
                         package_count = '%0.3f' % package_count
                     raw.append('   ' + package_count)
                 raw.append('   ' + part.supplier_currencies[i])
                 if part.supplier_countries[i]:
                     raw.append('   ' + part.supplier_currencies[i])
                 raw.append(' %0.2f' % part.supplier_prices[i])
                 if part.supplier_urls[i]:
                     raw.append('   ' + part.supplier_urls[i])
                 raw.append('\n')
             for i in range(len(part.subsystem_names)):
                 quantities = part.subsystem_quantities[i]
                 if (quantities % 1) == 0:
                     quantities = '%0.0f' % quantities
                 else:
                     quantities = '%0.2f' % quantities
                 raw.append('   ' + quantities + '   ' +
                            part.subsystem_names[i] + '   ' +
                            part.subsystem_specificuses[i] + '\n')
             rawparts.append({
                 'id': part.key.id(),
                 'raw': ''.join(raw)[:-1]
             })
         params = {
             "is_owner": ndb.Key('User', long(self.user_id or 0))
             in bom.owners,
             "public_id": public_id,
             "currency": "USD",
             "bom": bom,
             "rawparts": rawparts
         }
         # prime form
         # self.form.process(obj=bom)
         return self.render_template('bom_edit.html', **params)
     else:
         self.abort(404)