예제 #1
0
파일: app.py 프로젝트: ramanxg/weather_app
def index():
    data = getWeather()
    form = CityForm()
    if form.validate_on_submit():
        data = getWeatherCity(form.city_name.data)
        return render_template('index.html', data=data, form=form)
    return render_template('index.html', data=data, form=form)
예제 #2
0
def welcome():
    form = CityForm()
    if form.validate_on_submit():
        obj = ResultMaker()
        result = obj.call(form.city.data)
        if result == "not_found":
            return redirect(url_for('wrong_name'))
        clothes = obj.clothes()
        if form.degrees.data == True:
            result['temperature'] -= 273
        return redirect(url_for('.information', clothes=clothes, city=result))
    return render_template("welcome.html", form=form)
예제 #3
0
def edit_city(id):
    '''
    Edit City
    '''
    city = City.query.filter_by(id=id).first()
    form = CityForm(obj=city)
    if form.validate_on_submit():
        try:
            form.populate_obj(city)
            db.session.add(city)
            db.session.commit()
            flash('Saved successfully', 'success')
        except:
            db.session.rollback()
            flash('Error updating city.', 'danger')
    return render_template('web/edit_city.html', form=form)
예제 #4
0
def create_city():
    '''
    Create city
    '''
    form = CityForm()
    if form.validate_on_submit():
        city = City()
        form.populate_obj(city)
        db.session.add(city)
        try:
            db.session.commit()
            flash('City created correctly', 'success')
            return redirect(url_for('city.cities', **request.args))
        except Exception as e:
            db.session.rollback()
            flash('Error creating city', 'danger')

    return render_template('web/create_city.html', form=form)