Beispiel #1
0
def add_author():
    form = AuthorForm(request.form)
    if request.method == 'POST' and form.validate():
        author = Author(form.name.data)
        session.add(author)
        session.commit()
        return redirect(url_for('index'))
    return render_template('author_form.html', form=form, action="/author/add")
Beispiel #2
0
def op_create():
    session.add(Users(name="alex0", extra='sb'))
    
    session.add_all([
        Users(name="alex1", extra='sb'),
        Users(name="alex2", extra='sb'),
    ])
    session.commit()    # 这里需要commit,不然不提交数据
Beispiel #3
0
def add_book():
    form = BookForm(request.form)
    if request.method == 'POST' and form.validate():
        book = Book(form.title.data, form.authors.data)
        session.add(book)
        session.commit()
        return redirect(url_for('index'))
    return render_template('book_form.html', form=form, action="/book/add")
Beispiel #4
0
def add_book():
    form = BookForm(request.form)
    if request.method == 'POST' and form.validate():
        book = Book(form.title.data, form.author.data)
        session.add(book)
        session.commit()
        return redirect(url_for('index'))
    return render_template('book_form.html',
                           form=form,
                           action="/book/add",
                           user_name=current_user.name,
                           user_picture=current_user.picture,
                           if_administrator=verify_administrator())
Beispiel #5
0
def add_author():
    form = AuthorForm(request.form)
    if request.method == 'POST' and form.validate():
        author = Author(form.name.data)
        session.add(author)
        session.commit()
        return redirect(url_for('index'))
    return render_template('author_form.html',
                           form=form,
                           action="/author/add",
                           user_name=current_user.name,
                           user_picture=current_user.picture,
                           if_administrator=verify_administrator())
Beispiel #6
0
def add_customers():
    form = CustomerForm(request.form)
    error = None
    if form.validate():
        customer = Customer(form.first_name.data, form.last_name.data,
                            form.email.data, form.age.data)
        flash('You sucessfully added a new customer!')
        session.add(customer)
        session.commit()
        return redirect(url_for('customers'))
    else:
        error = "Fields are not filled correctly!"
        return render_template('customer_form.html',
                               form=form,
                               method="POST",
                               action="/add",
                               error=error,
                               submit_text="Save")
Beispiel #7
0
def add_numbers():
    form = TargetForm(request.form)
    error = None
    result = None
    if request.method == 'POST':
        if form.validate():
            target = Target(form.tgt_name.data, form.value_x.data,
                            form.value_y.data, form.value_z.data)
            flash('You sucessfully added a new target!')
            session.add(target)
            session.commit()
            return redirect(url_for('index'))
        else:
            error = "Fields are not filled correctly!"

    return render_template('target_form.html',
                           form=form,
                           method="POST",
                           action="/add",
                           error=error,
                           submit_text="Save",
                           title="ADD NEW")
	if msg is None:
		# No packets on queue
		sleep(10)
	else:
		# Get packet id from the queue
		packet_id = None
		try:
			packet_id = int(msg.get_body())
			print "Packet id:", str(packet_id)
		except:
			# If the message doesn't contain an integer (i.e someone put something on the queue that doesnt belong there)
			print "Erroneous msg"
			delMsg(msg)
			continue
		# Get that packet from the database
		try:
			packet = session.query(Packet).filter(Packet.id == packet_id).one()
		except:
			# Packet has been removed from db since it was added to the queue
			delMsg(msg)
			continue
		# Check if cartype has been added since the packet was enqueued (i.e packet.cartype != None)
		if packet.cartype is None:
			# Calculate cartype
			ctype = packet.getCarType()
			# if ctype is None that means the data was corrupt and the packet was deleted from db by the call to getCarType()
			if ctype is not None:
				session.add(packet)
				session.commit()
		delMsg(msg)
Beispiel #9
0
def create(**kwargs):
  kwargs['depart'] = create_date(kwargs['depart'])
  kwargs['arrive'] = create_date(kwargs['arrive'])
  r = Route(**kwargs)
  session.add(r)