def entries(mode, page_number):
    try:
        mode = get_specific_item(config.modes, "route", mode)
    except ValueError:
        return "invalid page"

    if not mode.get('enabled'):
        return "This mode is disabled"

    pagination = None
    mode_entries = None

    # todo: Choose if ajax_enabled and infinite_scroll_enabled configs are for each separate modes or globals
    ajax_enabled = config.ajax_enabled
    infinite_scroll_enabled = config.infinite_scroll_enabled

    if ajax_enabled and page_number is None:
        no_layout = False
    else:
        if ajax_enabled:
            no_layout = True
        else:  # AJAX is disabled
            no_layout = False
            infinite_scroll_enabled = False

    if page_number is None:
        page_number = 1

    db = get_db()

    cur = db.cursor()
    cur.execute('select count(id) from ' + mode.get("route"))
    count = cur.fetchone()[0]

    pagination = Pagination(page_number, config.pagination_entry_per_page,
                            count)

    cur = db.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
    cur.execute(
        'select id, title, text from %s order by id desc limit %d offset %d' %
        (mode.get('route'), config.pagination_entry_per_page,
         (pagination.page - 1) * config.pagination_entry_per_page))
    mode_entries = cur.fetchall()

    if not mode_entries and page_number != 1:
        abort(404)

    print(mode_entries)

    return render_template('modes/' + mode.get('route') + '.html',
                           pagination=pagination,
                           entries=mode_entries,
                           title=mode.get('name'),
                           mode=mode.get('route'),
                           config=config,
                           ajaxOn=ajax_enabled,
                           infiniteScrollOn=infinite_scroll_enabled,
                           noLayout=no_layout)
def get_mode(mode):
    db = get_db()
    for tmp_mode in config.modes:
        cur = db.cursor()
        cur.execute('select count(*) from ' + tmp_mode.get("route"))
        count = cur.fetchone()[0]
        tmp_mode.__setitem__('count', count)

    mode = get_specific_item(config.modes, "route", mode)

    return render_template("admin/modes.html", mode=mode, in_admin=True)
Example #3
0
def get_mode(mode):
    db = get_db()
    for tmp_mode in config.modes:
        cur = db.execute('select count(id) from ' + tmp_mode.get("route"))
        count = cur.fetchone()
        tmp_mode.__setitem__('count', count[0])

    mode = get_specific_item(config.modes, "route", mode)

    return render_template(
        "admin/modes.html",
        mode=mode,
        in_admin=True
    )
def entry(mode, mode_id):
    try:
        mode = get_specific_item(config.modes, "route", mode)
    except ValueError:
        return "invalid page"

    if not mode.get('enabled'):
        return "This mode is disabled"

    db = get_db()
    cur = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cur.execute('select id, title, text from ' + mode.get('route') +
                ' where id = ' + str(mode_id))
    mode_entry = cur.fetchall()

    if not mode_entry:
        abort(404)

    return render_template('modes/' + mode.get('route') + '.html',
                           entries=mode_entry,
                           title=mode.get('name'))
Example #5
0
def entry(mode, mode_id):
    try:
        mode = get_specific_item(config.modes, "route", mode)
    except ValueError:
        return "invalid page"

    if not mode.get('enabled'):
        return "This mode is disabled"

    db = get_db()
    cur = db.execute('select id, title, text from ' + mode.get('route') + ' where id = ' + str(mode_id))
    mode_entry = cur.fetchall()

    if not mode_entry:
        abort(404)

    return render_template(
        'modes/' + mode.get('route') + '.html',
        entries=mode_entry,
        title=mode.get('name')
    )
Example #6
0
def entries(mode, page_number):
    try:
        mode = get_specific_item(config.modes, "route", mode)
    except ValueError:
        return "invalid page"

    if not mode.get('enabled'):
        return "This mode is disabled"

    pagination = None
    mode_entries = None

    # todo: Choose if ajax_enabled and infinite_scroll_enabled configs are for each separate modes or globals
    ajax_enabled = config.ajax_enabled
    infinite_scroll_enabled = config.infinite_scroll_enabled

    if ajax_enabled and page_number is None:
        no_layout = False
    else:
        if ajax_enabled:
            no_layout = True
        else:  # AJAX is disabled
            no_layout = False
            infinite_scroll_enabled = False

    if page_number is None:
        page_number = 1

    db = get_db()

    cur = db.cursor()
    cur.execute('select count(id) from ' + mode.get("route"))
    count = cur.fetchone()[0]

    pagination = Pagination(
        page_number,
        config.pagination_entry_per_page,
        count
    )

    cur = db.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
    cur.execute(
        'select id, title, text from %s order by id desc limit %d offset %d' % (
            mode.get('route'),
            config.pagination_entry_per_page,
            (pagination.page - 1) * config.pagination_entry_per_page
        )
    )
    mode_entries = cur.fetchall()

    if not mode_entries and page_number != 1:
        abort(404)

    print (mode_entries)

    return render_template(
        'modes/' + mode.get('route') + '.html',
        pagination=pagination,
        entries=mode_entries,
        title=mode.get('name'),
        mode=mode.get('route'),
        config=config,
        ajaxOn=ajax_enabled,
        infiniteScrollOn=infinite_scroll_enabled,
        noLayout=no_layout
    )