Beispiel #1
0
	def db_del_recipe(self, event):
		"""
		Handles the deletion of the recipe from the actual databaes

		:return: returns nothing
		"""
		recipe_name = self.area1.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')

		recipe_to_add = None

		if (recipe_name == "" or
			db_func.row_exists(self.db, recipe_name, "recipes") is False):
			self.clean()

			self.columnconfigure(0, pad = 3, weight = 1)
			self.rowconfigure(0, pad = 3, weight = 1)
			self.rowconfigure(1, pad = 3, weight = 1)

			label = tk.Label(self, text =
				"Error: Recipe not found",
				font = ("Arial", 20), bg = "white")
			label.grid(row = 0, column = 0)
	
			back = ttk.Button(self, text = "Back",
				style = "Slate.TButton")
			back.grid(row = 1, column = 0,
				sticky = tk.N + tk.S + tk.E + tk.W)

			back.bind("<1>", self.main_menu)

		else:
			self.clean()

			cursor = self.db.cursor()
			cursor.execute("select rowid from recipes where name = ?",
				(str(recipe_name),))
		
			reid = cursor.fetchone()[0]

			recipe_to_del = table_objects.recipe(reid,
				recipe_name, "notimportant", "notimportant")

			db_func.del_recipe_row(self.db, recipe_to_del)

			self.columnconfigure(0, pad = 3, weight = 1)
			self.rowconfigure(0, pad = 3, weight = 1)
			self.rowconfigure(1, pad = 3, weight = 1)

			label = tk.Label(self, text = "Success!",
				font = ("Arial", 20), bg = "white")
			label.grid(row = 0, column = 0)
	
			back = ttk.Button(self, text = "Back",
				style = "Slate.TButton")
			back.grid(row = 1, column = 0,
				sticky = tk.N + tk.S + tk.E + tk.W)
	
			back.bind("<1>", self.main_menu)
	
		self.pack()
Beispiel #2
0
	def test_table_object_recipe(self):
		x = table_objects.recipe(1, "a", "b", 1)
		
		self.assertEqual(x.get_id() == 1, True)
		self.assertEqual(x.get_name() == "a", True)
		self.assertEqual(x.get_instructions() == "b", True)
		self.assertEqual(x.get_time() == 1, True)

		x.set_id(2)
		self.assertEqual(x.get_id() == 2, True)
		x.set_name("b")
		self.assertEqual(x.get_name() == "b", True)
		x.set_instructions("a")
		self.assertEqual(x.get_instructions() == "a", True)
		x.set_time(2)
		self.assertEqual(x.get_time() == 2, True)
Beispiel #3
0
    def test_table_object_recipe(self):
        x = table_objects.recipe(1, "a", "b", 1)

        self.assertEqual(x.get_id() == 1, True)
        self.assertEqual(x.get_name() == "a", True)
        self.assertEqual(x.get_instructions() == "b", True)
        self.assertEqual(x.get_time() == 1, True)

        x.set_id(2)
        self.assertEqual(x.get_id() == 2, True)
        x.set_name("b")
        self.assertEqual(x.get_name() == "b", True)
        x.set_instructions("a")
        self.assertEqual(x.get_instructions() == "a", True)
        x.set_time(2)
        self.assertEqual(x.get_time() == 2, True)
Beispiel #4
0
    def db_del_recipe(self, event):
        """
		Handles the deletion of the recipe from the actual databaes

		:return: returns nothing
		"""
        recipe_name = self.area1.get("1.0", 'end-1c').lower().encode(
            'ascii', 'ignore')

        recipe_to_add = None

        if (recipe_name == "" or
                db_func.row_exists(self.db, recipe_name, "recipes") is False):
            self.clean()

            self.columnconfigure(0, pad=3, weight=1)
            self.rowconfigure(0, pad=3, weight=1)
            self.rowconfigure(1, pad=3, weight=1)

            label = tk.Label(self,
                             text="Error: Recipe not found",
                             font=("Arial", 20),
                             bg="white")
            label.grid(row=0, column=0)

            back = ttk.Button(self, text="Back", style="Slate.TButton")
            back.grid(row=1, column=0, sticky=tk.N + tk.S + tk.E + tk.W)

            back.bind("<1>", self.main_menu)

        else:
            self.clean()

            cursor = self.db.cursor()
            cursor.execute("select rowid from recipes where name = ?",
                           (str(recipe_name), ))

            reid = cursor.fetchone()[0]

            recipe_to_del = table_objects.recipe(reid, recipe_name,
                                                 "notimportant",
                                                 "notimportant")

            db_func.del_recipe_row(self.db, recipe_to_del)

            self.columnconfigure(0, pad=3, weight=1)
            self.rowconfigure(0, pad=3, weight=1)
            self.rowconfigure(1, pad=3, weight=1)

            label = tk.Label(self,
                             text="Success!",
                             font=("Arial", 20),
                             bg="white")
            label.grid(row=0, column=0)

            back = ttk.Button(self, text="Back", style="Slate.TButton")
            back.grid(row=1, column=0, sticky=tk.N + tk.S + tk.E + tk.W)

            back.bind("<1>", self.main_menu)

        self.pack()
Beispiel #5
0
    def db_add_recipe(self, event):
        """
		Handles adding recipe to the database		

		:return: returns nothing
		"""
        cheese_name = self.area1.get("1.0", 'end-1c').lower().encode(
            'ascii', 'ignore')
        recipe_name = self.area2.get("1.0", 'end-1c').lower().encode(
            'ascii', 'ignore')
        time = self.area3.get("1.0",
                              'end-1c').lower().encode('ascii', 'ignore')
        instructions = self.area4.get("1.0", 'end-1c').lower().encode(
            'ascii', 'ignore')

        self.columnconfigure(0, pad=3, weight=1)
        self.rowconfigure(0, pad=3, weight=1)
        self.rowconfigure(1, pad=3, weight=1)

        if (cheese_name == "" or recipe_name == ""):
            self.clean()

            label = tk.Label(self,
                             text="Error: A name field was left blank",
                             font=("Arial", 20),
                             bg="white")
            label.grid(row=0, column=0)

            back = ttk.Button(self, text="Back", style="Slate.TButton")
            back.grid(row=1, column=0, sticky=tk.N + tk.S + tk.E + tk.W)

            back.bind("<1>", self.main_menu)
        elif (db_func.row_exists(self.db, cheese_name, "cheeses") is False
              or db_func.row_exists(self.db, recipe_name, "recipes") is True):
            self.clean()

            label = tk.Label(self, text =
             "Error: Cheese doesn't exist in database, "\
             "or recipe already exists",
             font = ("Arial", 16), bg = "white")
            label.grid(row=0, column=0)

            back = ttk.Button(self, text="Back", style="Slate.TButton")
            back.grid(row=1, column=0, sticky=tk.N + tk.S + tk.E + tk.W)

            back.bind("<1>", self.main_menu)
        else:
            cheese_to_add = table_objects.cheese(-1, cheese_name,
                                                 "notimportant")
            db_func.add_cheese_row(self.db, cheese_to_add)

            recipe_to_add = table_objects.recipe(-1, recipe_name, instructions,
                                                 time)
            db_func.add_recipe_row(self.db, recipe_to_add)

            db_func.connect_cheese_recipe(self.db, cheese_to_add,
                                          recipe_to_add)

            self.clean()

            label = tk.Label(self,
                             text="Success!",
                             font=("Arial", 20),
                             bg="white")
            label.grid(row=0, column=0)

            back = ttk.Button(self, text="Back", style="Slate.TButton")
            back.grid(row=1, column=0, sticky=tk.N + tk.S + tk.E + tk.W)

            back.bind("<1>", self.main_menu)

        self.pack()
Beispiel #6
0
	def db_add_recipe(self, event):
		"""
		Handles adding recipe to the database		

		:return: returns nothing
		"""
		cheese_name = self.area1.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')
		recipe_name = self.area2.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')
		time = self.area3.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')
		instructions = self.area4.get("1.0", 'end-1c').lower().encode('ascii', 'ignore')

		self.columnconfigure(0, pad = 3, weight = 1)
		self.rowconfigure(0, pad = 3, weight = 1)
		self.rowconfigure(1, pad = 3, weight = 1)

		if (cheese_name == "" or recipe_name == ""):
			self.clean()

			label = tk.Label(self, text =
				"Error: A name field was left blank",
				font = ("Arial", 20), bg = "white")
			label.grid(row = 0, column = 0)

			back = ttk.Button(self, text = "Back",
				style = "Slate.TButton")
			back.grid(row = 1, column = 0,
				sticky = tk.N + tk.S + tk.E + tk.W)

			back.bind("<1>", self.main_menu)
		elif (db_func.row_exists(self.db, cheese_name, "cheeses") is False or
			db_func.row_exists(self.db, recipe_name, "recipes") is True):
			self.clean()

			label = tk.Label(self, text = 
				"Error: Cheese doesn't exist in database, "\
				"or recipe already exists",
				font = ("Arial", 16), bg = "white")
			label.grid(row = 0, column = 0)

			back = ttk.Button(self, text = "Back",
				style = "Slate.TButton")
			back.grid(row = 1, column = 0,
				sticky = tk.N + tk.S + tk.E + tk.W)

			back.bind("<1>", self.main_menu)
		else:
			cheese_to_add = table_objects.cheese(-1,
				cheese_name, "notimportant")
			db_func.add_cheese_row(self.db, cheese_to_add)

			recipe_to_add = table_objects.recipe(-1,
				recipe_name, instructions, time)
			db_func.add_recipe_row(self.db,
				recipe_to_add)

			db_func.connect_cheese_recipe(self.db,
				cheese_to_add, recipe_to_add)

			self.clean()

			label = tk.Label(self, text = "Success!",
				font = ("Arial", 20), bg = "white")
			label.grid(row = 0, column = 0)

			back = ttk.Button(self, text = "Back",
				style = "Slate.TButton")
			back.grid(row = 1, column = 0,
				sticky = tk.N + tk.S + tk.E + tk.W)

			back.bind("<1>", self.main_menu)

		self.pack()