Example #1
0
def add_rendition():
    item = application.getItemByUUID(request.args(0))
    content = db.plugin_picture_info(item_id=item.unique_id)

    form = SQLFORM(db.plugin_picture_rendition)

    if form.process().accepted:
        r_id = form.vars.id
        rend = db.plugin_picture_rendition(r_id)
        (filename, stream) = db.plugin_picture_rendition.picture.retrieve(
            rend.picture)
        filename = stream.name
        im = Image.open(filename)
        # update rendition with image info
        rend.height = im.height
        rend.width = im.width
        rend.format = im.format
        rend.color = im.mode
        rend.update_record()
        # append this rendition to the item content
        content.renditions.append(r_id)
        content.update_record()
        redirect(application.getItemURL(item.unique_id))

    return locals()
Example #2
0
def add_rendition():
    item = application.getItemByUUID(request.args(0))
    content = db.plugin_picture_info(item_id=item.unique_id)

    form = SQLFORM(db.plugin_picture_rendition)

    if form.process().accepted:
        r_id = form.vars.id
        rend = db.plugin_picture_rendition(r_id)
        (filename,
         stream) = db.plugin_picture_rendition.picture.retrieve(rend.picture)
        filename = stream.name
        im = Image.open(filename)
        # update rendition with image info
        rend.height = im.height
        rend.width = im.width
        rend.format = im.format
        rend.color = im.mode
        rend.update_record()
        # append this rendition to the item content
        content.renditions.append(r_id)
        content.update_record()
        redirect(application.getItemURL(item.unique_id))

    return locals()
Example #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()
Example #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()
Example #5
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()
Example #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()
Example #7
0
def index():
    """
    Edit content
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)

    content = db.plugin_text_text(item_id=item.unique_id)

    form = SQLFORM(db.plugin_text_text,
                   record=content,
                   showid=False,
                   submit_button=T('Save'))

    if form.process().accepted:
        application.notifyChanges(item.unique_id)
        application.indexItem(item.unique_id)
        redirect(application.getItemURL(item.unique_id))
        response.flash = T('Done')

    return dict(form=form, item=item, content=content)
Example #8
0
def add_rendition():
    item = application.getItemByUUID(request.args(0))
    content = db.plugin_picture_info(item_id=item.unique_id)
    db.plugin_picture_rendition.thumbnail.writable = False
    db.plugin_picture_rendition.thumbnail.readable = False

    form = SQLFORM(db.plugin_picture_rendition)

    if form.process().accepted:
        r_id = form.vars.id
        rend = db.plugin_picture_rendition(r_id)
        (filename, stream) = db.plugin_picture_rendition.picture.retrieve(
            rend.picture)
        filename = stream.name
        im = Image.open(filename)
        # update rendition with image info
        rend.width, rend.height = im.size
        rend.format = im.format
        rend.color = im.mode
        rend.update_record()
        # --------------------------------
        size = (700, 700)
        im.thumbnail(size)
        fl = NamedTemporaryFile(suffix=".jpg", delete=True)
        fl.close()
        im.save(fl.name, "JPEG")
        store_tumb = db.plugin_picture_rendition.thumbnail.store(
            open(fl.name, 'rb'), fl.name)
        os.unlink(fl.name)  # cleanup
        rend.update_record(
            thumbnail=store_tumb
        )
        # append this rendition to the item content
        content.renditions.append(r_id)
        content.update_record()
        redirect(application.getItemURL(item.unique_id))

    return locals()
Example #9
0
def index():
    """
    Edit content
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)

    content = db.plugin_text_text(item_id=item.unique_id)

    form = SQLFORM(
        db.plugin_text_text,
        record=content,
        showid=False,
        submit_button=T('Save'))

    if form.process().accepted:
        application.notifyChanges(item.unique_id)
        application.indexItem(item.unique_id)
        redirect(application.getItemURL(item.unique_id))
        response.flash = T('Done')

    return dict(form=form, item=item, content=content)