示例#1
0
def edit(id):
    """Edit a place."""
    place = Place.query.get(id)
    form = PlaceForm()
    if form.validate_on_submit():
        form.populate_obj(place)
        db.session.commit()
    return redirect(url_for('.detail', id=id))
示例#2
0
def detail(id):
    """View details about a place."""
    place = Place.query.get(id)
    form = PlaceForm(obj=place)
    if not place.lat and place.adr_street:
        geocode_place(id)
    api_key = app.config['API_KEY_MAPS']
    return render_template('place_info.html',
                           place=place,
                           api_key=api_key,
                           form=form)
示例#3
0
def new():
    """Add a new place from a POST request."""
    form = PlaceForm()
    if form.validate_on_submit():
        if Place.query.filter(
                func.lower(Place.name) == func.lower(
                    form.name.data)).count() == 0:
            new_place = Place()
            form.populate_obj(new_place)
            new_place.id = None
            db.session.add(new_place)
            db.session.commit()
            return redirect(url_for('.list'))
        flash('a place with this name already exists')
    return redirect(url_for('.list'))
示例#4
0
def Place_add():
    form = PlaceForm()
    if request.method == 'POST':
        name = form.name.data
        coordinate = form.coordinate.data
        placeC_id = form.placeC_id.data
        if name and coordinate and placeC_id:
            try:
                new_place = Place(name=name,
                                  coordinate=coordinate,
                                  placeC_id=placeC_id)
                db.session.add(new_place)
                db.session.commit()
                return '上传成功'
            except Exception as e:
                print(e)
                flash('添加地点失败')
                db.session.rollback()
                return '添加失败'
        else:
            return '参数出错'

    return render_template('upload.html', form=form)
示例#5
0
 def setUp(self):
     self.form = PlaceForm({
         'state': 'GA',
         'state_req': 'NC',
         'name': 'impossible'
     })
示例#6
0
 def test_required(self):
     """Test that required USStateFields throw appropriate errors."""
     form = PlaceForm({'state': 'GA', 'name': 'Place in GA'})
     self.failIf(form.is_valid())
     self.assertEqual(form.errors['state_req'],
                      [u'This field is required.'])
示例#7
0
def list():
    """List all available places."""
    form = PlaceForm()
    return render_template('place_list.html',
                           places=Place.query.all(),
                           form=form)