示例#1
0
文件: app.py 项目: drazka/task_app
def devices(user_id, device_id):
    #print(user_id, device_id)
    list_deviceId = device_id.split(",")

    if device_id == "":
        sql = 'SELECT * FROM bugs WHERE testerId = {}'.format(user_id)
    elif len(list_deviceId) > 1:
        for id in list_deviceId:
            try:
                int(id)
            except ValueError:
                return " - not able to check - wrong input "

        sql = 'SELECT * FROM bugs WHERE testerId = {} AND ' \
          'deviceId IN {}'.format(user_id, tuple(list_deviceId))
    else:
        try:
            int(device_id)
        except ValueError:
            return " - not able to check - wrong input "

        sql = 'SELECT * FROM bugs WHERE testerId = {} AND ' \
          'deviceId = {}'.format(user_id, device_id)
    db = DBconnection()
    db.cursor.execute(sql)
    bugs = []
    for record in db.cursor:
        bugs.append(record)
    text3 = " filled " + str(len(bugs)) + " bugs"
    print(bugs)
    return text3
示例#2
0
	def deleteById(id):
		emp=Ems_services.searchById(id)
		if emp==None:
			return False
		else:
			cnx=DBconnection.connect()
			cur=cnx.cursor()
			query="delete from empDetails where empId=%s"
			data=[]
			data.append(id)
			cur.execute(query,data)
			cnx.commit()
			cur.close()
			cnx.close()
			return True
示例#3
0
	def getAllEmployees():
		emplist=[]
		cnx=DBconnection.connect()
		cur=cnx.cursor()
		query="select * from empDetails"
		cur.execute(query)
		tb=cur.fetchall()
		for row in tb:
			emp=Employee()
			emp.setId(int(row[0]))
			emp.setName(row[1])
			emp.setSalary(float(row[2]))
			emp.setAddress(row[3])
			emplist.append(emp)
		cur.close()
		cnx.close()
		return emplist
示例#4
0
	def addEmployee(emp):
		result=False
		cnx=DBconnection.connect()
		cur=cnx.cursor()
		query="insert into empDetails values(%s,%s,%s,%s)"
		data=[]
		data.append(emp.getId())
		data.append(emp.getName())
		data.append(emp.getSalary())
		data.append(emp.getAddress())
		try:
			cur.execute(query,data)
		except:
			return False
		if (cur.rowcount==1):
			result=True
		cnx.commit()
		cur.close()
		cnx.close()
		return result
示例#5
0
 def searchBySalRange(min, max):
     emplist = []
     cnx = DBconnection.connect()
     cur = cnx.cursor()
     query = "select * from empDetails_2 where empSalary>%s and empSalary<%s"
     data = []
     data.append(min)
     data.append(max)
     cur.execute(query, data)
     tb = cur.fetchall()
     for row in tb:
         emp = Employee()
         emp.setId(int(row[0]))
         emp.setName(row[1])
         emp.setSalary(float(row[2]))
         emp.setAddress(row[3])
         emplist.append(emp)
     cur.close()
     cnx.close()
     return emplist
示例#6
0
	def searchById(id):
		cnx=DBconnection.connect()
		cur=cnx.cursor()
		query="select * from empDetails where empId=%s"
		data=[]
		data.append(id)
		cur.execute(query,data)
		tb=cur.fetchall()
		if cur.rowcount==0:
			cur.close()
			cnx.close()
			return None
		for row in tb:
			emp=Employee()
			emp.setId(int(row[0]))
			emp.setName(row[1])
			emp.setSalary(float(row[2]))
			emp.setAddress(row[3])
		cur.close()
		cnx.close()
		return emp
示例#7
0
文件: app.py 项目: drazka/task_app
def post_form():
    if request.method == "GET":
        return render_template("app.html")
    else:
        db = DBconnection()
        if request.form["submit"] == "search_tester":
            table = "testers"
            country = request.form["country"]
            device = request.form["device"]
            #print(len(country))
            if country == "":
                sql = 'SELECT * FROM {}'.format(table)
            elif len(country) == 2:
                country = "'" + country + "'"
                sql = 'SELECT * FROM {} WHERE country = {}'.format(
                    table, country)
            else:
                list_country = country.split(",")
                #print(list_country)

                sql = "SELECT * FROM {} WHERE country IN {}".format(
                    table, tuple(list_country))

            #print(sql)
            try:
                db.cursor.execute(sql)
            except Exception:
                return render_template("app.html", err='podaj poprawne dane')

            results = []
            resultsInfo = []
            for record in db.cursor:
                text1 = "tester " + record[1] + " " + record[2]
                print(text1)
                text2 = " for device o ID " + device
                bugs = devices(record[0], device)
                resultsInfo.append(text1 + text2 + bugs)
                results.append(bugs)
            return render_template('app_result.html', result=resultsInfo)
示例#8
0
def all_form_day_one():
    if request.method == "GET":
        return render_template("index.html")

    else:
        db = DBconnection(user="******",
                          password="******",
                          database="cinemas_db")
        if request.form["submit"] == "add_cinema":
            new_cinema = {
                "name": request.form["name"],
                "address": request.form["address"]
            }
            db.insert("Cinema", new_cinema)
            return "Zapisano kino w bazie danych." + render_template(
                "index.html")

        elif request.form["submit"] == "remove_cinema":
            cinema_to_remove = request.form["name"]
            db.delete("Cinema", "name", cinema_to_remove)
            return "Usunięto kino z bazy danych." + render_template(
                "index.html")

        elif request.form["submit"] == "show_cinemas":
            Cinemas = db.select("Cinema")
            return "<h2>Lista wszystkich kin:</h2>" + str(
                Cinemas) + render_template("index.html")

        elif request.form["submit"] == "search_cinema":
            cinema_to_search = request.form["name"]
            searched_cin = db.select("Cinema", "name", cinema_to_search)
            return "<h2>Wyszukiwanie zakończone. Wyświetlam wyniki zapytania dla: {}</h2>".format(
                cinema_to_search) + str(searched_cin) + render_template(
                    "index.html")

        elif request.form["submit"] == "add_movie":
            if 0 < float(request.form["rating"]) < 10:
                new_movie = {
                    "name": request.form["name"],
                    "description": request.form["desc"],
                    "rating": request.form["rating"]
                }
                db.insert("Movie", new_movie)
                return "Zapisano film w bazie danych." + render_template(
                    "index.html")
            else:
                return "Ocena filmu musi mieścić się w 10!" + render_template(
                    "index.html")

        elif request.form["submit"] == "remove_movie":
            movie_to_remove = request.form["name"]
            db.delete("Movie", "name", movie_to_remove)
            return "Usunięto film z bazy danych." + render_template(
                "index.html")

        elif request.form["submit"] == "show_movies":
            Movies = db.select("Movie")
            return "<h2>Lista wszystkich filmów:</h2>" + str(
                Movies) + render_template("index.html")

        elif request.form["submit"] == "search_mov_by_name":
            movie_to_search = request.form["name"]
            searched_mov_by_name = db.select("Movie", "name", movie_to_search)
            return "<h2>Wyszukiwanie zakończone. Wyświetlam wyniki zapytania dla: {}</h2>".format(
                movie_to_search) + str(searched_mov_by_name) + render_template(
                    "index.html")

        elif request.form["submit"] == "search_mov_by_rate":
            movie_to_search = request.form["rating"]
            searched_mov_by_rate = db.select("Movie", "rating",
                                             movie_to_search)
            return "<h2>Wyszukiwanie zakończone. Wyświetlam wyniki zapytania dla: Rating: {}</h2>".format(
                movie_to_search) + str(searched_mov_by_rate) + render_template(
                    "index.html")

        elif request.form["submit"] == "add_ticket":
            if float(request.form["price"]) > 0:
                new_ticket = {
                    "quantity": request.form["quantity"],
                    "price": request.form["price"]
                }
                db.insert("Ticket", new_ticket)
                return "Zapisano bilet w bazie danych." + render_template(
                    "index.html")
            else:
                return "Cena biletu musi być wieksza od zera" + render_template(
                    "index.html")

        elif request.form["submit"] == "remove_ticket":
            ticket_to_remove = request.form["ID"]
            db.delete("Ticket", "id", ticket_to_remove)
            return "Usunięto bilet z bazy danych." + render_template(
                "index.html")

        elif request.form["submit"] == "add_payment":
            new_payment = {
                "type": request.form["payment_type"],
                "data": request.form["payment_date"]
            }
            db.insert("Payment", new_payment)
            return "Zapisano płatność w bazie danych." + render_template(
                "index.html")

        elif request.form["submit"] == "remove_payment":
            ticket_to_remove = request.form["ID"]
            db.delete("Payment", "id", ticket_to_remove)
            return "Usunięto płatność z bazy danych." + render_template(
                "index.html")

        elif request.form["submit"] == "show_payments":
            Payments = db.select("Payment")
            return "<h2>Lista wszystkich płatności:</h2>" + str(
                Payments) + render_template("index.html")

        elif request.form["submit"] == "search_payment":
            if request.form["payment_search_type"] == "day":
                payment_to_search = request.form["payment_date_from"]
                searched_payment = db.select("Payment", "data",
                                             payment_to_search)
                return "<h2>Wyszukiwanie zakończone. Wyświetlam wyniki zapytania dla: Wg dnia: {}</h2>".format(
                    payment_to_search) + str(
                        searched_payment) + render_template("index.html")

            elif request.form["payment_search_type"] == "older":
                payment_to_search = request.form["payment_date_from"]
                searched_payment = db.select_adv("Payment", "data", "<",
                                                 payment_to_search)
                return "<h2>Wyszukiwanie zakończone. Wyświetlam wyniki zapytania dla: Starsze niż: {}</h2>".format(
                    payment_to_search) + str(
                        searched_payment) + render_template("index.html")

            elif request.form["payment_search_type"] == "newer":
                payment_to_search = request.form["payment_date_from"]
                searched_payment = db.select_adv("Payment", "data", ">",
                                                 payment_to_search)
                return "<h2>Wyszukiwanie zakończone. Wyświetlam wyniki zapytania dla: Nowsze niż: {}</h2>".format(
                    payment_to_search) + str(
                        searched_payment) + render_template("index.html")

            elif request.form["payment_search_type"] == "between":
                payment_to_search_a = request.form["payment_date_from"]
                payment_to_search_b = request.form["payment_date_to"]
                searched_payment = db.select_between("Payment", "data",
                                                     payment_to_search_a,
                                                     payment_to_search_b)
                return "<h2>Wyszukiwanie zakończone. Wyświetlam wyniki zapytania dla: Zakres: {} - {}</h2>".format(
                    payment_to_search_a, payment_to_search_b) + str(
                        searched_payment) + render_template("index.html")
示例#9
0
# coding=utf-8

import argparse

from clcrypto import check_password, password_hash
from Message import Message
from dbconnection import DBconnection
from user import User

db = DBconnection(user='******', password='******', database='Workshop')
cnx = db.cnx
cursor = db.cursor


def set_options():
    parser = argparse.ArgumentParser()
    parser.add_argument('-u', '--username', help="user's login")
    parser.add_argument('-p', '--password', help="user's password")
    parser.add_argument('-l',
                        '--list',
                        action="store_true",
                        help="lists all messages of user")
    parser.add_argument('-t', '--to', help="sets recipient")
    parser.add_argument('-s', '--send', '--send', help="sends a message")
    args = parser.parse_args()
    return args


options = set_options()

if options.username and options.password: