예제 #1
0
def new():
    """
    Route for url: server/new/
    """
    if 'username' in session:
        form = NewForm()
        if request.method == 'GET':
            session.pop('project_name', None)
            session.pop('project_type', None)
            return render_template('new.html', form     = form,
                                               username = session['username'])

        if request.method == 'POST':
            if form.validate():
                session['project_name'] = form.project_name.data
                if form.project_type.data == 'create':
                    session['project_type'] = 'Create My Own'
                    session['data_parsed'] = ''
                    return redirect(url_for('edit'))
                if form.project_type.data == 'ubuildit':
                    session['project_type'] = 'UBuildIt'
                    return redirect(url_for('upload'))
            flash('There were problems creating your project.')
            return render_template('new.html', form     = form,
                                               username = session['username'])
    return abort(404)
예제 #2
0
파일: routes.py 프로젝트: fleaz/elendsindex
def new():
    form = NewForm()
    if form.validate_on_submit():
        thing = Thing(description=form.description.data, original_value=float(form.value.data.replace(",", ".")))
        db.session.add(thing)
        db.session.commit()
        return redirect(url_for("new"))
    return render_template("new.html", form=form)
예제 #3
0
def new():
    form = NewForm()
    if form.validate_on_submit():
        grocery = Grocery(name=form.name.data, stock=form.stock.data, best_before=form.best_before_date.data)
        db.session.add(grocery)
        db.session.commit()
        flash('Congrats, the Grocery is added')
        return redirect(url_for('new'))
    return render_template('new.html', form=form)
예제 #4
0
def todolist():
    form = NewForm()
    if form.validate_on_submit():
        todo = Todo(body=form.newtodo.data, author=current_user)
        print(todo)
        db.session.add(todo)
        db.session.commit()
        flash('Added')
        return redirect(url_for('todolist'))
    todoposts = current_user.todoposts().all()
    inprogressposts = current_user.inprogressposts().all()
    doneposts = current_user.doneposts().all()
    return render_template("todolist.html", title='To-Do List', form=form, todoposts=todoposts,
                           inprogressposts=inprogressposts, doneposts= doneposts)
예제 #5
0
def profile():

    newProfileForm = NewForm()

    if request.method == "POST":
        if newProfileForm.validate_on_submit():
            try:
                firstname = newProfileForm.firstname.data
                lastname = newProfileForm.lastname.data
                gender = newProfileForm.gender.data
                email = newProfileForm.email.data
                location = newProfileForm.location.data
                bio = newProfileForm.bio.data
                created_on = str(datetime.datetime.now()).split()[0]
                photo = newProfileForm.photo.data
                photo_name = secure_filename(photo.filename)

                user = User(firstname=firstname,
                            lastname=lastname,
                            gender=gender,
                            email=email,
                            location=location,
                            bio=bio,
                            created_on=created_on,
                            photo=photo_name)

                db.session.add(user)
                db.session.commit()

                photo.save(
                    os.path.join(app.config['UPLOAD_FOLDER'], photo_name))
                flash("Your profile has been added.", "success")
                return redirect(url_for("profiles"))

            except Exception as e:
                db.session.rollback()
                flash("An internal error has occurred", "danger")
                flash(str(e))
                return render_template("new_profile.html",
                                       newProfileForm=newProfileForm)

        errors = form_errors(newProfileForm)
        flash(''.join(error + " " for error in errors), "danger")
    return render_template("new_profile.html", newProfileForm=newProfileForm)
예제 #6
0
def new():
    form = NewForm()
    if form.validate_on_submit():
        path = form.wd_path.data
        target_species = form.selected_species.data[0].split(',')
        form_dict = {
            'path': path,
            'targets': {},
            'same_settings': form.same_setting.data,
            'change_settings': False,
            'modus': 'new'
        }
        for target in list(target_species):
            target = '_'.join(target.strip(' ').split(' '))
            target = target.capitalize()
            form_dict['targets'].update({target: {}})
        update_tmp_db({'new_run': form_dict})
        return redirect(url_for('settings'))
    return render_template('new.html', title='Start Primerdesign', form=form)
예제 #7
0
def admin_new():
    form = NewForm()
    if form.validate_on_submit():
        g_address = form.address.data.replace(" ", "+")
        g_city = form.city.data.replace(" ", "+")
        url = f"https://maps.googleapis.com/maps/api/geocode/json?address={g_address},+{g_city},+{form.state.data}&key={os.environ.get('API')}"
        r = requests.get(url)
        j = json.loads(r.text)
        latitude = j['results'][0]['geometry']['location']['lat']
        longitude = j['results'][0]['geometry']['location']['lng']
        overall_score = form.tortilla_score.data * 2.0 + form.potato_score.data * 2 + form.texture_score.data * 2 + form.flavor_score.data * 2 + form.general_score.data * 2
        overall_score = int(overall_score)
        burrito = Reviews(overview=form.overview.data,
                          user_id=current_user.id,
                          overall_score=overall_score,
                          lat=latitude,
                          lng=longitude,
                          date=form.date.data,
                          restaurant_name=form.restaurant_name.data,
                          address=form.address.data,
                          city=form.city.data,
                          state=form.state.data,
                          zip_code=form.zip_code.data,
                          tortilla_desc=form.tortilla_desc.data,
                          tortilla_score=form.tortilla_score.data,
                          potato_desc=form.potato_desc.data,
                          potato_score=form.potato_score.data,
                          texture_desc=form.texture_desc.data,
                          texture_score=form.texture_score.data,
                          flavor_desc=form.flavor_desc.data,
                          flavor_score=form.flavor_score.data,
                          general_desc=form.general_desc.data,
                          general_score=form.general_score.data,
                          smother=form.smother.data,
                          smother_score=form.smother_score.data,
                          published=form.published.data)
        db.session.add(burrito)
        db.session.commit()
        flash(f'Your post is now live!')
        return redirect(url_for('index'))
    return render_template('new_burrito.html', title='New Burrito', form=form)