Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 3
0
def delete_rendition():
    item = application.getItemByUUID(request.args(0))
    content = db.plugin_picture_info(item_id=item.unique_id)
    rend = db.plugin_picture_rendition(request.args(1))

    if item and content and rend:
        # remove rendition
        # update content.renditions
        # update content db record
        r_id = rend.id
        del db.plugin_picture_rendition[r_id]
        content.renditions.remove(r_id)
        content.update_record()

    return CAT('')
Exemplo n.º 4
0
def delete_rendition():
    item = application.getItemByUUID(request.args(0))
    content = db.plugin_picture_info(item_id=item.unique_id)
    rend = db.plugin_picture_rendition(request.args(1))

    if item and content and rend:
        # remove rendition
        # update content.renditions
        # update content db record
        r_id = rend.id
        del db.plugin_picture_rendition[r_id]
        content.renditions.remove(r_id)
        content.update_record()

    return CAT('')
Exemplo n.º 5
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()
Exemplo n.º 6
0
def create():

    fields = []
    # i need the input of the based item fields
    fdl_headline = db.item.headline
    fields.append(fdl_headline)
    fields.append(db.item.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 = 'picture'

    # and the image for the first redition
    fld_redition = db.plugin_picture_rendition.picture
    fld_redition.uploadfolder = os.path.join(request.folder, 'uploads')
    fld_redition.label = T('Select the first rendition of the picture')
    fld_redition.comment = T("""
    Normally the raw version of the image. You may add other renditions as
    needed after form submition..
    """)
    fld_redition.requires = IS_IMAGE()
    fields.append(fld_redition)

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

    if form.process(dbio=False).accepted:
        # create the item
        item_id = application.createItem('picture', form.vars)
        # first rendition
        rend_id = db.plugin_picture_rendition.insert(
            **db.plugin_picture_rendition._filter_fields(form.vars)
        )
        form.vars.renditions = [rend_id]
        # generate the thumbnail
        rend = db.plugin_picture_rendition(rend_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 = (500, 500)
        im.thumbnail(size)
        fl = NamedTemporaryFile(suffix=".jpg", delete=True)
        fl.close()
        im.save(fl.name, "JPEG")
        form.vars.thumbnail = db.plugin_picture_info.thumbnail.store(
            open(fl.name, 'rb'), fl.name)
        os.unlink(fl.name)  # cleanup
        # create the picture main content
        form.vars.item_id = item_id
        info_id = db.plugin_picture_info.insert(
            **db.plugin_picture_info._filter_fields(form.vars)
        )
        # register document for search
        application.indexItem(item_id)
        # --
        # redirect to the item
        redirect(URL('default', 'index'))

    return locals()
Exemplo n.º 7
0
def create():

    fields = []
    # i need the input of the based item fields
    fdl_headline = db.item.headline
    fields.append(fdl_headline)
    fields.append(db.item.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 = 'picture'

    # and the image for the first redition
    fld_redition = db.plugin_picture_rendition.picture
    fld_redition.uploadfolder = os.path.join(request.folder, 'uploads')
    fld_redition.label = T('Select the first rendition of the picture')
    fld_redition.comment = T("""
    Normally the raw version of the image. You may add other renditions as
    needed after form submition..
    """)
    fld_redition.requires = IS_IMAGE()
    fields.append(fld_redition)

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

    if form.process(dbio=False).accepted:
        # create the item
        item_id = application.createItem('picture', form.vars)
        # first rendition
        rend_id = db.plugin_picture_rendition.insert(
            **db.plugin_picture_rendition._filter_fields(form.vars)
        )
        form.vars.renditions = [rend_id]
        # generate the thumbnail
        rend = db.plugin_picture_rendition(rend_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 = (500, 500)
        im.thumbnail(size)
        fl = NamedTemporaryFile(suffix=".jpg", delete=True)
        fl.close()
        im.save(fl.name, "JPEG")
        form.vars.thumbnail = db.plugin_picture_info.thumbnail.store(
            open(fl.name, 'rb'), fl.name)
        os.unlink(fl.name)  # cleanup
        # create the picture main content
        form.vars.item_id = item_id
        info_id = db.plugin_picture_info.insert(
            **db.plugin_picture_info._filter_fields(form.vars)
        )
        # register document for search
        application.indexItem(item_id)
        # --
        # redirect to the item
        redirect(URL('default', 'index'))

    return locals()