Пример #1
0
def index():
    customer = Customer()
    customer.name = request.form['name']
    db.session.add(customer)
    db.session.commit()
    customers = Customer.query.all()
    return render_template('customers.html', customer=customers)
Пример #2
0
def seed_db():
    """Sembrado en la base de datos"""
    db.session.add(Customer(names='nickmostacero'))
    db.session.add(Customer(names='ldramostacero'))
    db.session.add(Order(customer_id='1', date='01/09/09'))
    db.session.add(Order(customer_id='2', date='01/09/09'))
    db.session.add(Product(name='agua'))
    db.session.add(Product(name='gaseosa'))
    db.session.add(Item(order_id='1', product_id='1', quantity='20'))
    db.session.add(Item(order_id='2', product_id='2', quantity='21'))
    db.session.commit()
Пример #3
0
def seed_db():
    """Sembrado en la base de datos"""
    db.session.add(Customer(names='josvillegas'))
    db.session.add(Customer(names='toshivillegas'))
    db.session.add(Order(customer_id='1', date='01/09/09'))
    db.session.add(Order(customer_id='2', date='01/09/09'))
    db.session.add(Product(name='gaseosa'))
    db.session.add(Product(name='helado'))
    db.session.add(Item(order_id='1',product_id='1', quantity='20'))
    db.session.add(Item(order_id='2',product_id='2', quantity='21'))
    db.session.commit()
Пример #4
0
def seed_db():
    """Sembrado en la base de datos: Customers"""
    db.session.add(Customer(name='brandux'))
    db.session.add(Customer(name='toshi'))
    """Sembrando en base datos: Producto"""
    db.session.add(Product(name='Pan Integral'))
    db.session.add(Product(name='Palitos Union'))
    """Sembrando datos en base de datos: orders"""
    db.session.add(Order(customer_id=1, date=datetime.datetime.now()))
    """Sembrando datos en item"""
    db.session.add(Item(order_id=1, product_id=1, quantity=20))

    db.session.commit()
Пример #5
0
def index():
    if request.method == 'POST':
        name = request.form['name']
        db.session.add(Customer(name=name))
        db.session.commit()
    customer = Customer.query.all()
    return render_template('index.html', customer=customer)
 def test_add_customer(self):
     customer = Customer(name='brandux')
     # user = add_user('justatest', '*****@*****.**')
     db.session.add(customer)
     db.session.commit()
     self.assertTrue(customer.id)
     self.assertEqual(customer.name, 'brandux')
 def test_add_customer_duplicate_name(self):
     customer = Customer(name='brandux')
     # add_user('justatest', '*****@*****.**')
     db.session.add(customer)
     db.session.commit()
     duplicate_customer = customer(name='brandux')
     db.session.add(duplicate_customer)
     self.assertRaises(IntegrityError, db.session.commit)
Пример #8
0
def create_customer(args):
    location_id = args.get('location_id', None)
    location = None
    if location_id:
        location = Location.query.get(location_id)
        if not location:
            return make_response(status_code=400,
                                 status='failure',
                                 message='No location found with that id')

    customer = Customer(**args)
    if location:
        location.customers.append(customer)
    db.session.add(customer)
    db.session.commit()
    return make_response(status_code=200,
                         status='success',
                         message=None,
                         data=customer_schema.dump(customer).data)
Пример #9
0
def add_customer():
    post_data = request.get_json()
    response_object = {'status': 'fallo', 'message': 'carga Invalida'}
    if not post_data:
        return jsonify(response_object), 400
    name = post_data.get('name')
    try:
        customer = Customer.query.filter_by(name=name).first()
        if not customer:
            db.session.add(Customer(name=name))
            db.session.commit()
            response_object['status'] = 'success'
            response_object['message'] = f'{name} was added!'
            return jsonify(response_object), 201
        else:
            response_object['messaje'] = 'Lo siento, el nombre ya existe'
            return jsonify(response_object), 400
    except exc.IntegrityError:
        db.session.rollback()
        return jsonify(response_object), 400
Пример #10
0
def add_customer():
    post_data = request.get_json()
    response_object = {'status': 'failed', 'message': 'Carga invalida.'}
    if not post_data:
        return jsonify(response_object), 400
    name = post_data.get('name')
    try:
        customer = Customer.query.filter_by(name=name).first()
        if not customer:
            db.session.add(Customer(name=name))
            db.session.commit()
            response_object['status'] = 'success'
            response_object['message'] = f'{name} ha sido agregado !'
            return jsonify(response_object), 201
        else:
            response_object['message'] = 'Lo siento. El usuario ya existe'
            return jsonify(response_object), 400
    except exc.IntegrityError:
        db.session.rollback()
        return jsonify(response_object), 400
Пример #11
0
def add_customer(name):
    customer = Customer(names=name)
    db.session.add(customer)
    db.session.commit()
    return customer
Пример #12
0
def seed_db():
    """Sembrado en la base de datos"""
    db.session.add(Customer(name='lilianaclaribel'))
    db.session.add(Customer(name='merlyyeslin'))
    db.session.commit()
Пример #13
0
def add_test_data():
    admin = User.query.get(1)
    tag1 = Tag(**{'title': 'Programming'})
    tag2 = Tag(**{'title': 'Programming'})
    tag3 = Tag(**{'title': 'Social studies'})
    tag4 = Tag(**{'title': 'Creative'})
    tag5 = Tag(**{'title': 'Engineering'})
    admin.tags.append(tag5)

    group = Group(
        **{
            'name': 'Copenhagen Office',
            'address': 'Købmagergade 67',
            'zipcode': '1150',
            'city': 'Copenhagen',
            'country': 'Denmark'
        })

    role = Role(**{'name': 'Application consultant'})

    user1 = User(
        **{
            'email': '*****@*****.**',
            'password': '******',
            'name': 'Jonatan Tegen',
            'admin': False,
            'verified': False
        })
    education1 = Education(
        **{
            'title': 'Engineering Physics',
            'school': 'LTH',
            'extent': 'Master\'s degree',
            'description': 'Learned cool stuff!'
        })
    admin.educations.append(education1)
    education2 = Education(
        **{
            'title': 'Psychology',
            'school': 'Lund University',
            'type': 'COURSE',
            'extent': 'One semester',
            'description': ''
        })
    education3 = Education(
        **{
            'title': 'Math',
            'school': 'LTH',
            'type': 'COURSE',
            'extent': '30HP',
            'description': 'Math man..!'
        })
    project = Project(
        **{
            'title': 'Some cool project',
            'description': 'DO STUFF',
            'startdate': '2018-01-01T00:00+01:00',
            'enddate': '2018-08-01T00:00+01:00',
            'hours': 100
        })
    location1 = Location(
        **{
            'description': 'HQ',
            'latitude': 55.6831585,
            'longitude': 13.1756237,
            'street': 'Sankt Lars väg 46',
            'zipcode': '222 70',
            'city': 'Lund',
            'country': 'Sweden'
        })
    customer = Customer(
        **{
            'name': 'Lime Technologies AB',
            'customer_number': '123456',
            'registration_number': '',
            'location_id': 1
        })
    contact_person = ContactPerson(**{
        'firstname': 'Jonatan',
        'lastname': 'Tegen',
        'title': 'Consultant manager'
    })
    project_response = ProjectResponse(**{'type': 'INTERESTED'})
    location1.customers.append(customer)
    location1.projects.append(project)
    customer.projects.append(project)
    customer.contactpersons.append(contact_person)
    education1.tags.append(tag1)
    education2.tags.append(tag3)
    user1.tags.append(tag2)
    user1.tags.append(tag4)
    user1.educations.append(education2)
    user1.educations.append(education3)
    user1.projectresponses.append(project_response)
    project.projectresponses.append(project_response)
    role.users.append(user1)
    group.users.append(user1)
    db.session.add(tag5)
    db.session.add(education1)
    db.session.add(user1)
    db.session.add(location1)
    db.session.commit()
Пример #14
0
 def test_to_json(self):
     customer = Customer(name='brandux')
     # add_user('justatest', '*****@*****.**')
     db.session.add(customer)
     db.session.commit()
     self.assertTrue(isinstance(customer.to_json(), dict))
Пример #15
0
def seed_db():
    """Sembrado en la base de datos"""
    db.session.add(Customer(name='kevinmogollon'))
    db.session.add(Customer(name='abelhuanca'))
    db.session.commit()
Пример #16
0
def add_customer(name):
    user = Customer(name=name)
    db.session.add(user)
    db.session.commit()
    return user
Пример #17
0
def seed_db():
    """Sembrado de la base de datos."""
    db.session.add(Customer(name='vanessa'))
    db.session.add(Customer(name='fiorella'))
    db.session.commit()