def create_menu(self):
        '''
		params are gotten from request object
		:return: json object with status of menu created with menu
		'''
        location_id = Auth.get_location()
        date, meal_period, main_meal_id, allowed_side,\
         allowed_protein, side_items, protein_items,\
         vendor_engagement_id = self.request_params(
          'date', 'mealPeriod', 'mainMealId', 'allowedSide',
          'allowedProtein', 'sideItems', 'proteinItems', 'vendorEngagementId'
         )

        if self.menu_repo.get_unpaginated(date=date,
                                          main_meal_id=main_meal_id,
                                          location_id=location_id):
            return self.handle_response(
                'You can\'t create multiple menus with same main item on the same day',
                status_code=400)
        menu = self.menu_repo.new_menu(date, meal_period, main_meal_id,
                                       allowed_side, allowed_protein,
                                       side_items, protein_items,
                                       vendor_engagement_id,
                                       location_id).serialize()

        menu['mainMeal'] = self.meal_repo.get(main_meal_id).serialize()
        menu['proteinItems'] = self.menu_repo.get_meal_items(protein_items)
        menu['sideItems'] = self.menu_repo.get_meal_items(side_items)
        return self.handle_response('OK',
                                    payload={'menu': menu},
                                    status_code=201)
    def list_menus_range(self, menu_period, menu_start_date, menu_end_date):
        """retrieves a list of menus for a specific date range for a specific meal period.
			date fornat: "YYYY-MM-DD"
			meal period: breakfast or lunch
			menu_start_date: start date of search
			menu_end_date: end date of search
		"""
        location_id = Auth.get_location()
        if MealPeriods.has_value(menu_period):

            menu_start_date = datetime.strptime(menu_start_date, '%Y-%m-%d')
            menu_end_date = datetime.strptime(menu_end_date, '%Y-%m-%d')

            if menu_start_date >= menu_end_date:
                return self.handle_response(
                    'Provide valid date range. start_date cannot be greater than end_date',
                    status_code=400)
            menus = self.menu_repo.get_range_paginated_options(
                start_date=menu_start_date,
                end_date=menu_end_date,
                meal_period=menu_period,
                location_id=location_id)
            menu_list = defaultdict(list)
            for menu in menus.items:
                serialised_menu = menu.serialize()
                arr_protein = [
                    int(prot_id) for prot_id in menu.protein_items.split(',')
                ]
                arr_side = [
                    int(side_id) for side_id in menu.side_items.split(',')
                ]

                serialised_menu['mainMeal'] = self.meal_repo.get(
                    menu.main_meal_id).serialize()
                serialised_menu[
                    'proteinItems'] = self.menu_repo.get_meal_items(
                        arr_protein)
                serialised_menu['sideItems'] = self.menu_repo.get_meal_items(
                    arr_side)
                menu_list[serialised_menu['date'].strftime('%Y-%m-%d')].append(
                    serialised_menu)

            grouped = [{
                'date': date,
                'menus': menus
            } for date, menus in menu_list.items()]

            return self.handle_response('OK',
                                        payload={
                                            'startDateOfSearch':
                                            menu_start_date,
                                            'endDateOfSearch': menu_end_date,
                                            'mealPeriod': menu_period,
                                            'meta':
                                            self.pagination_meta(menus),
                                            'menuList': grouped
                                        })

        return self.handle_response('Provide valid meal period and date range',
                                    status_code=400)
Esempio n. 3
0
def profile():

    if(session.get('username') != None):
        stock_array = Auth.getstocks(session.get('username'))
        return render_template('profile.html', user_name=session.get('username'), stock=stock_array)

    else:
        return redirect(url_for('loginpage'))
 def list_meals(self):
     query_kwargs = self.get_params_dict()
     location_id = Auth.get_location()
     meals = self.meal_repo.get_unpaginated_asc(self.meal_repo._model.name,
                                                is_deleted=False,
                                                location_id=location_id,
                                                **query_kwargs)
     meals_list = [meal.serialize() for meal in meals]
     return self.handle_response('OK', payload={'mealItems': meals_list})
Esempio n. 5
0
def sign():
    username = request.form['user_name']
    userpin = request.form['user_pin']

    userExists = Auth.checkUserExists(username)

    if userExists is True:
        return render_template('signup.html', error=True, error_text="username already exists")

    elif(userpin == ''):
        return render_template('signup.html', error=True, error_text="userpin is required")

    else:
        session['username'] = username
        Auth.authSign(username, userpin)
        Auth.createuserbase(username)
        stock_array = []
        return redirect(url_for('profile'))
 def list_meals_page(self, page_id, meals_per_page):
     location_id = Auth.get_location()
     meals = self.meal_repo.filter_by(page=page_id,
                                      per_page=meals_per_page,
                                      location_id=location_id)
     meals_list = [meal.serialize() for meal in meals.items]
     return self.handle_response('OK',
                                 payload={
                                     'mealItems': meals_list,
                                     'meta': self.pagination_meta(meals)
                                 })
Esempio n. 7
0
def stock(stock_name):

    if(session.get('username') != None):
        print(stock_name)
        CSV.generateCsv(session.get('username'), stock_name)
        gg.graphPlot(session.get('username'), stock_name)
        data = Auth.getStockData(stock_name)
        return render_template('stock_page.html', stock_name=stock_name, stock=stock_name, data=data, user_name=session.get('username'))

    else:
        return redirect(url_for('loginpage'))
    def create_meal(self):
        """
        Creates a new meal item
        """
        location_id = Auth.get_location()
        name, image_url, meal_type = self.request_params('mealName', 'image', 'mealType')
        if self.meal_repo.get_unpaginated(name=name, location_id=location_id):
            return self.handle_response('Meal item with this name already exists', status_code=400)
        if MealTypes.has_value(meal_type):
            new_meal_item = self.meal_repo.new_meal_item(name, image_url, meal_type, location_id).serialize()

            return self.handle_response('OK', payload={'mealItem': new_meal_item}, status_code=201)
        return self.handle_response('Invalid meal type. Must be main, protein or side', status_code=400)
Esempio n. 9
0
def login():
    username = request.form['user_name']
    userpin = request.form['user_pin']

    chechAuth = Auth.authLogin(username, userpin)

    print(chechAuth)

    if chechAuth is True:
        session['username'] = username
        return redirect(url_for('profile'))

    else:
        return render_template('login.html', error=True)
    def list_menus(self, menu_period, menu_date):
        '''retrieves a list of menus for a specific date for a specific meal period.
			date fornat: "YYYY-MM-DD"
			meal period: breakfast or lunch
			menu_date:  date of request
		'''
        location_id = Auth.get_location()
        if MealPeriods.has_value(menu_period):
            menus = self.menu_repo.get_unpaginated(date=menu_date,
                                                   meal_period=menu_period,
                                                   is_deleted=False,
                                                   location_id=location_id)
            menu_list = defaultdict(list)
            for menu in menus:
                serialised_menu = menu.serialize()
                arr_protein = menu.protein_items.split(",")
                arr_side = menu.side_items.split(",")
                serialised_menu['mainMeal'] = self.meal_repo.get(
                    menu.main_meal_id).serialize()
                serialised_menu[
                    'proteinItems'] = self.menu_repo.get_meal_items(
                        arr_protein)
                serialised_menu['sideItems'] = self.menu_repo.get_meal_items(
                    arr_side)
                menu_list[serialised_menu['date'].strftime('%Y-%m-%d')].append(
                    serialised_menu)

            grouped = [{
                'date': date,
                'menus': menus
            } for date, menus in menu_list.items()]
            return self.handle_response('OK',
                                        payload={
                                            'dateOfMeal': menu_date,
                                            'mealPeriod': menu_period,
                                            'menuList': grouped
                                        })

        return self.handle_response('Provide valid meal period and date',
                                    status_code=404)
 def list_meals(self):
     location_id = Auth.get_location()
     meals = self.meal_repo.get_unpaginated(is_deleted=False,
                                            location_id=location_id)
     meals_list = [meal.serialize() for meal in meals]
     return self.handle_response('OK', payload={'mealItems': meals_list})
Esempio n. 12
0
def deletestock():
    stock = request.form['delete_stock']
    print(stock)
    Auth.deletestock(stock, session.get('username'))

    return redirect(url_for('profile'))
Esempio n. 13
0
def addstock():
    stock = request.form['new_stock']
    print(stock)
    Auth.addstock(stock, session.get('username'))

    return redirect(url_for('profile'))