Пример #1
0
 def testClient(self):
     client = Client(2971019052536, "Hanes Camelia-Andreea")
     assert client.getID() == 2971019052536
     assert client.getName() == "Hanes Camelia-Andreea"
     client.setID(1971019052536)
     client.setName("Hanes Andrei")
     assert client.getName() == "Hanes Andrei"
     assert client.getID() == 1971019052536
Пример #2
0
    def init_clients(self):
        '''

        Initializes the repository of clients with 5 default entities.

        '''

        self.repo_clients.add_new_entity(Client(1, "Joshua"))
        self.repo_clients.add_new_entity(Client(2, "Sue"))
        self.repo_clients.add_new_entity(Client(3, "Philip"))
        self.repo_clients.add_new_entity(Client(4, "Josh"))
        self.repo_clients.add_new_entity(Client(5, "Ralph"))
    def add_client(self, id, name):
        # validations
        # if the id is a valid positive integer, then it is converted from str into int
        id = Validator.validate_positive_integer(id)

        # add client
        self.__repo_clients.add_new_entity(Client(id, name))
Пример #4
0
 def clientsMenu(self):
     commands = ["1", "2", "3", "4", "5", "x"]
     cmd = input("Enter your option: ")
     try:
         if cmd not in commands:
             print("Unknown command...")
         elif cmd == "x":
             return
         elif cmd == "1":
             try:
                 id = int(input("Enter the client's id: "))
                 name = input("Enter client's name: ")
                 cl = Client(id, name)
                 self._controller.addClient(cl)
             except ValueError:
                 print("Id must be an integer...")
         elif cmd == "2":
             try:
                 id = int("Enter the id of the client to be removed: ")
                 self._controller.removeClient(id)
             except ValueError:
                 print("Id must be an integer...")
         elif cmd == "3":
             try:
                 id = int(input("Enter client's id: "))
                 newName = input("Enter the new name for this client: ")
                 self._controller.updateClientName(id, newName)
             except ValueError:
                 print("Id must be integer...")
         elif cmd == "4":
             command = input(
                 "Press 1 for searching by ID and 2 for searching by Name \n"
             )
             if command == "1":
                 try:
                     id = int("Give ID: ")
                     print(self._controller.findClientzById(id))
                 except ValueError:
                     print("Id must be integer...")
             elif command == "2":
                 name = input("Enter client's name: ")
                 clients = self._controller.findClientByName(name)
                 for c in clients:
                     print(c.__str__())
             else:
                 print("Unrecognised option...")
         elif cmd == "5":
             clients = self._controller.mostActiveClients()
             for c in clients:
                 print("Client with ID: " + str(c["ID"]) + " and NAME: " +
                       str(c["name"]) + " has " + str(c["days"]) +
                       " days of total rentals.")
     except LibraryException as le:
         print(str(le))
Пример #5
0
 def deepCopy(self, other):
     '''
     Function to deepCopy another LibraryRepository to this (self) one
     ;copies all the data from another Repository to this one with no references of the objects (so that the states do not depend at all)
     params: other: another LibraryRepository
     '''
     self._books = [
         Book(book.getID(), book.getTitle(), book.getDescription(),
              book.getAuthor()) for book in other.getBooks()
     ]
     self._clients = [
         Client(client.getID(), client.getName())
         for client in other.getClients()
     ]
     self._rentals = [
         Rental(rental.getRentalID(), rental.getBookID(),
                rental.getClientId(), rental.getRentedDate(),
                rental.getDueDate(), rental.getReturnedDate())
         for rental in other.getRentals()
     ]
Пример #6
0
Файл: UI.py Проект: hofovea/DB
class UI:
    client = Client()
    menu_type = None

    def __init__(self, client_name):
        self.client.username = client_name
        if self.client.is_admin(client_name):
            self.menu_type = menu_variation.admin_ui
        elif self.client.is_owner(client_name):
            self.menu_type = menu_variation.owner_ui
        elif self.client.is_common_user(client_name):
            self.menu_type = menu_variation.common_ui

    def start(self):
        while True:
            op = prompt(self.menu_type)['operation']
            if op == 'New message':
                message = prompt(menu_variation.input_message)['value']
                receiver = prompt(menu_variation.input_username)['value']
                if self.client.is_exists(receiver):
                    self.client.create_message(message, receiver)
                else:
                    print(
                        'Can`t send message to {}: user does not exist'.format(
                            receiver))
            if op == 'Inbox':
                messages = self.client.get_inbox(self.client.username, 10)
                if messages:
                    message_list = []
                    for hashcode in messages:
                        mess = self.client.get_message(hashcode)
                        message_dict = {
                            'message_str':
                            mess['Sender'] + ' ' + mess['Message'][:8] + '...',
                            'hashcode':
                            hashcode
                        }
                        message_list.append(message_dict)
                    hashcode_new = prompt(
                        menu_variation.choose_message(message_list))['value']
                    print(self.client.get_message(hashcode_new)['Message'])
                    self.client.storage_manager.update_message_status(
                        hashcode_new, 'RECEIVED')
                else:
                    print('No messages')
            if op == 'View rating of spammers':
                spammers = self.client.get_spammers(10)
                for spammer in spammers:
                    print(spammer[0] + ': {} '.format(int(spammer[1])) +
                          'spam messages')
            if op == 'View Online':
                print(self.client.get_online())
            if op == 'Promote to admin':
                username = prompt(menu_variation.input_username)['value']
                if self.client.is_admin(username) or self.client.is_owner(
                        username):
                    print("User {} is already admin".format(username))
                else:
                    self.client.promote_to_admin(username)
            if op == 'Demote to user':
                username = prompt(menu_variation.input_username)['value']
                if self.client.is_common_user(username):
                    print("User {} is already common user".format(username))
                else:
                    self.client.demote_to_user(username)
            if op == 'Quit':
                self.client.disconnect()
                quit()
Пример #7
0
    def read_data_from_repository(self):
        if self.repository_type == "file_based":
            clients = self.repo_clients.read_data_from_file()
            for c in clients:
                c = c.strip()
                c = c.split(";")
                print(c)
                self.repo_clients.add_new_entity(Client(int(c[0]), c[1]))

            movies = self.repo_movies.read_data_from_file()
            for m in movies:
                m = m.strip()
                m = m.split(";")
                self.repo_movies.add_new_entity(Movie(int(m[0]), m[1], m[2], m[3]))

            rentals = self.repo_rentals.read_data_from_file()
            for r in rentals:
                r = r.strip()
                r = r.split(";")

                rented_date = parse(r[3])
                due_date = parse(r[4])
                return_date = parse(r[5])
                self.repo_rentals.add_new_entity(Rental(int(r[0]), int(r[1]), int(r[2]), rented_date.date(), due_date.date(), return_date.date()))
        if self.repository_type == "binary_file_based":
            self.repo_clients.repo = self.repo_clients.read_from_binary_file()
            self.repo_movies.repo = self.repo_movies.read_from_binary_file()
            self.repo_rentals.repo = self.repo_rentals.read_from_binary_file()

        if self.repository_type == "JSON_based":
            clients = self.repo_clients.read_data_from_json()
            for c in clients["clients"]:
                self.repo_clients.add_new_entity(Client(int(c["id"]), c["name"]))

            movies = self.repo_movies.read_data_from_json()
            for m in movies["movies"]:
                self.repo_movies.add_new_entity(Movie(int(m["id"]), m["title"], m["description"], m["genre"]))

            print("adasdasd")
            rentals = self.repo_rentals.read_data_from_json()
            for r in rentals["rentals"]:
                rented_date = parse(r["rented_date"])
                due_date = parse(r["due_date"])
                return_date = parse(r["return_date"])
                self.repo_rentals.add_new_entity(Rental(int(r["id"]), int(r["client_id"]), int(r["movie_id"]), rented_date.date(), due_date.date(), return_date.date()))

        if self.repository_type == "SQL_based":
            clients = self.repo_clients.read_data_from_mysql()
            for c in clients:
                self.repo_clients.add_new_entity(Client(int(c[0]), c[1]))

            movies = self.repo_movies.read_data_from_mysql()
            for m in movies:
                self.repo_movies.add_new_entity(Movie(int(m[0]), m[1], m[2], m[3]))

            rentals = self.repo_rentals.read_data_from_mysql()
            for r in rentals:
                # rented_date = parse(r[3])
                # due_date = parse(r[4])
                # return_date = parse(r[5])
                self.repo_rentals.add_new_entity(Rental(int(r[0]), int(r[1]), int(r[2]), r[3], r[4], r[5]))
    def update_client(self, id, new_id, name):
        id = Validator.validate_positive_integer(id)
        new_id = Validator.validate_positive_integer(new_id)

        self.__repo_clients.update_entity(id, Client(new_id, name))
Пример #9
0
import sys
from Entities.Client import Client
from PyInquirer import prompt
from UI import menu_variation
from UI.UI import UI

client = Client()
username = prompt(menu_variation.input_name)['value']
if client.is_exists(username):
    client.connect(username)
else:
    if len(sys.argv) > 1 and sys.argv[1] == 'owner':
        client.add_owner(username)
    elif len(sys.argv) > 1 and sys.argv[1] == 'admin':
        client.add_admin(username)
    else:
        client.add_user(username)
    client.connect(username)

ui = UI(username)
ui.start()