def home(request):
    info = ''
    if request.method == 'POST':
        form = InputForm(request.POST)
        if form.is_valid():
            fcd = form.cleaned_data
            mask=int(fcd['mask'])
            config=dict([('percent_'+str(m),0) for m in xrange(27,31)]+[('unit_'+str(m),0) for m in xrange(27,31)]) #словарь с нулевыми ключами

            for index,num in enumerate(xrange(27,31)):
                net=int(fcd['net_'+str(num)])

                if fcd['prs_or_unit_'+str(num)]=='%':
                    config['percent_'+str(num)]=net
                if fcd['prs_or_unit_'+str(num)]=='unit':
                    config['unit_'+str(num)]=net

            unit_ip_list,info=prs_conv(config,mask)
            if unit_ip_list:#если список не None
                network_matrix=create_matrix(unit_ip_list)
                curr_ip=[int(fcd[bite]) for bite in ['first_bite','second_bite','third_bite','fourth_bite']]
                main_ips=create_c_classes(curr_ip,mask)
                create_table(main_ips,network_matrix) #получаем окончательный файл
                info='Файл успешно сгенерирован'
    else:
        form = InputForm()
    return render_to_response('index.html',{'form': form,'info': info},
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
def prediction():
    form = InputForm()
    if form.validate_on_submit():
        id = form.data('id')
        recipe = form.data('ingredients')
    return render_template('predict.html',
                           title="Cuisine Prediction",
                           form=form)
Exemplo n.º 3
0
def update(taskid):
    form = InputForm()
    task_to_update = Tasks.query.get(taskid)

    if form.validate_on_submit():
        task_to_update.name = form.new_task.data
        db.session.commit()
        return redirect(url_for('home'))
    return render_template('add.html', form=form)
Exemplo n.º 4
0
def add():
    form = InputForm()

    if form.validate_on_submit():
        new_task = Tasks(name=form.new_task.data)
        db.session.add(new_task)
        db.session.commit()
        return redirect(url_for('home'))
    return render_template('add.html', form=form)
Exemplo n.º 5
0
def testing():
    form = InputForm()
    if form.validate_on_submit():
        id = form.data('id')
        recipe = form.data['ingredients']
    return render_template('testing.html', form=form)
Exemplo n.º 6
0
def homepage():

    if not session.new:
        redirect(url_for('chart'))

    form = InputForm()
    entry = LoginForm()

    if request.method == 'POST' and form.is_submitted():
        try:
            name = request.form.get('nome')
            email = request.form.get('email')
            password = request.form.get('pass')
            vpass = request.form.get('confirmPass')
            income = request.form.get('salario')
            savings = request.form.get('poupanca')
            debt = request.form.get('divida')
            dtype = request.form.get('tpDivida')
            interestrate = request.form.get('juros')
            obj = request.form.get('objetivo')
            rent = request.form.get('aluguel')
            transport = request.form.get('transporte')
            food = request.form.get('alimentacao')
            bills = request.form.get('contas')
            shopping = request.form.get('compras')
            extra = request.form.get('outros')

            if password != vpass:
                raise ValueError(
                    "Os campos senha e confirmação de senha não batem.")

            hashed_password = pwcrypt.generate_password_hash(password).decode(
                'utf-8')

            newuser = User(username=name,
                           email=email,
                           password=hashed_password,
                           income=income,
                           savings=savings,
                           debt=debt,
                           debttype=dtype,
                           interestrate=interestrate,
                           objective=obj,
                           rent=rent,
                           transport=transport,
                           food=food,
                           bills=bills,
                           shopping=shopping,
                           extra=extra)

            db.session.add(newuser)
            db.session.commit()
            redirect(url_for('chart'))

        except Exception:
            pass

        finally:
            return render_template("homepage.html", form=form, entry=entry)

    elif request.method == 'POST' and entry.is_submitted():
        try:
            uname = request.entry.get('nome')
            pwcheck = request.entry.get('pass')
            user = User.query.filter_by(email=form.email.data).first()
            dbpass = User.query.filter_by(username=uname).password

            if user and pwcrypt.check_password_hash(dbpass, pwcheck):
                login_user(user)
                redirect(url_for('handle_form'))
            else:
                return render_template("homepage.html", form=form, entry=entry)

        except Exception:
            pass

    return render_template("homepage.html", form=form, entry=entry)