Beispiel #1
0
def share():
    """
    Show the list of desk to with the item can be push
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)

    query = (db.desk.id != session.desk_id)
    query &= auth.accessible_query('push_items', db.desk)

    posible_desk = db(query).select()

    fld_to_desk = Field('to_desk', 'integer')
    fld_to_desk.label = T("Push to")
    fld_to_desk.comment = T("Select where to push the item")
    fld_to_desk.requires = IS_IN_SET([(desk.id, desk.name)
                                      for desk in posible_desk])
    form = SQLFORM.factory(fld_to_desk,
                           submit_button=T("Send"),
                           table_name='share')
    if form.process().accepted:
        # send the item to the selected desk
        ct = application.getContentType(item.item_type)
        ct.shareItem(item.unique_id, session.desk_id, form.vars.to_desk)
        response.js = "$('#metaModal').modal('hide');"

    return locals()
Beispiel #2
0
def share():
    """
    Show the list of desk to with the item can be push
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)

    query = (db.desk.id != session.desk_id)
    query &= auth.accessible_query('push_items', db.desk)

    posible_desk = db(query).select()

    fld_to_desk = Field('to_desk', 'integer')
    fld_to_desk.label = T("Push to organization desk")
    fld_to_desk.comment = T("Select where to push the item")
    fld_to_desk.requires = IS_EMPTY_OR(
        IS_IN_SET([(desk.id, desk.name) for desk in posible_desk]))

    fld_personal_desk = Field('to_person_desk', 'integer')
    fld_personal_desk.label = T("Push to other person desk")
    fld_personal_desk.comment = T("Select a person from the list.")
    # list of person on orgs
    persons = []
    # search up all the persons
    orgs = db(db.organization.users.contains(auth.user.id)).select()
    for org in orgs:
        x = [db.auth_user(id=y) for y in org.users if y != auth.user.id]
        persons.extend(x)
    persons = list(set(persons))
    fld_personal_desk.requires = IS_EMPTY_OR(
        IS_IN_SET([(per.id, "{} {}".format(per.first_name, per.last_name))
                   for per in persons]))

    fld_cond = Field('cond', 'boolean', default=False)
    fld_cond.label = T('To other person?')

    form = SQLFORM.factory(fld_to_desk,
                           fld_personal_desk,
                           fld_cond,
                           submit_button=T("Send"),
                           table_name='share')
    if form.process().accepted:
        src = session.desk_id
        if form.vars.cond:
            # send the item to other user
            other_user = db.auth_user(form.vars.to_person_desk)
            target = application.getUserDesk(other_user).id
        else:
            # send the item to the selected desk
            target = form.vars.to_desk

        if target:
            ct = application.getContentType(item.item_type)
            ct.shareItem(item.unique_id, src, target)
        response.js = "$('#metaModal').modal('hide');"
        response.flash = None

    return locals()
Beispiel #3
0
def create():
    """
    Create a Item of a given content type
    """
    item_type = request.args(0)
    ct = application.getContentType(item_type)
    if ct is None:
        raise HTTP(404)

    fields = [
        db.item.headline,
        db.item.keywords,
        db.item.genre,
        db.item.item_type,
    ]
    db.item.item_type.default = item_type
    db.item.item_type.writable = False
    db.item.item_type.readable = False

    # aks for preconditions:
    cond, values = ct.check_create_conditions()

    if cond is False:
        user_desk = application.getUserDesk()
        if 'message' in values.keys():
            message = values['message']
        else:
            message = T('Some conditions for the item creation are not met.')
        session.flash = message
        redirect(URL('desk', 'index.html', args=[user_desk.id]))

    else:
        # get the proposed values and initialize the form
        if 'headline' in values.keys():
            db.item.headline.default = values['headline']
        if 'keywords' in values.keys():
            db.item.keywords.default = values['keywords']
        if 'genre' in values.keys():
            db.item.genre.default = values['genre']

    form = SQLFORM.factory(*fields, submit_button=T("Continue"))

    if form.process(dbio=False).accepted:
        item_id = application.createItem(item_type, form.vars)
        application.indexItem(item_id)
        redirect(application.getItemURL(item_id))

    return locals()
Beispiel #4
0
def create():
    """
    Create a Item of a given content type
    """
    item_type = request.args(0)
    ct = application.getContentType(item_type)
    if ct is None:
        raise HTTP(404)

    fields = [
        db.item.headline,
        db.item.keywords,
        db.item.genre,
        db.item.item_type,
    ]
    db.item.item_type.default = item_type
    db.item.item_type.writable = False
    db.item.item_type.readable = False

    # aks for preconditions:
    cond, values = ct.check_create_conditions()

    if cond is False:
        user_desk = application.getUserDesk()
        if 'message' in values.keys():
            message = values['message']
        else:
            message = T('Some conditions for the item creation are not met.')
        session.flash = message
        redirect(URL('desk', 'index.html', args=[user_desk.id]))

    else:
        # get the proposed values and initialize the form
        if 'headline' in values.keys():
            db.item.headline.default = values['headline']
        if 'keywords' in values.keys():
            db.item.keywords.default = values['keywords']
        if 'genre' in values.keys():
            db.item.genre.default = values['genre']

    form = SQLFORM.factory(*fields, submit_button=T("Continue"))

    if form.process(dbio=False).accepted:
        item_id = application.createItem(item_type, form.vars)
        application.indexItem(item_id)
        redirect(application.getItemURL(item_id))

    return locals()
Beispiel #5
0
def share():
    """
    Show the user's who has access to this item
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)

    fld_email = Field('email', 'string', default='')
    fld_perms = Field('perms', 'string', default='owner')
    fld_email.requires = IS_EMAIL()
    form = SQLFORM.factory(
        fld_email,
        fld_perms,
        formstyle='bootstrap3_inline',
        submit_button=T("Share this item"),
        table_name='share')
    if form.process().accepted:
        # search a user by his email addr
        u = db.auth_user(email=form.vars.email)
        if u is not None:
            # create new share
            ct = application.getContentType(item.item_type)
            ct.shareItem(item.unique_id, u, perms=form.vars.perms)
            # notify users
            subject = T("Share of %s", (item.headline,))
            message = response.render(
                'share_email.txt',
                dict(
                    item=item,
                    user=auth.user,
                    t_user=db.auth_user(email=form.vars.email)
                )
            )
            application.notifyCollaborators(
                item.unique_id,
                subject,
                message
            )
            # --
            # close the dialog
            response.js = "$('#metaModal').modal('hide');"
        else:
            # no user with that email
            response.flash = T("The user don't exists on this system")
            form.errors.email = T("The user don't exists on this system")

    return locals()
Beispiel #6
0
def meta():
    """
    Edit/Show item metadata info
    """
    item = application.getItemByUUID(request.args(0))

    if item is None:
        raise HTTP(404)

    contentType = application.getContentType(item.item_type)
    l_names = [
        (r.language_tag, r.english_name) for r in db(
            db.languages.id > 0
        ).select(orderby=db.languages.english_name)
    ]
    db.item.language_tag.requires = IS_IN_SET(
        l_names,
        zero=None
    )

    # issue #5 hidde some fields from metadata
    db.item.provider.readable = False
    db.item.provider.writable = False
    db.item.provider_service.readable = False
    db.item.provider_service.writable = False
    db.item.copyright_holder.readable = False
    db.item.copyright_holder.writable = False
    db.item.copyright_url.readable = False
    db.item.copyright_url.writable = False
    db.item.copyright_notice.readable = False
    db.item.copyright_notice.writable = False
    db.item.pubstatus.readable = False
    db.item.pubstatus.writable = False

    form = SQLFORM(db.item, record=item)

    if form.process().accepted:
        # session.flash = "Done !"
        # send an email to all the users who has access to this item
        application.notifyChanges(item.unique_id)
        application.indexItem(item.unique_id)
        if request.ajax:
            response.js = "$('#metaModal').modal('hide');"
        else:
            redirect(application.getItemURL(item.unique_id))

    return locals()
Beispiel #7
0
def meta():
    """
    Edit/Show item metadata info
    """
    item = application.getItemByUUID(request.args(0))

    if item is None:
        raise HTTP(404)

    contentType = application.getContentType(item.item_type)
    l_names = [(r.language_tag, r.english_name) for r in db(
        db.languages.id > 0).select(orderby=db.languages.english_name)]
    db.item.language_tag.requires = IS_IN_SET(l_names, zero=None)

    # issue #5 hidde some fields from metadata
    db.item.provider.readable = False
    db.item.provider.writable = False
    db.item.provider_service.readable = False
    db.item.provider_service.writable = False
    db.item.copyright_holder.readable = False
    db.item.copyright_holder.writable = False
    db.item.copyright_url.readable = False
    db.item.copyright_url.writable = False
    db.item.copyright_notice.readable = False
    db.item.copyright_notice.writable = False
    db.item.pubstatus.readable = False
    db.item.pubstatus.writable = False

    form = SQLFORM(db.item, record=item)

    if form.process().accepted:
        # session.flash = "Done !"
        # send an email to all the users who has access to this item
        application.notifyChanges(item.unique_id)
        application.indexItem(item.unique_id)
        if request.ajax:
            response.js = "$('#metaModal').modal('hide');"
        else:
            redirect(application.getItemURL(item.unique_id))

    return locals()
Beispiel #8
0
def share():
    """
    Show the list of desk to with the item can be push
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)

    query = (db.desk.id != session.desk_id)
    query &= auth.accessible_query('push_items', db.desk)

    posible_desk = db(query).select()

    fld_to_desk = Field('to_desk', 'integer')
    fld_to_desk.label = T("Push to organization desk")
    fld_to_desk.comment = T("Select where to push the item")
    fld_to_desk.requires = IS_EMPTY_OR(IS_IN_SET(
        [(desk.id, desk.name) for desk in posible_desk]
    ))

    fld_personal_desk = Field('to_person_desk', 'integer')
    fld_personal_desk.label = T("Push to other person desk")
    fld_personal_desk.comment = T("Select a person from the list.")
    # list of person on orgs
    persons = []
    # search up all the persons
    orgs = db(db.organization.users.contains(auth.user.id)).select()
    for org in orgs:
        x = [db.auth_user(id=y) for y in org.users if y != auth.user.id]
        persons.extend(x)
    persons = list(set(persons))
    fld_personal_desk.requires = IS_EMPTY_OR(IS_IN_SET(
        [(per.id, "{} {}".format(per.first_name, per.last_name)) for per in persons]
    ))

    fld_cond = Field('cond', 'boolean', default=False)
    fld_cond.label = T('To other person?')

    form = SQLFORM.factory(
        fld_to_desk,
        fld_personal_desk,
        fld_cond,
        submit_button=T("Send"),
        table_name='share')
    if form.process().accepted:
        src = session.desk_id
        if form.vars.cond:
            # send the item to other user
            other_user = db.auth_user(form.vars.to_person_desk)
            target = application.getUserDesk(other_user).id
        else:
            # send the item to the selected desk
            target = form.vars.to_desk

        if target:
            ct = application.getContentType(item.item_type)
            ct.shareItem(item.unique_id, src, target)
        response.js = "$('#metaModal').modal('hide');"
        response.flash = None

    return locals()