예제 #1
0
def getDTP() -> render_template:
    """Список ДТП"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'
    islogIn: bool = True if session.get('islogIn') else False
    wallet: str = session.get('wallet')
    session['lastPage'] = '/list/dtp/'
    role: int = session.get('role')
    session_role: int = session.get('session_role')
    list_dtp: list = []

    if wallet:
        info: dict = User.getUserInfo(wallet)['info']
        response = User.getDTP(wallet)
        if response['status']:
            list_dtp = response['dtp']

        return render_template('html/list_dtp.html',
                               islogIn=islogIn,
                               lastPage=lastPage,
                               list_dtp=list_dtp,
                               info=info,
                               role=role,
                               session_role=session_role,
                               datetime=dt)
예제 #2
0
def getCars() -> render_template:
    """Список машин"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'
    islogIn: bool = True if session.get('islogIn') else False
    session['lastPage'] = '/list/car/'
    wallet: str = session.get('wallet')
    role: int = session.get('role')
    session_role: int = session.get('session_role')
    list_cars: list = []

    if wallet:
        info: dict = User.getUserInfo(wallet)['info']
        response: dict = User.getCars(wallet)
        if response['status']:
            list_cars: list = response['cars']

        return render_template('html/list_car.html',
                               islogIn=islogIn,
                               lastPage=lastPage,
                               list_cars=list_cars,
                               info=info,
                               role=role,
                               session_role=session_role,
                               datetime=dt)
예제 #3
0
def getFines() -> render_template:
    """Список штрафов"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'
    islogIn: bool = True if session.get('islogIn') else False
    wallet: str = session.get('wallet')
    session['lastPage'] = '/list/fines/'
    role: int = session.get('role')
    session_role: int = session.get('session_role')
    list_fines: list = []

    if wallet:
        info: dict = User.getUserInfo(wallet)['info']
        response = User.getFines(wallet)
        if response['status']:
            list_fines = response['fines']

        return render_template('html/list_fines.html',
                               islogIn=islogIn,
                               lastPage=lastPage,
                               list_fines=list_fines,
                               info=info,
                               role=role,
                               session_role=session_role,
                               datetime=dt)
예제 #4
0
def getInsuranceHistory() -> render_template:
    """Вся история страховок"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'
    islogIn: bool = True if session.get('islogIn') else False
    wallet: str = session.get('wallet')
    role: int = session.get('role')
    session['lastPage'] = '/list/insurence/'
    session_role: int = session.get('session_role')
    list_insurence: list = []

    if wallet:
        info: dict = User.getUserInfo(wallet)['info']
        response = User.getInsuranceHistory(wallet)
        if response['status']:
            list_insurence = response['insurance_history']

        return render_template('html/list_insurence.html',
                               islogIn=islogIn,
                               lastPage=lastPage,
                               list_insurence=list_insurence,
                               info=info,
                               role=role,
                               session_role=session_role,
                               datetime=dt)
예제 #5
0
def addNewDL() -> render_template:
    """Зарегистрировать новые вод.удовст"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'

    if request.method == 'POST':
        wallet: str = session.get('wallet')
        private_key: str = request.form['private_key']
        if 'catA' in request.form:
            catA: bool = True
        else:
            catA: bool = False

        if 'catB' in request.form:
            catB: bool = True
        else:
            catB: bool = False

        if 'catC' in request.form:
            catC: bool = True
        else:
            catC: bool = False

        response = User.addNewDL(wallet, private_key, catA, catB, catC)
        if response['status']:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   info=True)
        else:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   addRiderLicenceToBase=True)
예제 #6
0
def addNewCategory() -> render_template:
    """Добавить новую категорию ТС"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'

    if request.method == 'POST':
        wallet: str = session.get('wallet')
        if 'catA' in request.form:
            catA: bool = True
        else:
            catA: bool = False

        if 'catB' in request.form:
            catB: bool = True
        else:
            catB: bool = False

        if 'catC' in request.form:
            catC: bool = True
        else:
            catC: bool = False
        private_key: str = request.form['private_key']

        response = User.addNewCategory(wallet, private_key, catA, catB, catC)
        if response['status']:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   info=True)
        else:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   addCategoryRiderLicence=True)
예제 #7
0
def main() -> render_template:
    """Главная страница"""

    islogIn: bool = True if session.get('islogIn') else False
    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'
    session['lastPage'] = '/'
    wallet: str = session.get('wallet')
    role: int = session.get('role')
    session_role: int = session.get('session_role')
    info: dict = {}

    if wallet:
        info: dict = User.getUserInfo(wallet)['info']
        if role == 4:
            balance_contract: int = Bank.getBalanceETH(
                wallet)['balance_contract']
            info.update({'balance_contract': balance_contract})
        elif role == 5:
            debt: int = Insurance.getInsuranceDebt(wallet)['debt']
            balance_contract: int = Insurance.getBalanceETH(
                wallet)['balance_contract']
            info.update({'balance_contract': balance_contract, 'debt': debt})

    return render_template('html/main.html',
                           islogIn=islogIn,
                           lastPage=lastPage,
                           info=info,
                           role=role,
                           session_role=session_role,
                           datetime=dt)
예제 #8
0
def getRequestsNewCategory() -> render_template:
    """Список новых категорий ТС вод.удовст для регистрации в базу ДПС"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'
    islogIn: bool = True if session.get('islogIn') else False
    wallet: str = session.get('wallet')
    role: int = session.get('role')
    session['lastPage'] = '/list/category_dps/'
    session_role: int = session.get('session_role')
    list_category: list = []

    if wallet:
        info: dict = User.getUserInfo(wallet)['info']
        response = DPS.getRequestsNewCategory(wallet)
        if response['status']:
            list_category = response['driver_licences']

        return render_template('html/category_dps.html',
                               islogIn=islogIn,
                               lastPage=lastPage,
                               list_category=list_category,
                               info=info,
                               role=role,
                               session_role=session_role,
                               datetime=dt)
예제 #9
0
def addCar() -> render_template:
    """Добавить ТС"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'

    if request.method == 'POST':
        wallet: str = session.get('wallet')
        private_key: str = request.form['private_key']
        price: int = int(request.form['price'])
        model: str = request.form['model']
        category: str = request.form['category']
        year: int = int(request.form['year'])

        response: dict = User.addCar(wallet, private_key, model, category,
                                     price, year)
        if response['status']:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   info=True)
        else:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   addCar=True)
예제 #10
0
    def requestInsurance(id_car: int) -> None:
        """Узнать стоимость страховки"""

        response: dict = User.requestInsurance(functional.wallet, id_car)

        if response['status']:
            cli.Logger.info(f'Стоимость страховки {response["price"]}')
        else:
            cli.Logger.warn(response['msg'])
예제 #11
0
    def payFine(private_key: str, id_fine: int) -> None:
        """Оплатить штраф"""

        response: dict = User.payFine(functional.wallet, private_key, id_fine)

        if response['status']:
            cli.Logger.info(response['msg'])
        else:
            cli.Logger.warn(response['msg'])
예제 #12
0
    def buyInsurance(private_key: str, id_car: int) -> None:
        """Регистрация страховки"""

        response: dict = User.buyInsurance(functional.wallet, private_key,
                                           id_car)

        if response['status']:
            cli.Logger.info(response['msg'])
        else:
            cli.Logger.warn(response['msg'])
예제 #13
0
    def addNewDL(private_key: str, catA: bool, catB: bool, catC: bool) -> None:
        """Зарегистрировать новое вод.удост"""

        response: dict = User.addNewDL(functional.wallet, private_key, catA,
                                       catB, catC)

        if response['status']:
            cli.Logger.info(response['msg'])
        else:
            cli.Logger.warn(response['msg'])
예제 #14
0
    def register(wallet: str, private_key: str, surname: str, name: str,
                 middlename: str) -> None:
        """Регистрация"""

        fio: str = f'{surname} {name} {middlename}'
        response: dict = User.register(wallet, private_key, fio)

        if response['status']:
            cli.Logger.info(response['msg'])
        else:
            cli.Logger.warn(response['msg'])
예제 #15
0
    def addNewCategory(private_key: str, catA: bool, catB: bool,
                       catC: bool) -> None:
        """Добавить новую категорию ТС в права"""

        response: dict = User.addNewCategory(functional.wallet, private_key,
                                             catA, catB, catC)

        if response['status']:
            cli.Logger.info(response['msg'])
        else:
            cli.Logger.warn(response['msg'])
예제 #16
0
    def addCar(private_key: str, model: str, category: str, market_price: int,
               year: int) -> None:
        """Добавить ТС"""

        response: dict = User.addCar(functional.wallet, private_key, model,
                                     category, market_price, year)

        if response['status']:
            cli.Logger.info(response['msg'])
        else:
            cli.Logger.warn(response['msg'])
예제 #17
0
    def addDL(private_key: str, experience: int, number: int, validity: str,
              catA: bool, catB: bool, catC: bool) -> None:
        """Добавить вод.удост  формат даты - (ДД.ММ.ГГГГ)"""
        validity = dt.strptime(validity, "%d.%m.%Y")
        validity = int(validity.timestamp())
        response: dict = User.addDL(functional.wallet, private_key, experience,
                                    number, validity, catA, catB, catC)

        if response['status']:
            cli.Logger.info(response['msg'])
        else:
            cli.Logger.warn(response['msg'])
예제 #18
0
    def changeUserInfo(private_key: str, surname: str, name: str,
                       middlename: str) -> None:
        """Изменить информация о пользователе"""

        fio: str = f'{surname} {name} {middlename}'
        response: dict = User.changeUserInfo(functional.wallet, private_key,
                                             fio)

        if response['status']:
            cli.Logger.info(response['msg'])
        else:
            cli.Logger.warn(response['msg'])
예제 #19
0
    def logIn(wallet: str, private_key: str) -> None:
        """Авторизация"""

        response: dict = User.logIn(wallet, private_key)

        if response['status']:
            functional.logIn: bool = True
            functional.wallet: str = wallet
            functional.role: int = response['role']
            functional.session_role: int = response['role']
            cli.Logger.info(response['msg'])
        else:
            cli.Logger.warn(response['msg'])
예제 #20
0
    def getDTP() -> None:
        """Список всех ДТП пользователя"""

        response: dict = User.getDTP(functional.wallet)

        if response['status']:
            cli.Logger.info(response['msg'])

            msg: str = f'"ID"{6 * " "}|{10 * " "}"ID Car"{10 * " "}| Time'
            cli.Logger.info(msg, prefix='DTP')
            for dtp in response['dtp']:
                msg: str = f'{dtp[0]}{(10-len(str(dtp[0]))) * " "}| {dtp[1]}{(26 - len(str(dtp[1]))) * " "} | {dt.strftime(dt.fromtimestamp(dtp[2]), "%d.%m.%Y %H:%M:%S")}'
                cli.Logger.info(msg, prefix='DTP')
        else:
            cli.Logger.warn(response['msg'])
예제 #21
0
    def getFines() -> None:
        """Мои штрафы"""

        response: dict = User.getFines(functional.wallet)

        if response['status']:
            cli.Logger.info(response['msg'])

            msg: str = f'"ID"{6 * " "}|{8 * " "}"Time"{17 * " "}| "Status"'
            cli.Logger.info(msg, prefix='FINE')

            for fine in response['fines']:
                msg: str = f'{fine[0]}{(10 - len(str(fine[0]))) * " "}| {dt.strftime(dt.fromtimestamp(fine[1]), "%d.%m.%Y %H:%M:%S")}{(30 - len(str(dt.strftime(dt.fromtimestamp(fine[1]), "%d.%m.%Y %H:%M:%S")))) * " "}| {"Оплачено" if fine[2] else "Не оплачено"}'
                cli.Logger.info(msg, prefix='FINE')
        else:
            cli.Logger.warn(response['msg'])
예제 #22
0
    def getInsuranceHistory() -> None:
        """История страховок"""

        response: dict = User.getInsuranceHistory(functional.wallet)

        if response['status']:
            cli.Logger.info(response['msg'])

            msg: str = f'"ID"{6 * " "}|{3 * " "}"Car ID"{3 * " "} | {8 * " "}"Time"{7 * " "} | "Price"'
            cli.Logger.info(msg, prefix='INS')

            for insurance in response['insurance_history']:
                msg: str = f'{insurance[0]}{(9 - len(str(insurance[0]))) * " "} | {insurance[1]}{(14 - len(str(insurance[1]))) * " "}| {insurance[2]}{(21 - len(str(dt.strftime(dt.fromtimestamp(insurance[2]), "%d.%m.%Y %H:%M:%S")))) * " "} | {insurance[3]}'
                cli.Logger.info(msg, prefix='INS')
        else:
            cli.Logger.warn(response['msg'])
예제 #23
0
    def getInsurance(id_car: int) -> None:
        """Информация о страховке конкретного ТС"""

        response: dict = User.getInsurance(functional.wallet, id_car)

        if response['status']:
            cli.Logger.info(response['msg'])

            msg: str = f'"ID"{6 * " "}|{3 * " "}"Car ID"{3 * " "} | {8 * " "}"Time"{7 * " "} | "Price"'
            cli.Logger.info(msg, prefix='FINE')

            insurance: dict = response['insurance_history']
            msg: str = f'{insurance["id"]}{(9 - len(str(insurance["id"]))) * " "} | {insurance["id_car"]}{(14 - len(str(insurance["id_car"]))) * " "}| {insurance["validity"]}{(21 - len(str(dt.strftime(dt.fromtimestamp(insurance["validity"]), "%d.%m.%Y %H:%M:%S")))) * " "} | {insurance["price_insurance"]}'
            cli.Logger.info(msg, prefix='FINE')
        else:
            cli.Logger.warn(response['msg'])
예제 #24
0
    def getCar(id_car: int) -> None:
        """Информация о конкретном ТС"""

        response: dict = User.getCar(functional.wallet, id_car)

        if response['status']:
            cli.Logger.info(response['msg'])

            msg: str = f'"ID"{6 * " "}|{20 * " "}"Model"{20 * " "}| {3 * " "}"Category"{3 * " "} | {7 * " "}"Market price"{7 * " "} |  {7 * " "}"Insurance price"{7 * " "} | Use time'
            cli.Logger.info(msg, prefix='CAR')

            info_car: dict = response['info_car']
            msg: str = f'{info_car["id"]}{(10-len(str(info_car["id"]))) * " "}| {info_car["model"]}{(45 - len(info_car["model"])) * " "} | {info_car["category"]}{(17 - len(info_car["category"])) * " "}| {info_car["market_price"]}{(28 - len(str(info_car["market_price"]))) * " "} | {info_car["insurance_price"]}{(32 - len(str(info_car["insurance_price"]))) * " "} | {info_car["validity"]}'
            cli.Logger.info(msg, prefix='CAR')
        else:
            cli.Logger.warn(response['msg'])
예제 #25
0
def requestInsurance() -> render_template:
    """Узнать смоимость страховки"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'

    if request.method == 'POST':
        wallet: str = session.get('wallet')
        car_id: int = int(request.form['car_id'])

        response: dict = User.requestInsurance(wallet, car_id)
        if response['status']:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   info=True)
        else:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   infoInsurence=True)
예제 #26
0
def login() -> render_template:
    """Авторизация"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'

    if request.method == 'POST':
        wallet: str = request.form['wallet']
        private_key: str = request.form['private_key']

        response = User.logIn(wallet, private_key)
        if response['status']:
            session['islogIn'] = True
            session['wallet'] = wallet
            session['role'] = response['role']
            session['session_role'] = response['role']

            return redirect(lastPage)
        else:
            flash(response['msg'])
    return render_template('html/main.html', lastPage=lastPage, logIn=True)
예제 #27
0
def buyInsurance() -> render_template:
    """Купить страховку"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'

    if request.method == 'POST':
        wallet: str = session.get('wallet')
        car_id: int = int(request.form['car_id'])
        private_key: str = request.form['private_key']

        response: dict = User.buyInsurance(wallet, private_key, car_id)
        if response['status']:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   info=True)
        else:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   addInsurence=True)
예제 #28
0
def payFine() -> render_template:
    """Оплатить штраф"""

    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'

    if request.method == 'POST':
        wallet: str = session.get('wallet')
        id_fine: int = int(request.form['id_fine'])
        private_key: str = request.form['private_key']

        response: dict = User.payFine(wallet, private_key, id_fine)
        if response['status']:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   info=True)
        else:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   payFine=True)
예제 #29
0
def addRiderLicence() -> render_template:
    """Добавить вод.удовст"""
    lastPage: str = session.get('lastPage') if session.get('lastPage') else '/'

    if request.method == 'POST':
        wallet: str = session.get('wallet')
        number: int = int(request.form['number'])
        if 'catA' in request.form:
            catA: bool = True
        else:
            catA: bool = False

        if 'catB' in request.form:
            catB: bool = True
        else:
            catB: bool = False

        if 'catC' in request.form:
            catC: bool = True
        else:
            catC: bool = False

        experience: int = int(request.form['experience'])
        date_: str = request.form['date']
        private_key: str = request.form['private_key']

        date = dt.strptime(date_, '%Y-%d-%m')
        date = int(date.timestamp())
        response = User.addDL(wallet, private_key, experience, number, date,
                              catA, catB, catC)
        if response['status']:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   info=True)
        else:
            flash(response['msg'])
            return render_template('html/main.html',
                                   lastPage=lastPage,
                                   addRiderLicence=True)
예제 #30
0
    def getCars() -> None:
        """Список всех ТС пользователя"""

        response: dict = User.getCars(functional.wallet)
        cat = ''

        if response['status']:
            cli.Logger.info(response['msg'])

            msg: str = f'"ID"{6 * " "}|{20 * " "}"Model"{20 * " "}| {3 * " "}"Category"{3 * " "} | {7 * " "}"Market price"{7 * " "} |  {7 * " "}"Insurance price"{7 * " "} | Use time'
            cli.Logger.info(msg, prefix='CARS')

            for car in response['cars']:
                if car[2] == 0:
                    cat = 'A'
                elif car[2] == 1:
                    cat = 'B'
                elif car[2] == 2:
                    cat = 'C'
                msg: str = f'{car[0]}{(10-len(str(car[0]))) * " "}| {car[2]}{(45 - len(str(car[2]))) * " "} | {cat}{(17 - len(str(cat))) * " "}| {car[3]}{(28 - len(str(car[3]))) * " "} | {car[4]}{(32 - len(str(car[4]))) * " "} | {car[5]}'
                cli.Logger.info(msg, prefix='CARS')
        else:
            cli.Logger.warn(response['msg'])