Ejemplo n.º 1
0
def category_edit(id, cat_type):
    set_menu(cat_type)
    lang = get_admin_lang()
    category = Category.query.filter_by(category_id=id, lang=lang).first()
    if not category and lang != 'en':
        category = Category.query.filter_by(category_id=id, lang='en').first()
        if not category:
            abort(404)
        return category_trans(id, cat_type)
    if not category:
        abort(404)
    if lang != 'en':
        trans = Category.query.filter_by(category_id=category.category_id,
                                         lang='en').first()
    else:
        trans = {}
    if request.method == 'POST':
        category.title = request.form['title']
        category.description = request.form['description']
        db.session.add(category)
        # Update locked fields
        if lang == 'en':
            locked = {
                'active': get_bool('active'),
                'order': get_int('order', 99),
            }
            Category.query.filter_by(
                category_id=category.category_id
            ).update(locked)
        db.session.commit()
        return redirect(url_for_admin('category_list', cat_type=cat_type))
    translations = get_cat_trans(category.category_id)
    return render_template('admin/category_edit.html', category=category,
                           trans=trans, cat_type=cat_type,
                           translations=translations)
Ejemplo n.º 2
0
def menu_edit(id):
    set_menu()
    lang = get_admin_lang()
    menu_item = MenuItem.query.filter_by(menu_id=id, lang=lang).first()
    if not menu_item and lang != 'en':
        menu_item = MenuItem.query.filter_by(menu_id=id, lang='en').first()
        if not menu_item:
            abort(404)
    if not menu_item:
        abort(404)
    if request.method == 'POST' and 'title' in request.form:
        if menu_item.lang != lang:
            menu_item = reedit(menu_item)
        menu_item.title = request.form['title']
        db.session.add(menu_item)
        db.session.commit()
        # Update locked fields
        if lang == 'en':
            locked = {
                'active': get_bool('active'),
                'private': get_bool('private'),
                'item': get_str('item'),
                'order': get_int('order', 99),
            }
            MenuItem.query.filter_by(
                menu_id=id
            ).update(locked)
        db.session.commit()
        return redirect(url_for_admin('menu_list'))
    if lang != 'en':
        trans = MenuItem.query.filter_by(menu_id=menu_item.menu_id,
                                         lang='en').first()
    else:
        trans = {}
    translations = get_trans(id)
    options = []
    if lang == 'en':
        options = [
            {'value': 'orgs', 'name': 'Special: Organisation search'},
            {'value': 'res', 'name': 'Special: Resources'},
        ]

        menu_items = db.session.query(Cms.url, Cms.title).filter_by(
            lang='en', active=True, status='publish'
        )
        for i in menu_items:
            options.append({'value': i.url, 'name': 'Page: %s ~ %s'
                            % (i.title, i.url)})
    elif menu_item.lang == 'en':
        menu_item = MenuItem()
    return render_template('admin/menu_edit.html', menuitem=menu_item,
                           trans=trans, options=options,
                           translations=translations)
Ejemplo n.º 3
0
def code_edit(id, cat_type):
    set_menu(cat_type)
    lang = get_admin_lang()
    code = Code.query.filter_by(code_id=id, lang=lang).first()
    if not code and lang != 'en':
        code = Code.query.filter_by(code_id=id, lang='en').first()
        if not code:
            abort(404)
        return code_trans(id, cat_type)
    if not code:
        abort(404)
    if request.method == 'POST':
        code.title = request.form['title']
        code.description = request.form['description']
        db.session.add(code)
        if lang == 'en':
            locked = {
                'active': get_bool('active'),
                'order': get_int('order', 99),
            }
            Code.query.filter_by(code_id=code.code_id).update(locked)
        db.session.commit()
        return redirect(url_for_admin('category_list', cat_type=cat_type))

    if lang != 'en':
        trans = Code.query.filter_by(code_id=code.code_id, lang='en').first()
    else:
        trans = {}
    cats = Category.query.filter_by(lang='en', current=True)
    categories = []
    for cat in cats:
        categories.append({'name': cat.title, 'value': cat.category_id})

    translations = get_code_trans(code.code_id)
    return render_template('admin/code_edit.html', code=code, trans=trans,
                           categories=categories, cat_type=cat_type,
                           translations=translations)