Пример #1
0
def menu_store():
    form = MenuCreateForm(request.form)
    if form.validate():
        menu = Menu()
        menu.create(data=form.data)
        return Success(message="操作成功!")
    return Fail(message=form.first_error)
Пример #2
0
 def test_add(self):
     m1 = Menu()
     m1.title = '艹'
     m1.name = ''
     session.add(m1)
     if session.commit():
         print('success')
Пример #3
0
 def test_adds(self):
     session.add_all([
         Menu(title='orderManage'),
         Menu(title='vipManage', url='/user1', parent_id=1),
         Menu(title='friend', url='/user2', parent_id=1)
     ])
     session.commit()
Пример #4
0
 def add_route(gid, routes):
     with db.auto_commit():
         Group.get_or_404(id=gid, msg='无指定权限组')
         for route_id in routes:
             Route.get_or_404(id=route_id, msg='无指定路由节点')
             Menu.abort_repeat(group_id=gid, route_id=route_id)
             Menu.create(group_id=gid, route_id=route_id)
Пример #5
0
 def test_adds(self):
     session.add_all([
         Menu(title='订单管理'),
         Menu(title='会员管理', url='/user', parent_id=1),
         Menu(title='派件员', url='/user2', parent_id=1),
         Menu(title='合作商', url='/user3', parent_id=1),
         Menu(title='订单统计', url='/order_cnt', parent_id=2),
     ])
     session.commit()
Пример #6
0
def add_menu():
    form = MenuForm().validate_for_api()
    with db.auto_commit():
        menu = Menu()
        menu.menu_name = form.menu_name.data
        menu.en_name = form.en_name.data
        menu.create_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
        db.session.add(menu)
    return restful_json(menu)
Пример #7
0
    def cover_menus(group_id, routes):
        Menu.query.filter_by(group_id=group_id).delete(
            synchronize_session=False)
        t = RouteTree()
        t.generate_by_dir({'id': 0, 'children': routes})

        with db.auto_commit():
            for route in t.deserialize():
                if route['id'] != 0:
                    Menu.create(group_id=group_id, route_id=route['id'])
Пример #8
0
 def test_add(self):
     # m1 = Menu(title='用户管理')
     # session.add(m1)
     session.add_all([
         Menu(title='订单管理'),
         Menu(title='会员管理', url='/user1', parent_id=1),
         Menu(title='派件员', url='/user2', parent_id=1),
         Menu(title='合作商', url='/user3', parent_id=1),
         Menu(title='订单统计', url='/order_cnt', parent_id=2)
     ])
     session.commit()
Пример #9
0
    def update(self):
        # data retrieve
        list = self.retrieve(url1) + self.retrieve(url2)

        # data storing
        for i in range(len(list) / 4):
            d = self.parseDate(list[i*4])
            menu = Menu(date=d, key_name=str(d))
            menu.menu = [list[i*4+1], list[i*4+2], list[i*4+3]]
            menu.last_update = datetime.datetime.now().date()
            menu.put()
 def setUp(self):
     self.BaseSetUp()
     self.mock_vendor = Vendor(id=1,
                               created_at=datetime.now(),
                               updated_at=datetime.now(),
                               name='Mock vendor',
                               address='Mock address',
                               tel='',
                               contact_person='Mock person',
                               is_active=True,
                               location_id=1)
     self.mock_vendor_engagement = VendorEngagement(
         id=1,
         created_at=datetime.now(),
         updated_at=datetime.now(),
         vendor_id=1,
         location_id=1,
         start_date=datetime.now(),
         end_date=datetime.now(),
         status=1,
         termination_reason='Mock reason',
         vendor=self.mock_vendor)
     self.mock_menu = Menu(is_deleted=False,
                           date=datetime.now(),
                           meal_period='',
                           location_id=1,
                           main_meal_id=1,
                           allowed_side=1,
                           allowed_protein=1,
                           side_items='',
                           protein_items='',
                           vendor_engagement_id=1,
                           created_at=datetime.now(),
                           updated_at=datetime.now())
     self.mock_vendor_engagement = VendorEngagement(
         id=1,
         created_at=datetime.now(),
         updated_at=datetime.now(),
         vendor_id=1,
         location_id=1,
         start_date=datetime.now(),
         end_date=datetime.now(),
         status=1,
         termination_reason='Mock reason',
         vendor=self.mock_vendor,
         menus=[
             self.mock_menu,
         ])
     self.mock_vendor_engagement_no_child = VendorEngagement(
         id=1,
         created_at=datetime.now(),
         updated_at=datetime.now(),
         vendor_id=1,
         location_id=1,
         start_date=datetime.now(),
         end_date=datetime.now(),
         status=1,
         termination_reason='Mock reason',
         vendor=self.mock_vendor)
Пример #11
0
 def new_menu(self, date, meal_period, main_meal_id, allowed_side,
              allowed_protein, side_items, protein_items,
              vendor_engagement_id, location_id):
     date = datetime.strptime(date, '%Y-%m-%d')
     meal_period = meal_period.lower()
     menu = Menu(date=date,
                 meal_period=meal_period,
                 main_meal_id=main_meal_id,
                 allowed_side=allowed_side,
                 allowed_protein=allowed_protein,
                 side_items=','.join(str(item) for item in side_items),
                 protein_items=','.join(
                     str(item) for item in protein_items),
                 vendor_engagement_id=vendor_engagement_id,
                 location_id=location_id)
     menu.save()
     return menu
Пример #12
0
    def delete(id: int):
        route = Route.get_or_404(id=id, msg='路由不存在, 删除失败')
        # 禁止任意删除
        if Menu.get(route_id=id):
            raise Forbidden(msg='存在权限组的菜单绑定路由,不可删除')

        with db.auto_commit():
            route.delete(commit=False)
            Route.query.filter_by(parent_id=id).delete(
                synchronize_session=False)
Пример #13
0
def menu_update(id):
    edit_one_field = request.form.get('edit_one_field', None)
    if not edit_one_field:
        form = MenuEditForm(formdata=request.form, id=id)
    else:
        form = MenuEditOneKeyForm(formdata=request.form, id=id)
    if not form.validate():
        return Fail(message=form.first_error)
    menu = Menu.get_by_id(id=id)
    menu.update(form.data, edit_one_field)

    return Success(message="操作成功!")
Пример #14
0
def create_menu(name, endpoint):
    """
    设置角色
    :param name:
    :param label:
    :return:
    """
    with db.auto_commit():
        menu = Menu()
        menu.name = name
        menu.endpoint = endpoint
        menu.pid = 0
        menu.active = 1
        menu.target = 1
        db.session.add(menu)
    print("成功创建后台导航: %s " % (name, ))
Пример #15
0
    def get(self, type=0):
        # normalize input
        if type == "" or type == None:
            type = 0
        type = int(type)
        if (type < 0 and 2 < type):
            type = 0

        # get menu by JST
        date = (datetime.datetime.now() + datetime.timedelta(hours=+9)).date()
        menu = Menu.get_by_key_name(str(date))

        post = menu.format(date, type)

        # debug output
        self.response.out.write(post)

        # tweet
        config = lib.config.load("config/twitter.yaml")
        try:
            api = twitter.oauth(config['tokens'])
            api.update_status(post)
        except tweepy.TweepError, e:
            logging.info(u"Error while updating; {error}".format(error=e.message))
Пример #16
0
def menu_lists():
    total, result = Menu.get_list_all(is_sort=True)
    return AjaxResponse(data=result, count=total)
Пример #17
0
def menu_create():
    menus = Menu.get_all_for_select(is_group=True)
    return render_template('admin/menu/create.html', menus=menus)
Пример #18
0
    def test_handle_placing_order(self, func_get_unpaginated):
        # LocationFactory.create(name='Lagos')
        with self.app.app_context():
            m_menu = Menu(id=1, main_meal=MealItem(name='Main meal 1'))
            func_get_unpaginated.return_value = [
                m_menu,
            ]
            m_date = date.today().strftime('%Y-%m-%d')
            m_location_id = LocationRepo().get_unpaginated(name='Lagos')[0].id
            m_meal_period = MealSessionRepo().new_meal_session(
                name='lunch',
                start_time=time(hour=12, minute=20, second=0),
                stop_time=time(hour=14, minute=0, second=0),
                location_id=m_location_id,
                date=m_date).name

            m_value = f'{m_meal_period}_{m_date}_menu_{m_location_id}'
            m_payload = {'actions': [{'value': m_value}]}
            bot_controller = BotController(self.request_context)

            # Act
            result = bot_controller.handle_placing_order(m_payload)

            # Assert
            if result.status_code != 200:
                raise AssertionError()
            result_json = result.get_json()
            if 'text' not in result_json:
                raise AssertionError()
            if result_json['text'] != 'Select Main Meal':
                raise AssertionError()
            if 'attachments' not in result_json:
                raise AssertionError()
            if result_json['attachments'] is None:
                raise AssertionError()
            if 'text' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['text'] != '':
                raise AssertionError()
            if 'callback_id' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['callback_id'] != \
                    'meal_action_selector':
                raise AssertionError()
            if 'color' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['color'] != '#3AA3E3':
                raise AssertionError()
            if 'attachment_type' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['attachment_type'] != 'default':
                raise AssertionError()
            if 'actions' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'] is None:
                raise AssertionError()
            if 'name' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['name'] != \
                    'main_meal':
                raise AssertionError()
            if 'type' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['type'] != 'button':
                raise AssertionError()
            if 'text' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['text'] != \
                    'Main meal 1':
                raise AssertionError()
            if 'value' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['value'] != \
                    f'1_{m_value}':
                raise AssertionError()
Пример #19
0
    def test_handle_action_selection(self, func_get_unpaginated, func_get,
                                     func_get_meal_items_by_ids):
        with self.app.app_context():
            # Arrange
            m_menu = Menu(side_items='item 1', protein_items='item 1')
            func_get_unpaginated.return_value = [
                m_menu,
            ]
            func_get.return_value.name = 'Main meal 1'
            func_get_meal_items_by_ids.return_value = [
                'item 1',
            ]
            m_date = date.today().strftime('%Y-%m-%d')
            m_location_id = LocationRepo().get_unpaginated(name='Lagos')[0].id
            m_meal_session = MealSessionRepo().new_meal_session(
                name='lunch',
                start_time=time(hour=12, minute=20, second=0),
                stop_time=time(hour=14, minute=0, second=0),
                location_id=m_location_id,
                date=m_date)

            m_value = f'{m_meal_session.name}_{m_date}_menu_{m_location_id}'
            m_payload = {'actions': [{'value': m_value}]}
            bot_controller = BotController(self.request_context)

            # Act
            result = bot_controller.handle_action_selection(m_payload)

            # Assert
            if result.status_code != 200:
                raise AssertionError()
            result_json = result.get_json()
            if 'text' not in result_json:
                raise AssertionError()
            if result_json['text'] != m_meal_session.name.upper():
                raise AssertionError()
            if 'attachments' not in result_json:
                raise AssertionError()
            if result_json['attachments'] is None:
                raise AssertionError()
            if 'text' not in result_json['attachments'][0]:
                raise AssertionError()
            expected_text = 'Main meal: *Main meal 1*\n ' \
                            'Side items: item 1\n' \
                            'Protein items: item 1\n\n\n'
            if result_json['attachments'][0]['text'] != expected_text:
                raise AssertionError()
            if 'callback_id' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['callback_id'] != \
                    'after_menu_list':
                raise AssertionError()
            if 'color' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['color'] != '#3AA3E3':
                raise AssertionError()
            if 'attachment_type' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['attachment_type'] != 'default':
                raise AssertionError()
            if 'actions' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'] is None:
                raise AssertionError()
            if 'name' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['name'] != \
                    'main meal':
                raise AssertionError()
            if 'text' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['text'] != \
                    'Rate meal':
                raise AssertionError()
            if 'type' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['type'] != \
                    'button':
                raise AssertionError()
            if 'value' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['value'] != \
                    f'{m_meal_session.name}_{m_date}_rate_{m_location_id}_{m_location_id}':
                raise AssertionError()
            if 'name' not in result_json['attachments'][0]['actions'][1]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['name'] != \
                    'main meal':
                raise AssertionError()
            if 'text' not in result_json['attachments'][0]['actions'][1]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][1]['text'] != \
                    'Place an order':
                raise AssertionError()
            if 'type' not in result_json['attachments'][0]['actions'][1]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][1]['type'] != \
                    'button':
                raise AssertionError()
            if 'value' not in result_json['attachments'][0]['actions'][1]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][1]['value'] != \
                    f'{m_meal_session.name}_{m_date}_order_{m_location_id}_{m_location_id}':
                raise AssertionError()
Пример #20
0
def menu_edit(id):
    menu = Menu.get_by_id(id)
    menus = Menu.get_all_except_by_id(id=id, is_sort=True)
    return render_template('admin/menu/edit.html', menu=menu, menus=menus)
Пример #21
0
    def test_add(self):
        m1 = Menu()
        m1.title = '用户管理'

        session.add(m1)
        session.commit()
Пример #22
0
def permission_create():
    menus = Menu.get_all(is_group=True)
    return render_template('admin/permission/create.html', menus=menus)
Пример #23
0
            post = u"RT @{name}: {text}".format(
                    name=status.user.screen_name,
                    text=status.text
                    )
            try:
                self.api.update_status(post)
            except tweepy.TweepError, e:
                logging.info(u"Error while updating status ('{text}'); {error}".format(
                    error=e.message,
                    text=post
                    ))

        elif rep_type == self.REP_TYPE_MENU:
            # parse date
            date, time = self.parse_datetime(status.text)
            menu = Menu.get_by_key_name(str(date))

            if menu:
                post = u"@{name} {menu}".format(
                        name=status.user.screen_name,
                        menu=menu.format(date, time))
                try:
                    self.api.update_status(post,
                            in_reply_to_status_id=status.id
                            )
                except tweepy.TweepError, e:
                    logging.info(u"An tweet error has occurred; text='{text}'; {error}".format(
                        error=e.message,
                        text=post
                        ))
Пример #24
0
def menu_delete(ids):
    ids = ids.split('-')
    menus = Menu.get_all_in_ids(ids=ids)
    for menu in menus:
        menu.destroy()
    return Success(message="成功删除")
Пример #25
0
def permission_edit(id):
    permission = Permission.get_by_id(id)
    menus = Menu.get_all(is_group=True)
    return render_template('admin/permission/edit.html',
                           permission=permission,
                           menus=menus)
Пример #26
0
from app.models.database import DatabaseConnection
# from flask_jwt import JWT, jwt_required
# from app.authentication import authenticate, identity
#app = Flask(__name__)
from app.models.order import Orders
from app.models.menu import Menu
from app.user import User

api = Api(app)
app.secret_key = 'dave'
# jwt = JWT(app, authenticate)
# orders = []

database = DatabaseConnection()
order = Orders()
menu = Menu()
user = User()

database.create_user_table()
database.create_menu_list()
cur = database.cursor
"""
    Handling the order endpoints
"""


#getting all the orders from the database
@app.route('/orders', methods=['GET'])
def get_all_orders():
    response = order.get()
    return jsonify({'orders': response})