Ejemplo n.º 1
0
def home_view(request, *args, **kwargs):
    today = datetime.datetime.now().date()

    if request.method == 'POST':
        form = MyForm(request.POST, request.FILES)
        if form.is_valid():
            action = request.POST['action']
            title = str(request.FILES['field'])
            content = request.FILES['field'].read()
            f = open(str(settings.MEDIA_ROOT) + title, "wb")
            f.write(content)
            f.close()
            loadInputAndProcess('media/' + title, action == 'watch')
            if action == 'watch':
                return render(request, "myaction.html", {
                    'value': "output.mp4",
                    'annotate': 'false'
                })
            elif action == 'annotate':
                return render(request, "myaction.html", {
                    'value': title,
                    'annotate': 'true'
                })
            else:
                return render(request, "showlink.html",
                              {'value': "output.avi"})

    form = MyForm()
    print(form)
    return render(request, "home.html", {"today": today, 'form': form})
def predict():
    form = MyForm(request.form)
    message = ''
    liste = []

    if request.method == 'POST':

        liste.append(form.Attr16.data)
        liste.append(form.Attr25.data)
        liste.append(form.Attr33.data)
        liste.append(form.Attr40.data)
        liste.append(form.Attr46.data)
        liste.append(form.Attr63.data)
        liste.append(form.year.data)
        p = model.predict(pd.DataFrame(liste))[0]
        if p == 1:
            message = "Sorry it seems that your company go straight to bankruptcy"
        elif p == 0:
            message = "Your company will not go to bankruptcy"

        flash(message)
        return redirect(url_for('index'))
    else:

        return render_template('pred.html', form=form)
Ejemplo n.º 3
0
def get_atis(icao):
    print(icao)
    form = MyForm()
    if form.is_submitted:
        print("Validated")
        return render_template("get_atis.html", icao=icao)
    return render_template("get_atis.html")
Ejemplo n.º 4
0
def results():
    """ Show results page or the error page """
    myform = MyForm(request.form)
    if request.method == 'POST' and myform.validate():
        dub = myform.doubler.data * 2
        return render_template('results.html', form=myform, doubler=dub)
    return render_template('errors.html', form=myform)
Ejemplo n.º 5
0
def register():
    form = MyForm()
    if form.validate_on_submit():
        # cur  = mysql.connection.cursor()
        # cur.execute("INSERT INTO kaskoghar(username,email,password,name) VALUES(%s,%s,%s,%s)",(form.username.data,form.email.data,form.password.data,form.name.data))
        # mysql.connection.commit()
        # cur.close()
        db.session.close()
        x = db.session.query(KaskoGhar).filter_by(
            username=form.username.data).first()
        if (x):
            flash('choose a different username ')
            return render_template('registration.html', form=form)
        formdata = KaskoGhar(username=form.username.data,
                             email=form.email.data,
                             password=generate_password_hash(
                                 form.password.data),
                             name=form.name.data)
        print(type(formdata))
        db.session.add(formdata)

        db.session.commit()
        print(db.session)
        return redirect(url_for('home'))
    return render_template('registration.html', form=form)
Ejemplo n.º 6
0
def profile():
    myform = MyForm()

    if request.method == 'POST':
        if myform.validate_on_submit():

            firstname = myform.firstname.data
            lastname = myform.lastname.data
            email = myform.email.data
            location = myform.location.data
            biography = myform.biography.data
            gender = myform.gender.data
            photo = myform.photo.data

            filename = secure_filename(photo.filename)
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            userid = str(uuid.uuid4())
            created_on = format_date_joined()

            db = connect_db()
            cur = db.cursor()
            query = "insert into Profiles (firstname, lastname, email, location, biography, gender, photo, userid, created_on) values (%s, %s, %s, %s, %s, %s, %s, %s, %s);"
            data = (firstname, lastname, email, location, biography, gender,
                    filename, userid, created_on)
            cur.execute(query, data)
            db.commit()

            flash('Profile successfully added!', 'success')
            return redirect(url_for("profiles"))

        flash_errors(myform)
    return render_template('profile.html', form=myform)
Ejemplo n.º 7
0
def contact():
    form = MyForm()
    if form.validate_on_submit():
        return "Hey there, {}!".format(form.name.data)
        
    else:
        return render_template("contact.html", form=form)
Ejemplo n.º 8
0
def profile():
    form = MyForm()
    print form.validate_on_submit()
    print form.errors
    print request.form
    if request.method == 'POST' and form.validate_on_submit():
        count = db.session.query(UserProfile).count()
        location = form.location.data
        bio = form.biography.data
        lname = form.lastname.data
        fname = form.firstname.data
        mail = form.email.data
        gender = form.gender.data
        photograph = form.photo.data
        date = datetime.date.today()
        uid = 10000 + count
        filename = str(uid) + ".jpg"
        photograph.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        user = UserProfile(id=uid,
                           first_name=fname,
                           last_name=lname,
                           gender=gender,
                           location=location,
                           bio=bio,
                           email=mail,
                           created_on=date)
        db.session.add(user)
        db.session.commit()
        flash('Profile created!', 'success')
        return redirect(url_for('profiles'))
    else:
        return render_template('profile.html', form=form)
Ejemplo n.º 9
0
def predict():
    '''
    For rendering results on HTML GUI
    '''
    form = MyForm()

    features = request.form.values()

    final_features = []
    for val in features:

        final_features.append(val)
    final_features.remove(final_features[-1])
    final_features.remove(final_features[0])
    final_list = []
    for num in final_features:
        final_list.append(int(num))
    final = [final_list]
    final_arr = np.asarray(final)
    final_arr.reshape(-1, 1)
    prediction = model.predict(final_arr)

    output = prediction
    if (output == 0):
        predicted_value = "Rejected"
    elif (output == 1):
        predicted_value = "Accepted"

    #output=features
    return render_template(
        'about.html',
        prediction_text=
        f"Your Loan Application is likely to be : {predicted_value}")
Ejemplo n.º 10
0
def put_applicant():

    global job_id

    if request.method == 'POST':
        if request.get_json():

            job_data = request.get_json()
            job_id = job_data['id']

            return jsonify({"message": "success"})

    form = MyForm()

    form.validate_on_submit()
    for key, value in form.errors.items():
        flash(value, 'error')

        # if action is POST and form is valid
    if form.validate_on_submit():

        result = request.form.to_dict()
        data = {
            'firstname': result['firstname'],
            'surname': result['surname'],
            'email': result['email'],
            'dob': result['dob'],
            'phone': result['phone'],
            'job_ref': job_id[3:]
        }
        if client:
            # for reading the job_ref
            job_data = request.get_json()
            flag = False
            # check whether in the database there is no user with these credentials
            # an user CANNOT apply for the same job once but CAN apply two different jobs
            for document in appi_db:
                if (document['email']
                        == data['email']) and (job_id[3:]
                                               == document['job_ref']):
                    flag = True

            if flag == False:
                # create a document and add the data to it
                my_document = appi_db.create_document(data)

                flash('You have been added to the database', 'success')
                # use sessions to share the document info to the other routes
                session['document'] = my_document
            else:
                flash('Sorry you cannot apply for the same job twice',
                      'validation')

            return render_template('applicant.html', form=form)
        else:
            print('No database')
            return jsonify(data)

    return render_template('applicant.html', form=form)
Ejemplo n.º 11
0
def submit():
    form = MyForm()
    if form.validate_on_submit():
        name = form.name.data
        print name
        store_bookmark(name, name)
        return 'success data'
    return render_template('submit.html', form=form)
Ejemplo n.º 12
0
def home():
    form = MyForm()

    if form.validate_on_submit():
        date = form.date.data
        city = form.city.data

    return render_template("login.html", title='Prometric check', form=form)
Ejemplo n.º 13
0
    def post(self, request):
        form = MyForm(data=request.POST)
        if form.is_valid():
            messages.success(request, form.cleaned_data['message'])
        else:
            messages.error(request, 'Validation failed')

        c = {'form': form}
        return render(request, 'my_app/form.html', c)
Ejemplo n.º 14
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))

    form = MyForm()
    if request.method == "POST" and form.validate_on_submit():
        # referral = request.form.get('ref')
        email = form.email.data
        password = form.password.data
        username = form.username.data
        bank_name = form.bank_name.data
        account_name = form.account_name.data
        account_number = form.account_number.data
        bitcoin_wallet = form.bitcoin_wallet.data
        mobile_number = form.mobile_number.data
        country = request.form.get("country")
        referral = form.referral.data

        password = md5_crypt.hash(password)
        check_for_first_user = len(User.query.all())
        if not check_for_first_user:
            user = User(username=username,
                        referral=referral,
                        is_admin=True,
                        password=password,
                        country=country,
                        account_number=account_number,
                        account_name=account_name,
                        bitcoin_addr=bitcoin_wallet,
                        bank_name=bank_name,
                        mobile_number=mobile_number,
                        email=email)
        else:
            user = User(username=username,
                        referral=referral,
                        is_admin=False,
                        password=password,
                        country=country,
                        account_number=account_number,
                        account_name=account_name,
                        bitcoin_addr=bitcoin_wallet,
                        bank_name=bank_name,
                        mobile_number=mobile_number,
                        email=email)

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

        flash("You have signed up successfully")
        return redirect('/login')
    else:
        ref = request.args.get("ref")
        context = {"ref": ref}
        all_tasks = Admin_tasks.query.all()
        for task in all_tasks:
            context[f"{task.key}"] = task.value
        return render_template("sign_up.html", form=form, context=context)
Ejemplo n.º 15
0
def contact():
    myform=MyForm()
    """Render the website's contact page."""
    if request.method == 'POST' and myform.validate_on_submit():
        send_mail(myform.name.data,myform.email.data,myform.subject.data,myform.message.data)
        flash('Message Successfully Sent')
        return redirect(url_for('home'))
    else:
        return render_template('contact.html',form=myform,addtext='Error sending')
Ejemplo n.º 16
0
def index():
    form = MyForm()
    # post
    if form.validate_on_submit():
      # extract form input data
      input_value = form.name.data
      result = input_value.upper()
      return render_template('result.html', result=result)
    # get
    return render_template('index.html', form=form)
Ejemplo n.º 17
0
def contact():
    form = MyForm()
    if form.validate_on_submit():
        msg	= Message(request.form['subject'], sender=(request.form['name'], request.form['email']), recipients=["*****@*****.**"])
        msg.body =	request.form['message']
        mail.send(msg)
        msg.body	=	request'This	is	the	body	of	the	message'
        return redirect(url_for('home'))
            
    return render_template('contact.html', form=form)
Ejemplo n.º 18
0
def submit():
    form = MyForm()
    if request.method == 'POST':
        msg = Message(request.form['name'],
                      sender=(form.name.data, form.email.data),
                      recipients=["*****@*****.**"])
        msg.body = form.text.data
        mail.send(msg)

    return render_template('contact.html', ccform=form)
Ejemplo n.º 19
0
def contact():
    form = MyForm()
    if form.validate_on_submit():
        msg	=	Messagere)
        msg.body =	request.form['message']
        mail.send(msg)
        
        return redirect(url_for('home'))
            
    return render_template('contact.html', form=form)
Ejemplo n.º 20
0
def contact():
    form = MyForm(request.form)
    if request.method == 'POST' and form.validate():
        msg = Message("form.subject.data",
                      sender=('form.name.data', 'form.email.data'),
                      recipients=['smtp.mailtrap.io'])
        msg.body = 'form.textArea.data'
        mail.send(msg)
        flash('Message Sent')
        return redirect(url_for('home'))
    return render_template('contact.html')
Ejemplo n.º 21
0
def contact():
    form = MyForm()
    if form.validate_on_submit():
        msg = Message(request.form['subject'],
                      sender=(request.form['name'], request.form['email']),
                      recipients=["*****@*****.**"])
        msg.body = request.form['message']
        mail.send(msg)

        return redirect(url_for('home'))

        return redirect(url_for('home'))
Ejemplo n.º 22
0
def contact():
    form = MyForm()
    if request.method == 'POST':
        if form.validate():
            msg =  Message(request.form['subject'],
                    sender=(request.form['name'],request.form['email']),
                    recipients=["*****@*****.**"])
            msg.body = request.form['message'];
            mail.send(msg)
            flash('Message was sent')
            return redirect(url_for('home'))
    return render_template('contact.html',form=form)
Ejemplo n.º 23
0
def contact():
    form = MyForm()
    if request.method == "POST":
        if form.validate_on_submit():
            msg = Message("subject",
                          sender=("name", "email"),
                          recipients=["*****@*****.**"])
            msg.body = 'message'
            mail.send(msg)
            flash('message has been sent!!', 'success')
            return redirect(url_for('home'))
    return render_template('contact.html', form=form)
Ejemplo n.º 24
0
def index():
    form = MyForm()
    users = models.User.get_all()
    if form.validate_on_submit:
        username = form.username.data
        email = form.email.data
        if username and email:
            user = models.User(username=username, email=email)
            db.session.add(user)
            db.session.commit()
            flash("Stored '{}'".format(username))
            return redirect(url_for('index'))
    return render_template('main/index.html', form=form, users=users)
Ejemplo n.º 25
0
def contact():
    form = MyForm()
    if form.validate_on_submit():
        msg = Message(request.form['subject'],
                      sender=(request.form['name'], request.form['email']),
                      recipients=["*****@*****.**"])
        msg.body = request.form['message']
        mail.send(msg)

        return redirect(url_for('home'))
        flash('Mail Sent!')
        return str(get_flashed_messages())

    return render_template('contact.html', form=form)
Ejemplo n.º 26
0
def cart(request):
    args = {}
    args.update(csrf(request))
    if request.method == 'POST':
        args['form'] = MyForm(request.POST)
        if request.POST['brand']:
            brand_id = int(request.POST['brand'])
        else:
            brand_id = 1
        selected_models = Model.objects.filter(brands=Brand.objects.get(id=brand_id))
        args['form'].fields['model'].queryset = selected_models
        if args['form'].is_valid():
            args['thanks'] = True
            args['model'] = Model.objects.get(pk=request.POST['model'])
            args['brand'] = Brand.objects.get(pk=request.POST['brand'])
            args['distance'] = request.POST['run']
            return render_to_response('base.html', args)
        return render_to_response('base.html', args)
    else:
        selected_models = Model.objects.filter(brands=Brand.objects.get(id=1))
        args['form'] = MyForm(initial={'brand': 1})
        args['form'].fields['model'].queryset = selected_models
        return render_to_response('base.html', args)
Ejemplo n.º 27
0
def contact():
    """ """
    form = MyForm(request.form)
    if request.method=="POST" and form.validate():
        name=request.form['name']
        email=request.form['email']
        subject=request.form['subject']
        message=request.form['message']
        
        msg = Message(subject, sender=(name,email), recipients = ["*****@*****.**"])
        msg.body = message
        mail.send(msg)
        flash('Message sent successfully',)
        return redirect(url_for('home'))
Ejemplo n.º 28
0
def contact():
    form = MyForm()
    if request.method=='POST':
        if form.validate_on_submit():
            name = form.name.data
            email = form.email.data
            subject = request.form['subject']
            message = request.form['message']
            msg = Message(subject, sender=(name,email), recipients=["*****@*****.**"])
            msg.body = message
            mail.send(msg)
            flash('Message Sent')
            return redirect(url_for('home'))

    return render_template('contact.html', form=form)
Ejemplo n.º 29
0
def home():
    message = ''
    form = MyForm(csrf_enabled=False)
    if form.validate_on_submit():
        message = form.message.data
    else:
        message_validation_errors = form.errors.get('message')
        if message_validation_errors:
            message = message_validation_errors[0]  # 今回は0番目のエラーのみ表示する

    return render_template(
        'index.html',
        message=message,
        form=form,
    )
Ejemplo n.º 30
0
def contact():
    form = MyForm()
    if request.method == 'POST' and form.validate:
        name = form.name.data
        email = form.email.data
        subject = form.subject.data
        msg = form.msg.data
        msg = Message(form.subject.data,
                      sender=(form.name.data, form.email.data),
                      recipients=["*****@*****.**"])
        msg.body = form.msg.data
        mail.send(msg)
        flash("Message Sent!")
        return redirect(url_for('home'))
    else:
        return render_template('contact.html', form=form)