Ejemplo n.º 1
0
def load_items():
    """Show the item list of this dashboard"""
    dash = db.dashboard(request.args(0))
    # session.dashboard = dash.id

    request.vars.q = None if request.vars.q == '' else request.vars.q
    if request.vars.q is not None:
        ids = Whoosh().search(request.vars.q)
        query = db.item.unique_id.belongs(ids)
    else:
        query = (db.item.id > 0)

    query &= (
        auth.accessible_query('collaborator', db.item) |
        auth.accessible_query('owner', db.item))
    query &= db.dashboard.item_list.contains(db.item.unique_id)
    query &= (db.dashboard.id == dash.id)

    grid = SQLFORM.grid(
        query, args=request.args[:1],
        orderby=[~db.item.created_on],
        create=False,
        csv=False,
        paginate=6,
    )

    response.title = dash.name
    response.js = "jQuery('#dashboard_cmp').get(0).reload();"

    return dict(grid=grid, current_dash=dash)
Ejemplo n.º 2
0
def delete():
    dash = db.dashboard(request.args(0))

    db(db.dashboard.id == dash.id).delete()
    session.dashboard = None

    redirect(URL('default', 'index'))
    return CAT()
Ejemplo n.º 3
0
def edit():
    dash = db.dashboard(request.args(0))
    db.dashboard.item_list.readable = False
    db.dashboard.item_list.writable = False

    form = SQLFORM(db.dashboard, record=dash, showid=False)

    if form.process().accepted:
        redirect(URL('index', args=[dash.id]))

    return locals()
Ejemplo n.º 4
0
def create():
    if session.dashboard is None:
        session.flash = T('You must activate some dashboard first')
        redirect(URL('default', 'index'))

    dash = db.dashboard(session.dashboard)
    if not dash.item_list:
        session.flash = T('The current dashboard is empty')
        redirect(URL('default', 'index'))

    # get the headline form the first item in the list
    # first_item = application.getItemByUUID(dash.item_list[0])

    fields = []
    # i need the input of the based item fields
    fdl_headline = db.item.headline
    fields.append(fdl_headline)
    fdl_keywords = db.item.keywords
    keywords_list = []
    for item_id in dash.item_list:
        _item = application.getItemByUUID(item_id)
        keywords_list.extend(_item.keywords)
    keywords_list = list(set(keywords_list))  # remove any dup
    fdl_keywords.default = keywords_list
    fields.append(fdl_keywords)
    fields.append(db.item.genre)
    fdl_item_type = db.item.item_type
    fdl_item_type.writable = False
    fdl_item_type.readable = False
    fdl_item_type.default = 'package'
    fields.append(db.plugin_package_content.description)

    form = SQLFORM.factory(
        *fields,
        table_name='plugin_package_item'  # to allow the correct file name
    )

    if form.process(dbio=False).accepted:
        form.vars.item_id = application.createItem('package', form.vars)
        form.vars.item_list = dash.item_list
        db.plugin_package_content.insert(
            **db.plugin_package_content._filter_fields(form.vars)
        )
        application.indexItem(form.vars.item_id)
        redirect(URL('default', 'index'))

    return locals()
Ejemplo n.º 5
0
def toogle_pin():
    dash = db.dashboard(request.args(0))
    item = application.getItemByUUID(request.args(1))

    response.js = ""

    if item.unique_id in dash.item_list:
        new_list = dash.item_list
        new_list.remove(item.unique_id)
        if request.vars.remove_item == "True":
            response.js += "$('#item-{}').hide();".format(item.id)

    else:
        new_list = dash.item_list
        new_list.append(item.unique_id)
    dash.update_record(item_list=new_list)

    response.js += "jQuery('#dashboard_cmp').get(0).reload();"

    return CAT('')
Ejemplo n.º 6
0
def index():
    """Show the item list of this dashboard"""
    dash = db.dashboard(request.args(0))
    activeDashboard(request.args(0))

    query = (db.item.id > 0)
    query &= (
        auth.accessible_query('collaborator', db.item) |
        auth.accessible_query('owner', db.item))
    query &= db.dashboard.item_list.contains(db.item.unique_id)
    query &= (db.dashboard.id == dash.id)

    grid = SQLFORM.grid(
        query, args=request.args[:1],
        orderby=[~db.item.created_on],
        create=False,
        csv=False,
        paginate=6,
    )

    response.title = dash.name

    return dict(grid=grid, current_dash=dash)
Ejemplo n.º 7
0
def toogle_on():
    dash = db.dashboard(request.args(0))
    activeDashboard(dash.id)
    response.js = "jQuery('#dashboard_cmp').get(0).reload();"
    response.js += "jQuery('#main').get(0).reload();"
    return CAT('')
Ejemplo n.º 8
0
def activeDashboard(dash_id):
    dash = db.dashboard(dash_id)

    if dash:
        session.dashboard = dash.id