def category(parent_id=ROOT_CAT_ID):
    ''' This will render the main page with the selected category defined by parent_id, and with the
    content that it contains  '''
    contents = get_images_for_category(parent_id)
    if request.is_xhr:
        categories = [c.jsond() for c in CategoryModel.all().filter('parent_id', parent_id).filter('visible', True)]
        categories = sorted(categories, key=lambda c: c.order)
        return jsonify(categories=categories, contents=contents)
    else:
        category = CategoryModel.get_by_id(parent_id)
        path = None
        if category:
            path = category.get_path_ids_to_root() + [category.key().id()]
        categories = []
        for cat in CategoryModel.all().filter('parent_id', ROOT_CAT_ID).filter('visible', True):
            if path is not None and cat.key().id() in path:
                init_sub_tree_along_path(cat, path)
            categories += [cat]
            pass
        pass
        categories = sorted(categories, key=lambda c: c.order)
        contents = sorted(contents, key=lambda c: c['order'])
        return render_template('category/index.html', categories=categories, contents=contents,
                               current_category=category)
    pass
def admin_categories(parent_id=ROOT_CAT_ID):
    """List all categories"""
    form = CategoryForm(prefix='category')
    if form.validate_on_submit():
        if len(form.key_id.data) > 0 and long(form.key_id.data) > 0:
            category = CategoryModel.get_by_id(long(form.key_id.data)); 
        else:
            category = CategoryModel()
        v2m(form, category)
        try:
            category.put()
            category_id = category.key().id()
            flash(u'Category %s successfully saved.' % category_id, 'success')
            return redirect(url_for('admin_category', parent_id=category.parent_id))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'info')
            return redirect(url_for('admin_category', parent_id=category.parent_id))
        except CircularCategoryException as cce:
            flash(cce.message, 'error')
            return redirect(url_for('admin_category', parent_id=category.parent_id))
        pass
    elif form.is_submitted():
        parent_id = long(form.parent_id.data)
    (categories, category_path, all_categories) = CategoryModel.get_categories_info(parent_id)
    form.parent_id.data = category_path[-1].key().id()
    reset_category = CategoryModel()
    reset_category.parent_id = parent_id
    return render_template('category/admin_categories.html',
                           categories=categories, form=form,
                           category_path=category_path,
                           current_category=category_path[-1],
                           all_categories=all_categories,
                           reset_category=reset_category)
Exemple #3
0
def category(parent_id=ROOT_CAT_ID):
    ''' This will render the main page with the selected category defined by parent_id, and with the
    content that it contains  '''
    contents = get_images_for_category(parent_id)
    if request.is_xhr:
        categories = [
            c.jsond() for c in CategoryModel.all().filter(
                'parent_id', parent_id).filter('visible', True)
        ]
        categories = sorted(categories, key=lambda c: c.order)
        return jsonify(categories=categories, contents=contents)
    else:
        category = CategoryModel.get_by_id(parent_id)
        path = None
        if category:
            path = category.get_path_ids_to_root() + [category.key().id()]
        categories = []
        for cat in CategoryModel.all().filter('parent_id', ROOT_CAT_ID).filter(
                'visible', True):
            if path is not None and cat.key().id() in path:
                init_sub_tree_along_path(cat, path)
            categories += [cat]
            pass
        pass
        categories = sorted(categories, key=lambda c: c.order)
        contents = sorted(contents, key=lambda c: c['order'])
        return render_template('category/index.html',
                               categories=categories,
                               contents=contents,
                               current_category=category)
    pass
def delete_category(category_id):
    """Delete an category object"""
    category = CategoryModel.get_by_id(category_id)
    parent_id = category.parent_id
    try:
        category.delete()
        flash(u'Category %s successfully deleted.' % category_id, 'success')
    except CapabilityDisabledError:
        flash(u'App Engine Datastore is currently in read-only mode.', 'info')
    return redirect(url_for('admin_category', parent_id=parent_id))
def move_category(category_id, parent_id=ROOT_CAT_ID):
    cat = CategoryModel.get_by_id(category_id)
    cat.parent_id = parent_id
    try:
        cat.put()
    except CircularCategoryException as cce:
        flash(cce.message, 'error')
        return redirect(url_for('admin_category', parent_id=parent_id))
    return redirect(url_for('admin_category', parent_id=parent_id), 302);
    pass
Exemple #6
0
def delete_category(category_id):
    """Delete an category object"""
    category = CategoryModel.get_by_id(category_id)
    parent_id = category.parent_id
    try:
        category.delete()
        flash(u'Category %s successfully deleted.' % category_id, 'success')
    except CapabilityDisabledError:
        flash(u'App Engine Datastore is currently in read-only mode.', 'info')
    return redirect(url_for('admin_category', parent_id=parent_id))
Exemple #7
0
def move_category(category_id, parent_id=ROOT_CAT_ID):
    cat = CategoryModel.get_by_id(category_id)
    cat.parent_id = parent_id
    try:
        cat.put()
    except CircularCategoryException as cce:
        flash(cce.message, 'error')
        return redirect(url_for('admin_category', parent_id=parent_id))
    return redirect(url_for('admin_category', parent_id=parent_id), 302)
    pass
Exemple #8
0
def admin_categories(parent_id=ROOT_CAT_ID):
    """List all categories"""
    form = CategoryForm(prefix='category')
    if form.validate_on_submit():
        if len(form.key_id.data) > 0 and long(form.key_id.data) > 0:
            category = CategoryModel.get_by_id(long(form.key_id.data))
        else:
            category = CategoryModel()
        v2m(form, category)
        try:
            category.put()
            category_id = category.key().id()
            flash(u'Category %s successfully saved.' % category_id, 'success')
            return redirect(
                url_for('admin_category', parent_id=category.parent_id))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.',
                  'info')
            return redirect(
                url_for('admin_category', parent_id=category.parent_id))
        except CircularCategoryException as cce:
            flash(cce.message, 'error')
            return redirect(
                url_for('admin_category', parent_id=category.parent_id))
        pass
    elif form.is_submitted():
        parent_id = long(form.parent_id.data)
    (categories, category_path,
     all_categories) = CategoryModel.get_categories_info(parent_id)
    form.parent_id.data = category_path[-1].key().id()
    reset_category = CategoryModel()
    reset_category.parent_id = parent_id
    return render_template('category/admin_categories.html',
                           categories=categories,
                           form=form,
                           category_path=category_path,
                           current_category=category_path[-1],
                           all_categories=all_categories,
                           reset_category=reset_category)