def __init__(self, category_id, recipes, recipe_name, ingredients, directions): Category.__init__(self, '', '', '') self.category_id = category_id if recipes: self.recipe_id = recipes[-1].recipe_id + 1 else: self.recipe_id = 1 self.recipes = recipes self.recipe_name = recipe_name if self.recipe_name: self.recipe_name = ' '.join(self.recipe_name.strip().split()) self.ingredients = ingredients self.directions = directions
class CreateCategoryForm(FlaskForm): """ Enables a user to add a new category (All fields are required) """ category_name = StringField("Category name") def __init__(self, user_id, categories, *args, **kwargs): FlaskForm.__init__(self, *args, **kwargs) self.category = Category(user_id, categories, self.category_name.data) def validate_category_name(self, _): """ Validate category name """ if self.category.validate_category_name() != 'Valid': raise ValidationError( message=self.category.validate_category_name())
def view(self, session, **kwargs): if self.form.validate_on_submit(): category = Category(title=self.form.title.data, description=self.form.description.data, icon=self.form.icon.data) status = DataBaseWorker.add_category(session, category) if status == "ok": return redirect("/") else: return super(CategoryAddController, self).view(form=self.form)
def Main(): # Create country crawler object country = Country() # Create category crawler object category = Category() # Create restaurant crawler object restaurant = Restaurant() # Create review crawler object review = Review() # Crawl list of country country_lst = country.get_coutries() # Crawl list of category category_lst = category.get_categories() yc = yelpcontext() # Create work scope object unit_of_work = ws(yc) # Handle insert category to the database Insert_Category(category_lst, unit_of_work) # Get list category in your database category_lst = unit_of_work.category.get() # Get list restaurant in your database restaurant_lst = unit_of_work.restaurant.get() # Take last restaurant id in your database restaurant_id = sorted(restaurant_lst, key=itemgetter(0), reverse=True)[0][0] + 1 if restaurant_lst else 0 # Handle insert restaurant to your database Insert_Restaurant(country_lst, category_lst, unit_of_work, restaurant, restaurant_id) # Take restaurant list in your database restaurant_lst = unit_of_work.restaurant.get() # Handle insert review to your database Insert_Review(restaurant_lst, unit_of_work, review) yelpcontext.disconnect()
def getProducts(): return Category.get_categories()
def category_by_id(self, category_id): """ Returns instance of Category model corresponding to the category of given `category_id`. """ return Category(self.conn, category_id)
def test_category_instance(self): category = Category('test name', 'test descirption') assert isinstance(category, Category) assert isinstance(category, BaseModel)
def test_description_too_big(self): try: Category('test name' * 100, 'test description') raise NotImplementedError('Not implemented error') except Exception as error: assert isinstance(error, ValueError)
def test_description_isinstance_str(self): try: Category('test name', None) raise NotImplementedError('Not implemented error') except Exception as error: assert isinstance(error, TypeError)
def test_name_blank_spaces(self): try: Category(' ', 'test description') raise NotImplementedError('Not implemented error') except Exception as error: assert isinstance(error, ValueError)
def get_categories(self): return Category.get_categories()
def __init__(self, user_id, categories, *args, **kwargs): FlaskForm.__init__(self, *args, **kwargs) self.category = Category(user_id, categories, self.category_name.data)