Пример #1
0
    def update(self):
        if request.is_xhr:
            status = "NOK"
            ret_id = 0
            if admin_per.require().can():
                form = MenuViewForm(request.form)

                myChoices = [('0', '...')] + [(str(page.id), page.translations[get_locale()].title) for page in
                                              Pages.query.order_by(Pages.updated_on.desc()).all()]
                form.page_view.choices = myChoices

                if form.validate():
                    res = update_node(request.form['node_id'], request.form['page_view'])
                    if res is not None:
                        ret_id = request.form['node_id']
                        status = "OK"
                else:
                    data = []
                    for field, errors in form.errors.items():
                        for error in errors:
                            data.append((getattr(form, field).label.text, error))

                    status = data
            return jsonify({'status': status, 'id': ret_id})

        else:
            # redirect to home
            return redirect(url_for('.index'))
Пример #2
0
    def update(self):
        if request.is_xhr:
            status = "NOK"
            ret_id = 0
            if admin_per.require().can():
                form = MenuViewForm(request.form)

                myChoices = [('0', '...')] + [
                    (str(page.id), page.translations[get_locale()].title)
                    for page in Pages.query.order_by(
                        Pages.updated_on.desc()).all()
                ]
                form.page_view.choices = myChoices

                if form.validate():
                    res = update_node(request.form['node_id'],
                                      request.form['page_view'])
                    if res is not None:
                        ret_id = request.form['node_id']
                        status = "OK"
                else:
                    data = []
                    for field, errors in form.errors.items():
                        for error in errors:
                            data.append((getattr(form,
                                                 field).label.text, error))

                    status = data
            return jsonify({'status': status, 'id': ret_id})

        else:
            # redirect to home
            return redirect(url_for('.index'))
Пример #3
0
    def index(self):
        if not login.current_user.is_authenticated():
            return redirect(url_for('users.login'))

        form = MenuViewForm()

        # myChoices = [ ('' , '...') ]
        # for page in Pages.query.order_by(Pages.updated_on.desc()).all():
        #     myChoices.append( (page.translations[page.get_locale()].title , page.translations[get_locale()].title) )

        myChoices = [(0, '...')] + [(page.id, page.translations[get_locale()].title) for page in
                                    Pages.query.order_by(Pages.updated_on.desc()).all()]
        form.page_view.choices = myChoices

        self._template_args['menu'] = get_menu()
        self._template_args['menu_view'] = form
        # print get_menu()
        return self.render('admin/menu.html')
Пример #4
0
    def index(self):
        if not login.current_user.is_authenticated():
            return redirect(url_for('users.login'))

        form = MenuViewForm()

        # myChoices = [ ('' , '...') ]
        # for page in Pages.query.order_by(Pages.updated_on.desc()).all():
        #     myChoices.append( (page.translations[page.get_locale()].title , page.translations[get_locale()].title) )

        myChoices = [(0, '...')] + [
            (page.id, page.translations[get_locale()].title)
            for page in Pages.query.order_by(Pages.updated_on.desc()).all()
        ]
        form.page_view.choices = myChoices

        self._template_args['menu'] = get_menu()
        self._template_args['menu_view'] = form
        # print get_menu()
        return self.render('admin/menu.html')
Пример #5
0
def create_node(parent, text, type):
    try:
        # options(joinedload_all("children", "children", "children", "children")).
        parent = db.session.query(MenuItemsNode).filter(MenuItemsNode.id == parent).first()
        node = MenuItemsNode(parent=parent, type=type)
        # think of a different solution how to extract node.id
        db.session.commit()

        node.text = text + str(node.id)
        if get_locale() is not node.get_locale():
            node.translations[node.get_locale()].text = text + str(node.id)

        # parent.append(node)
        # parent.children[text + str(node.id)] = node
        db.session.commit()
        res = node.id
    except Exception as e:
        import logging

        logging.error(e)
        res = None

    return res
Пример #6
0
def create_node(parent, text, type):
    try:
        # options(joinedload_all("children", "children", "children", "children")).
        parent = db.session.query(MenuItemsNode).filter(
            MenuItemsNode.id == parent).first()
        node = MenuItemsNode(parent=parent, type=type)
        # think of a different solution how to extract node.id
        db.session.commit()

        node.text = text + str(node.id)
        if get_locale() is not node.get_locale():
            node.translations[node.get_locale()].text = text + str(node.id)

        # parent.append(node)
        # parent.children[text + str(node.id)] = node
        db.session.commit()
        res = node.id
    except Exception as e:
        import logging
        logging.error(e)
        res = None

    return res