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')
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
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'
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')
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)
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()
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)
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()
def create(id, name, description): db = get_db() db.execute( "INSERT INTO organization(id, name, description) " " VALUES (?, ?, ?)", (id, name, description), ) db.commit()
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
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()
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
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
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
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
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
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
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()
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
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
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
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)
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
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)
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
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)
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)