Example #1
0
def register():
    if request.method != 'POST':
        return render_template('auth/register.html')

    username = request.form['username']
    password = request.form['password']

    db = get_db()

    error = None

    if not username:
        error = 'Username is required'
    elif not password:
        error = 'Password is required'
    elif db.execute('SELECT id FROM user WHERE username = ?',
                    (username, )).fetchone() is not None:
        error = 'User {} is already registered.'.format(username)

    if error is None:
        db.execute('INSERT INTO user (username, password) VALUES (?, ?)',
                   (username, generate_password_hash(password)))
        db.commit()
        return redirect(url_for('auth.login'))

    flash(error)
    return render_template('auth/register.html')
Example #2
0
    def search(show_name, year, media_type=None):
        from metafinder.identifier import Identifier
        from db.db import get_db
        import sqlite3

        matches = None

        re_search = AniDB._clean_name(show_name, year)
        try:
            db = get_db()
            db.connect(database=AniDB.DATABASE)

            try:
                matches = db.get_ext_ids(AniDB.TITLE_TO_ID_TABLE, re_search)
            except sqlite3.OperationalError:
                print('generating anidb table')

                AniDB._generate_search_table(db)
                matches = db.get_ext_ids(AniDB.TITLE_TO_ID_TABLE, re_search)

            if len(matches) == 0 and year is not None:
                re_search = AniDB._clean_name(show_name, None)
                matches = db.get_ext_ids(AniDB.TITLE_TO_ID_TABLE, re_search)

        finally:
            db.close()

        return matches
Example #3
0
def register():
    if request.method == 'POST':
        nome = request.form['nome']
        telefone = request.form['telefone']
        visualizacao = request.form['visualizacao']

        db = get_db()
        error = None

        if not nome:
            error = 'Nome is required.'
        elif not telefone:
            error = 'Telefone is required.'
        elif db.execute('SELECT id FROM client WHERE nome = ?',
                        (nome, )).fetchone() is not None:
            error = 'User {} is already registered.'.format(nome)

        if error is None:
            db.execute(
                'INSERT INTO client (nome, telefone, visualizacao) VALUES (?, ?, ?)',
            )
            db.commit()
            return 'salvo no db'

        flash(error)

    return 'cadastro realizado'
Example #4
0
def login():
    if request.method != 'POST':
        return render_template('auth/login.html')

    username = request.form['username']
    password = request.form['password']
    db = get_db()
    error = None

    user = db.execute('SELECT * FROM user WHERE username = ?',
                      (username, )).fetchone()

    if user is None:
        error = 'Incorrect username.'
    elif not check_password_hash(user['password'], password):
        error = 'Incorrect password'

    if error is None:
        session.clear()
        session['user_id'] = user['id']
        return redirect(url_for('index'))

    flash(error)

    return render_template('auth/login.html')
Example #5
0
def question(qid):
    user = get_cur_user()
    db = get_db()
    db.execute(
        'select questions.id as question_id, questions.question, askers.name as asker_name, experts.name as expert_name from questions join users as askers on askers.id = questions.ask_by_id join users as experts on experts.id = questions.expert_id where questions.id = ?',
        [question_id])

    return render_template("question.html", user=user)
Example #6
0
 def create(orderid, status, image_file, shopid, user_id) :
     db = get_db()
     db.execute (
         "INSERT INTO orders (orderid, file, shopid, status, userid) "
         "VALUES (?, ?, ?, ?, ?)",
         (orderid, image_file, shopid, status, user_id),
     )
     db.commit()
Example #7
0
def index():
    user = get_cur_user()
    db = get_db()
    query = db.execute(
        'select questions.id as question_id, questions.question, askers.name as asker_name, experts.name as expert_name from questions join users as askers on askers.id = questions.ask_by_id join users as experts on experts.id = questions.expert_id where questions.answer_text is not null'
    )
    res = query.fetchall()
    return render_template("home.html", user=user, res=res)
Example #8
0
 def create(id_, name, email, profile_pic):
     db = get_db()
     db.execute(
         "INSERT INTO user (id, name, email, profile_pic) "
         "VALUES (?, ?, ?, ?)",
         (id_, name, email, profile_pic),
     )
     db.commit()
Example #9
0
 def create(id, name, description):
     db = get_db()
     db.execute(
         "INSERT INTO organization(id, name, description) "
         " VALUES (?, ?, ?)",
         (id, name, description),
     )
     db.commit()
Example #10
0
 def create(name, description, org_id):
     db = get_db()
     db.execute(
         "INSERT INTO topic (name, description, org_id) "
         "VALUES (?, ?, ?)",
         (name, description, org_id),
     )
     db.commit()
    def load_all_cases(self):
        c = get_db().cursor()
        c.execute('''SELECT * FROM cases_by_loc''')
        cases = [[item for item in results] for results in c.fetchall()]
        c.close()
        close_db()

        return cases
Example #12
0
def load_logged_in_user():
    user_id = session.get('user_id')

    if user_id is None:
        g.user = None
    else:
        g.user = get_db().execute('SELECT * FROM user WHERE id = ?',
                                  (user_id, )).fetchone()
Example #13
0
def unanswered():
    user = get_cur_user()
    db = get_db()
    question_query = db.execute(
        "select questions.id, questions.question, users.name from questions join users on users.id = questions.ask_by_id where questions.answer_text is null and questions.expert_id = ? ",
        [user['id']])
    questions = question_query.fetchall()

    return render_template("unanswered.html", user=user, questions=questions)
    def get_cases_by_council(self, council):
        c = get_db().cursor()
        c.execute('''SELECT * FROM cases_by_loc 
            WHERE local_gov_area like {}'''.format(council))
        cases = [[item for item in results] for results in c.fetchall()]
        c.close()
        close_db()

        return cases
    def get_cases_by_postcode(self, postcode):
        c = get_db().cursor()
        c.execute('''SELECT * FROM cases_by_loc
            WHERE postcode LIKE "{}"'''.format(postcode))
        cases = [[item for item in results] for results in c.fetchall()]
        c.close()
        close_db()

        return cases
    def get_last_case_id(self, table_name):
        c = get_db().cursor()
        c.execute('''SELECT id FROM "{table}" 
            WHERE id=(SELECT max(id) FROM {table})'''.format(table = table_name))
        last_case_update = c.fetchone()
        c.close()
        close_db()

        return last_case_update[0]
 def get_available_councils(self):
     c = get_db().cursor()
     c.execute('''SELECT DISTINCT local_gov_area FROM cases_by_loc''')
     councils = [str(results[0]) for results in c.fetchall()]
     c.close()
     close_db()
     councils.sort()
     
     return councils
Example #18
0
 def get(user_id) : 
     db = get_db()
     orders = db.execute(
         "SELECT orders.orderid, shop.shop_name, orders.file  FROM orders INNER JOIN shop ON orders.shopid = shop.shopid WHERE orders.userid = ?", (user_id,)
     ).fetchall()
     if not orders:
         return None
     
     return orders
Example #19
0
def get_cur_user():
    user_res = None
    if "user" in session:
        user = session["user"]
        db = get_db()
        user_query = db.execute(
            "select id, name, password, expert, admin from users where name = ?",
            [user])
        user_res = user_query.fetchone()

    return user_res
Example #20
0
    def get_order(orderid):
        db = get_db()
        orders = db.execute(
            '''SELECT orders.status, orders.file, shop.shop_name, shop.shop_address 
            FROM  orders 
            INNER JOIN shop 
            ON shop.shopid = orders.shopid  
            WHERE orders.orderid = ?''', (orderid,)
        ).fetchone()

        return orders
Example #21
0
    def get(topic_id):
        db = get_db()
        topic = db.execute("SELECT * FROM topic WHERE id = ?",
                           (topic_id, )).fetchone()
        if not topic:
            return None

        topic = Topic(id_=topic[0],
                      name=topic[1],
                      description=topic[2],
                      org_id=topic[3])
        return topic
Example #22
0
    def get(org_id):
        db = get_db()
        org = db.execute(
            "SELECT * FROM organization WHERE id = ?", (org_id,)
        ).fetchone()
        if not org:
            return None

        org = Organization(
            id_=org[0], name=org[1], description=org[2]
        )
        return org
Example #23
0
 def create(
     email,
     file,
     topic_id,
 ):
     db = get_db()
     db.execute(
         "INSERT INTO contribution (email, file, topic_id) "
         "VALUES (?, ?, ?)",
         (email, file, topic_id),
     )
     db.commit()
Example #24
0
    def get(user_id):
        db = get_db()
        user = db.execute("SELECT * FROM user WHERE id = ?",
                          (user_id, )).fetchone()
        if not user:
            return None

        user = User(id_=user[0],
                    name=user[1],
                    email=user[2],
                    profile_pic=user[3])
        return user
Example #25
0
    def get(contribution_id):
        db = get_db()
        contribution = db.execute("SELECT * FROM contribution WHERE id = ?",
                                  (contribution_id, )).fetchone()
        if not contribution:
            return None

        contribution = Contribution(id_=contribution[0],
                                    email=contribution[1],
                                    file=contribution[2],
                                    topic_id=contribution[3],
                                    timestamp=contribution[4])
        return contribution
Example #26
0
    def get_all():
        db = get_db()
        shops = db.execute("SELECT * FROM shop").fetchall()
        if not shops:
            return None

        shop_list = []
        for shop in shops:
            shop_obj = Shop(id_=shop[0],
                            name=shop[1],
                            email=shop[2],
                            address=shop[3])
            shop_list.append(shop_obj)
        return shop_list
Example #27
0
def answer(q_id):
    user = get_cur_user()
    db = get_db()

    if request.method == 'POST':
        answer = request.form['answer']
        db.execute('update questions set answer_text = ? where id = ? ',
                   [answer, q_id])
        db.commit()
        return redirect(url_for('unanswered'))

    query = db.execute('select id, question from questions where id = ?',
                       [q_id])
    question = query.fetchone()
    return render_template("answer.html", user=user, question=question)
Example #28
0
    def revalidate_client_cache(self, file_path=None):
        response_code = None

        if 'If-None-Match' in self.headers.keys():
            if file_path is not None:
                from hashlib import sha256

                with open(file_path, "rb") as f:
                    _bytes = f.read()

                etag = sha256(_bytes).hexdigest()
            else:
                etag = get_db().version()

            if f'"{etag}"' == self.headers['If-None-Match']:
                response_code = 304

        elif 'If-Modified-Since' in self.headers.keys():
            from datetime import datetime, timezone

            if file_path is not None:
                last_modified = int(os.path.getmtime(file_path))
            else:
                last_modified = get_db().last_modified()

            dt_last_modified = datetime.fromtimestamp(
                last_modified, timezone.utc).replace(tzinfo=None)
            dt_if_modified_since = datetime.strptime(
                self.headers['If-Modified-Since'], '%a, %d %b %Y %H:%M:%S %Z')

            if dt_last_modified <= dt_if_modified_since:
                response_code = 304
        # elif 'If-Unmodified-Since', 'If-Match'

        # print('revalidate_client_cache:', response_code)
        return response_code
Example #29
0
def login():
    user = get_cur_user()
    if request.method == "POST":
        password = request.form["inputPassword"]
        username = request.form["inputName"]
        db = get_db()
        user_query = db.execute(
            "select id, name, password from users where name = ?", [username])
        res = user_query.fetchone()
        if res == None or not check_password_hash(res["password"], password):
            return "User name or password incorrect!"
        else:
            session["user"] = res["name"]
            return redirect(url_for("index"))

    return render_template("login.html", user=user)
Example #30
0
def handler(resource_packets, context):
    # resource_packets is a native python data structure, not the raw json string
    # you expect. This conversion is handled by Lambda automatically.

    # TODO: this connection should be moved outside of the handler function, and
    # only re-established here if the connection has been lost
    database = db.get_db()

    strategy = strategies.get_strategy()
    command = None

    for resource_packet in resource_packets:
        database.write(resource_packet)
        command = strategy.generate_command(resource_packet)

    return command
Example #31
0
    def open_file(self):
        old_db = db.get_db()
        try:
            file = QtWidgets.QFileDialog.getOpenFileName(None, '  Open log database')[0]
            if not os.path.isfile(file):
                return
        except:
            return

        try:
            db.set_db(file)
            self._init_filter()
        except DBError:
            db.set_db(old_db)
            QtWidgets.QMessageBox.critical(self, "Database Error", "Not a log database", QtWidgets.QMessageBox.Ok)
        else:
            QtWidgets.QMessageBox.information(self, "Import database", "Import successfully", QtWidgets.QMessageBox.Ok)
Example #32
0
    def __init__(self, parent, infile, outfile):
        super(ImportDialog, self).__init__(parent)
        self.parent = parent
        self.setupUi(self)
        self.imported_file = infile
        self.db_file = outfile

        self.progress.setMaximum(100)

        self._paused = False
        self._cancel = False
        self._importing = False

        self._old_db = db.get_db()
        try:
            db.set_db(outfile)
        except:
            db.set_db(self._old_db)
            self.close()

        else:
            self.button_import.clicked.connect(self._log_import)
            self.button_cancel.clicked.connect(self.cancel)