Exemple #1
0
def signup_berber_page():
    if request.method == 'GET':
        return render_template("signup_berber.html")
    else:
        person = People()
        person.username = request.form["username"]
        person.name_surname = request.form["name_surname"]
        person.mail = request.form["mail"]
        person.password_hash = hasher.hash(request.form["password"])
        person.gender = request.form["gender"]
        person.age = request.form["age"]
        person.role = "berber"
        people = Peoplemodel()

        if (people.control_exist(person)):
            return render_template("signup_berber.html", message="False")
        else:
            people.save(person)
            berbers = Berbermodel()
            berber = Berber()
            berber.people_id = berbers.get_id(person.username)[0]
            berber.gender_choice = request.form["gender_choice"]
            berber.experience_year = request.form["experience"]
            berber.start_time = request.form["start_time"][:2]
            berber.finish_time = request.form["finish_time"][:2]
            berbers.insert(berber)
            return render_template("signup_berber.html", message="True")

        return redirect(url_for("signup_berber_page"))
Exemple #2
0
def signup_owner_page():
    if request.method == 'GET':
        return render_template("signup_owner.html")
    else:
        person = People()
        person.username = request.form["username"]
        person.name_surname = request.form["name_surname"]
        person.mail = request.form["mail"]
        person.password_hash = hasher.hash(request.form["password"])
        person.gender = request.form["gender"]
        person.age = request.form["age"]
        person.role = "owner"
        people = Peoplemodel()
        if (people.control_exist(person)):
            return render_template("signup_owner.html", message="False")
        else:
            owners = Ownermodel()
            owner = Owner()
            owner.tc_number = request.form["tc_number"]
            owner.serial_number = request.form["serial_number"]
            owner.vol_number = request.form["vol_number"]
            owner.family_order_no = request.form["family_order_no"]
            owner.order_no = request.form["order_no"]
            if (owners.control_exist_tc(owner.tc_number)):
                return render_template(
                    "signup_owner.html",
                    message="The TC Number has been saved already ")
            elif (len(owner.tc_number) != 11):
                return render_template(
                    "signup_owner.html",
                    message="TC Number Length must be 11 digits")
            elif (len(owner.serial_number) != 3):
                return render_template(
                    "signup_owner.html",
                    message="Serial number must be 3 digits")
            elif (len(owner.vol_number) != 3):
                return render_template("signup_owner.html",
                                       message="Vol number must be 3 digits")
            elif (len(owner.family_order_no) != 3):
                return render_template(
                    "signup_owner.html",
                    message="Family order number must be 3 digits")
            elif (len(owner.order_no) != 3):
                return render_template("signup_owner.html",
                                       message="Order number must be 3 digits")
            else:
                people.save(person)
                owner.people_id = owners.get_id(person.username)[0]
                owners.insert(owner)
                #tc kimlik varlığını kontrolü
                return render_template("signup_owner.html", message="True")

        return redirect(url_for("signup_owner_page"))
Exemple #3
0
    def read_from_info_file(self, path_to_file):
        with open(path_to_file, 'r') as f:
            data = f.readlines()
        count_of_people, dates = data[0].split('-')
        count_of_people = int(count_of_people)
        dates = dates.split(' ')
        dates.remove('\n')
        dates = list(map(lambda x: int(x), dates))
        peoples = []

        for i in range(1, count_of_people + 1):
            name, visiting = data[i].split('-')
            people = People(name)
            visiting = visiting.split(' ')
            visiting.remove('\n')
            visiting = list(map(lambda x: bool(int(x)), visiting))
            people.set_visiting(dates, visiting)
            peoples.append(people)
        return peoples, dates
 def read_from_console(self):
     peoples = []
     print('Введите через пробел числа учебных дней в месяце:')
     dates = list(map(lambda x: int(x), input().split(' ')))
     print(dates)
     print("Введите количество людей:")
     n = int(input())
     for i in range(0, n):
         print('Введите имя:')
         name = input()
         people = People(name)
         print(
             'Введите информацию о посещаемости ученика через пробел.'
             ' Введите "0" если ученик отсутствовал в данный день и "1" в ином случае.'
         )
         print(self.join_dates(dates))
         visiting = list(map(lambda x: bool(int(x)), input().split(' ')))
         people.set_visiting(dates, visiting)
         peoples.append(people)
     print('\n'.join(list(map(lambda x: str(x), peoples))))
 def __init__(self, path_to_name, path_to_info):
     self.peoples = []
     self.dates = []
     f = FileReaderWriter()
     try:
         self.peoples, self.dates = f.read_from_info_file(path_to_info)
     except Exception:
         with open(path_to_name, 'r') as file:
             for name in file.readlines():
                 self.peoples.append(People(name[0:len(name) - 1]))
     finally:
         self.read_visiting_data(path_to_info)
Exemple #6
0
def signup_user_page():
    if request.method == 'GET':
        return render_template("signup_user.html", message="")
    else:
        person = People()
        person.username = request.form["username"]
        person.name_surname = request.form["name_surname"]
        person.mail = request.form["mail"]
        person.password_hash = hasher.hash(request.form["password"])
        person.gender = request.form["gender"]
        person.age = request.form["age"]
        person.role = "user"

        people = Peoplemodel()
        if (people.save(person)):
            return render_template("signup_user.html", message="True")
        else:
            return render_template("signup_user.html", message="False")

        return redirect(url_for("signup_user_page"))
Exemple #7
0
def signin():
    if request.method == 'GET':
        return render_template("signin.html", message="")
    else:
        username = request.form["username"]
        password = request.form["password"]
        people = Peoplemodel()

        #Eğer kullanıcı databasede ekli değilse patlar //Düzeltildi
        if (people.control_exist_username(username)):
            person = People()
            person = people.get_all(username)

            if (hasher.verify(password, person.password_hash)):
                login_user(person)
                current_app.config["LOGGED_USERS"][person.username] = person

                return render_template("signin.html",
                                       message="True",
                                       role=people.get_role(username))
            else:
                return render_template("signin.html", message="False")
        else:
            return render_template("signin.html", message="False")
Exemple #8
0
def admin_panel():
    peoples = []
    people = Peoplemodel()
    berbers = Berbermodel()
    owners = Ownermodel()
    peoples = people.get_all_list()
    berber_list = []
    berber_list = berbers.get_all_list()
    owner_list = []
    owner_list = owners.get_all_list()

    if request.method == 'GET':
        if (current_user.role == "admin"):
            return render_template("admin_panel.html",
                                   people=peoples,
                                   berbers=berber_list,
                                   owners=owner_list)
        else:
            return render_template("signin.html", message="admin_error")
    else:
        if request.form["edit"] == "delete":
            form_movie_keys = request.form.getlist("people_keys")
            for i in form_movie_keys:
                for j in peoples:
                    if j.id == int(i) and j.role == "user":
                        people.delete_id(j.id)
                    elif j.id == int(i) and j.role == "berber":
                        berbers.delete_with_people_id(j.id)
                        people.delete_id(j.id)
                    elif j.id == int(i) and j.role == "owner":
                        owners.delete_with_people_id(j.id)
                        people.delete_id(j.id)

        elif "update" in request.form["edit"]:
            for i in peoples:
                x = request.form["edit"].split("_")[0]
                if int(x) == i.id:
                    person = People()
                    person.username = request.form["username"]
                    person.name_surname = request.form["name_surname"]
                    person.mail = request.form["mail"]
                    person.password_hash = hasher.hash(
                        request.form["password"])
                    person.gender = request.form["gender"]
                    person.age = request.form["age"]
                    person.role = "user"
                    person.id = i.id

                    #Validation
                    if len(person.name_surname) > 50 or len(
                            person.username) > 50 or len(person.mail) > 300:
                        return render_template(
                            "update.html",
                            person=i,
                            message="You should check input validations.")

                    if i.role == "user" or i.role == "admin":

                        if (people.update(person)):
                            return render_template("admin_panel.html",
                                                   people=peoples,
                                                   berbers=berber_list,
                                                   owners=owner_list,
                                                   message="True")
                        else:
                            return render_template("admin_panel.html",
                                                   people=peoples,
                                                   berbers=berber_list,
                                                   owners=owner_list,
                                                   message="False")
                    elif i.role == "berber":
                        berbers = Berbermodel()
                        berber = Berber()
                        berber.people_id = i.id
                        berber.gender_choice = request.form["gender_choice"]
                        berber.experience_year = request.form["experience"]
                        berber.start_time = request.form["start_time"][:2]
                        berber.finish_time = request.form["finish_time"][:2]
                        berbers = Berbermodel()
                        people.update(person)
                        berbers.update_berber(berber)
                        return render_template("admin_panel.html",
                                               people=peoples,
                                               berbers=berber_list,
                                               owners=owner_list,
                                               message="True")
                    elif i.role == "owner":
                        owner = Owner()
                        owner.people_id = owners.get_id(person.username)[0]
                        owner.tc_number = request.form["tc_number"]
                        owner.serial_number = request.form["serial_number"]
                        owner.vol_number = request.form["vol_number"]
                        owner.family_order_no = request.form["family_order_no"]
                        owner.order_no = request.form["order_no"]
                        if (owners.control_exist_tc(owner.tc_number)):
                            return render_template("admin_panel.html",
                                                   people=peoples,
                                                   berbers=berber_list,
                                                   owners=owner_list,
                                                   message="False")
                        people.update(person)
                        owners.update_owner(owner)
                        return render_template("admin_panel.html",
                                               people=peoples,
                                               berbers=berber_list,
                                               owners=owner_list,
                                               message="True")

        elif "order_id" in request.form["edit"]:
            peoples = sorted(peoples,
                             key=lambda people: people.id)  # sort by age
            return render_template("admin_panel.html",
                                   people=peoples,
                                   berbers=berber_list,
                                   owners=owner_list)

        elif "order_username" in request.form["edit"]:
            peoples = sorted(peoples,
                             key=lambda people: people.username)  # sort by age
            return render_template("admin_panel.html",
                                   people=peoples,
                                   berbers=berber_list,
                                   owners=owner_list)

        elif "order_role" in request.form["edit"]:
            peoples = sorted(peoples,
                             key=lambda people: people.role)  # sort by age
            return render_template("admin_panel.html",
                                   people=peoples,
                                   berbers=berber_list,
                                   owners=owner_list)

        else:
            for i in peoples:
                if int(request.form["edit"]) == i.id:
                    return render_template("update.html", person=i)

        return redirect(url_for("admin_panel"))