import re


class Categories(object):
    """
    this class will handle all the functions related to the categories and recipes
    """
    categories = {}
    recipes = {}

    def __init__(self, category_name=None, category_owner=None):
        """constructor to initialize the global variables"""

        self.category_name = category_name
        self.category_owner = category_owner

    def create_category(self, category_name, category_owner):

        regexcategory_name = "[a-zA-Z0-9- .]"

        if re.match(regexcategory_name, category_name):

            if category_name != '' and category_name.strip():

                if category_name not in self.categories.keys():

                        self.categories[category_name] = {'cat_name': category_name,
                                                          'cat_owner': category_owner,
                                                          }
                        return "success"
                return "catname_uniqueness"
            return "null_empty_field"
        return "catname_pattern"

    def view_category(self, category_owner):
        cats = self.categories
        my_category = []
        for category in cats:
            if cats[category]['cat_owner'] == category_owner:
               my_category.append(category)
        return my_category

    def create_recipe(self, recipe_name, category_name, category_owner):

     regexrecipe_name = "[a-zA-Z0-9- .]"

     if re.match(regexrecipe_name, recipe_name):

         if recipe_name != '' and recipe_name.strip():

             if recipe_name not in self.recipes.keys():

                     self.recipes[recipe_name] = {'recipe_name': recipe_name,
                                                  'cat_name': category_name,
                                                  'cat_owner': category_owner,
                                                  }
                     return "success"
             return "recipename_uniqueness"
         return "null_empty_field"
     return "recipename_pattern"


    def view_recipes(self, category_name):
        data = self.recipes
        my_recipes = []
        for recipe in data:
            if data[recipe]['cat_name'] == category_name:
               my_recipes.append(recipe)
        return my_recipes
@@ -2289,16 +2289,951 @@
 eturn my_recipes
+%0A%0A    def edit_category(self,current_name,category_name, category_owner):%0A%0A     regexcategory_name = %22%5Ba-zA-Z0-9- .%5D%22%0A%0A     if re.match(regexcategory_name, category_name):%0A%0A         if category_name != '' and category_name.strip():%0A%0A             if category_name not in self.categories.keys():%0A%0A%0A%0A%0A%0A%0A                return %22success%22%0A             return %22categoryname_uniqueness%22%0A         return %22null_empty_field%22%0A     return %22categoryname_pattern%22%0A%0A%0A    def delete_category(self,current_name):%0A         list_of_categories = self.categories%0A         if list_of_categories%5Bcurrent_name%5D%5B%22cat_name%22%5D == current_name:%0A             del list_of_categories%5Bcurrent_name%5D%0A         return list_of_categories%0A%0A    def delete_recipe(self,current_name):%0A         list_of_recipes = self.recipes%0A         if list_of_recipes%5Bcurrent_name%5D%5B%22recipe_name%22%5D == current_name:%0A             del list_of_recipes%5Bcurrent_name%5D%0A         return list_of_recipes

add edit, delete and update methods and code refactor