Esempio n. 1
0
  def create_manufacturer(payload):
    body = request.get_json()
    name = body.get('name', None)
    website_link = body.get('website_link', None)
    try:
      manufacturer = Manufacturer(name=name, website_link=website_link)
      exists = Manufacturer.query.filter(Manufacturer.name == name).one_or_none()
      if exists == None:
        manufacturer.insert()

        manufacturers = Manufacturer.query.all()
        current_page = paginate(manufacturers, request)

        return jsonify({
          'created_manufacturer': manufacturer.id,
          'manufacturers': current_page,
          'num_manufacturers': len(manufacturers),
          'success': True
        })
      else:
        manufacturers = Manufacturer.query.all()
        current_page = paginate(manufacturers, request)

        return jsonify({
          'created_manufacturer': None,
          'manufacturers': current_page,
          'num_manufacturers': len(manufacturers),
          'success': False  
        })
    except Exception: 
      abort(422)
Esempio n. 2
0
def seed(table):
    if table == 'all':
        db.create_all()
    elif table == 'mfg':
        for mfg in manufacturers:
            entry = Manufacturer(name=mfg)
            db.session.add(entry)
            db.session.commit()
    elif table == 'temp':
        for temp in reagent_templates:
            entry = ReagentTemplate(description=temp['description'],
                                    expiry_duration=temp['expiry_dur'],
                                    expiry_type=temp['expiry_type'],
                                    container_size=temp['container_size'],
                                    container_units=temp['container_units'],
                                    requires_qual=temp['requires_qual'])
            db.session.add(entry)
            db.session.commit()
    elif table == 'lot':
        for lot in lots:
            entry = Lot(template_id=lot['temp_id'],
                        mfg_id=lot['mfg_id'],
                        lot_num=lot['lot_num'],
                        expiry=lot['expiry'])
            db.session.add(entry)
            db.session.commit()
    elif table == 'reagent':
        for reagent in reagents:
            entry = Reagent(template_id=reagent['template_id'],
                            lot_id=reagent['lot_id'],
                            expiry=reagent['expiry'],
                            status=reagent['status'])
            db.session.add(entry)
            db.session.commit()
    return 'Good times!'
Esempio n. 3
0
def create_manufacturers(manufacturer_json):
    for man in manufacturer_json:
        manufacturer_model = Manufacturer(man['name'], man['num_models'],
                                          man['avg_price'], man['max_car'],
                                          man['avg_horsepower'])
        db.session.add(manufacturer_model)
        db.session.commit()
Esempio n. 4
0
    def update_product(self, request):
        '''
        Update a product
        '''
        product = Product.get_by_urlsafe_key(request.productKey)
        if not product:
            message = 'No product with the key "%s" exists.' % request.productKey
            raise endpoints.NotFoundException(message)

        user = User.get_by_urlsafe_key(request.userKey)
        if not user:
            message = 'No user with the key "%s" exists.' % request.userKey
            raise endpoints.NotFoundException(message)

        category = None
        if request.category:
            category = ProductCategory.get_by_urlsafe_key(request.category)

        price = None
        if request.price:
            price = request.price

            currency = CurrencyUnit.get_by_urlsafe_key(price.currencyKey)

            location = None
            if price.location:
                location = PhysicalLocation.load(lat=price.location.lat,
                                                 lon=price.location.lon)

            price = Price.create(user=user,
                                 value=price.value,
                                 currency=currency,
                                 location=location)

        manufacturer = None
        if request.manufacturer:
            manufacturer = Manufacturer.load(name=request.manufacturer,
                                             user=user)

        specs = []
        if request.specs:
            for spec in request.specs:
                specification = Specification.get_by_urlsafe_key(spec.key)
                unit = Unit.get_by_urlsafe_key(spec.unit)
                specs.append([specification, spec.value, unit])

        product.update(user=user,
                       name=request.name,
                       category=category,
                       manufacturer=manufacturer,
                       price=price,
                       specs=specs)

        return message_types.VoidMessage()
Esempio n. 5
0
def newManufacturer():
    """Create a new manufacturer."""
    with session_scope() as session:
        images = session.query(Image).order_by(Image.alt_text).all()
        if request.method == 'GET':
            return render_template('new-manufacturer.html', images=images)
        if request.method == 'POST':
            manufacturer = Manufacturer(
                        name=request.form["manufacturer_name"],
                        country=request.form["country"],
                        image_id=request.form["manufacturer_image"],
                        year_founded=request.form["year_founded"],
                        owner_id=login_session['user_id']
                        )
            session.add(manufacturer)
            session.commit()
            return redirect(url_for('allManufacturers'))
Esempio n. 6
0
from models import Car, Driver, Garage, Manufacturer, Status, Station
import datetime

test_manufacturer = Manufacturer()
test_driver = Driver()
test_car = Car()
test_garage = Garage()
test_status = Status()
test_station = Station()

test_manufacturer = {
    'id': 1,
    'name': "Nissan",
    'start_date': datetime.date(year=1933, month=12, day=26)
}

test_driver = {
    'id': 1,
    'name': "Sanic",
    'birthday': datetime.date(year=2010, month=3, day=31)
}

test_car = {
    'id': 1,
    'on': False,
    'doors': 2,
    'color': 'black',
    'make': test_manufacturer,
    'passengers': [test_driver]
}
Esempio n. 7
0
from models import Wheel, Frame, Bicycle, Manufacturer, BikeShop, Customer

# Raw materials
w1 = Wheel(weight=1050, cost=50, name="Vuelta 37mm")
w2 = Wheel(weight=900, cost=100, name="Vuelta Corsa Lite")
w3 = Wheel(weight=850, cost=150, name="Reynolds Eighty One")

f1 = Frame(material="steel", weight=8000, cost=100)
f2 = Frame(material="aluminum", weight=6000, cost=200)
f3 = Frame(material="carbon", weight=5000, cost=300)

# Manufacturers
m1 = Manufacturer(20, "Trek")
m2 = Manufacturer(15, "Navarro")

m1.add_inventory(w1, f1, "transportation")
m1.add_inventory(w2, f1, "transportation+")
m1.add_inventory(w3, f1, "transportation super")

m2.add_inventory(w1, f2, "comp")
m2.add_inventory(w2, f2, "comp extra")
m2.add_inventory(w3, f3, "elite max")

# Shop
s1 = BikeShop(name="Sam's Bikes", margin=20)
s1.restock(m1.ship(3))
s1.restock(m2.ship(3))

s1.print_stock()

#Customer