WebApp

Check-in [07372acec1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Thread implemented
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA3-256:07372acec1f21f47aeb329f1c2094da5b30e56b028289eb3725b113e30b2f054
User & Date: sebpc 2018-05-30 17:49:57
Context
2018-05-30
17:49
Thread implemented Leaf check-in: 07372acec1 user: sebpc tags: trunk
2018-05-28
15:59
Rest of exception handling has been implemented check-in: 384da38890 user: sebpc tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to vsearch4web.py.

1

2
3
4
5

6
7
8
9
10
11
12
..
17
18
19
20
21
22
23
24



25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
from flask import Flask, render_template, request, escape, session

from vsearch import search4letters
from DBcm import UseDatabase, ConnectionError, CredentialsError, SQLError
from checker import check_logged_in


app = Flask(__name__)

app.secret_key = 'Moj$3kret'

db = 'vsearchlog.db'


................................................................................


@app.route('/logout')
def logout():
    session.pop('logged_in')
    return 'Zostales wylogowany'





def log_request(req: 'flask_request', res: str) -> None:

    with UseDatabase(db) as cursor:
        _SQL = """insert into log
        (phrase, letters, ip, browser_string, results)
        values
        (?, ?, ?, ?, ?);"""
        cursor.execute(_SQL, (req.form['phrase'],
                              req.form['letters'],
                              req.remote_addr,
                              req.user_agent.browser,
                              res,))


@app.route('/search4', methods=['POST'])
def do_search() -> 'html':
    phrase = request.form['phrase']
    letters = request.form['letters']
    title = "Oto twoj wynik"
    result = str(search4letters(phrase, letters))
    try:
        log_request(request, result)

    except Exception as err:
        print('***Login failed with this error: ' + str(err))
    return render_template('results.html',
        the_phrase = phrase,
		the_letters = letters,
		the_title = title,
		the_results = result,)

>



|
>







 








>
>
>
|
>
|
|
|
|
|
|
|
|
|
|
<
<
<
<





|
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
..
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41




42
43
44
45
46
47
48
49
50
51
52
53
54
55
from flask import Flask, render_template, request, escape, session
from flask import copy_current_request_context
from vsearch import search4letters
from DBcm import UseDatabase, ConnectionError, CredentialsError, SQLError
from checker import check_logged_in
from threading import Thread
from time import sleep
app = Flask(__name__)

app.secret_key = 'Moj$3kret'

db = 'vsearchlog.db'


................................................................................


@app.route('/logout')
def logout():
    session.pop('logged_in')
    return 'Zostales wylogowany'


@app.route('/search4', methods=['POST'])
def do_search() -> 'html':
    @copy_current_request_context
    def log_request(req: 'flask_request', res: str) -> None:
        sleep(15)
        with UseDatabase(db) as cursor:
            _SQL = """insert into log
            (phrase, letters, ip, browser_string, results)
            values
            (?, ?, ?, ?, ?);"""
            cursor.execute(_SQL, (req.form['phrase'],
                                  req.form['letters'],
                                  req.remote_addr,
                                  req.user_agent.browser,
                                  res,))




    phrase = request.form['phrase']
    letters = request.form['letters']
    title = "Oto twoj wynik"
    result = str(search4letters(phrase, letters))
    try:
        t = Thread(target=log_request, args=(request, result))
        t.start()
    except Exception as err:
        print('***Login failed with this error: ' + str(err))
    return render_template('results.html',
        the_phrase = phrase,
		the_letters = letters,
		the_title = title,
		the_results = result,)