Пример #1
0
def create():
    """
    Show the creation form of the text item.
    """

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

    form = SQLFORM.factory(*fields)

    if form.process().accepted:
        item_id = application.createItem('text', form.vars)
        form.vars.item_id = item_id
        db.plugin_text_text.insert(
            **db.plugin_text_text._filter_fields(form.vars))
        application.indexItem(item_id)
        redirect(URL('default', 'index.html'))

    return locals()
Пример #2
0
def create():
    """
    Show the creation form of the text item.
    """

    fields = [
        db.item.headline,
        db.item.keywords,
        db.item.genre,
        db.item.item_type,
        # db.plugin_text_text.body
    ]
    db.item.item_type.default = 'text'
    db.item.item_type.writable = False
    db.item.item_type.readable = False

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

    if form.process().accepted:
        item_id = application.createItem('text', form.vars)
        form.vars.item_id = item_id
        db.plugin_text_text.insert(
            **db.plugin_text_text._filter_fields(form.vars))
        application.indexItem(item_id)
        redirect(URL('index.html', args=[item_id]))

    return locals()
Пример #3
0
def create():
    fields = []

    fld_headline = db.item.headline
    fields.extend([fld_headline, db.item.keywords, db.item.genre])
    fdl_item_type = db.item.item_type
    fdl_item_type.writable = False
    fdl_item_type.readable = False
    fdl_item_type.default = 'photoset'

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

    if form.process(dbio=False).accepted:
        # item_id = CT_REG.photoset.create_item(form.vars)
        item_id = application.createItem('photoset', form.vars)
        form.vars.item_id = item_id
        if session.plugin_photoset:
            form.vars.photoset = session.plugin_photoset.photos
        else:
            form.vars.phoset = []
        db.plugin_photoset_content.insert(
            **db.plugin_photoset_content._filter_fields(
                form.vars
            )
        )
        application.indexItem(item_id)
        session.plugin_photoset = None
        redirect(URL('default', 'index.html'))

    return locals()
Пример #4
0
def create():
    fields = []

    fld_headline = db.item.headline
    fields.extend([fld_headline, db.item.keywords, db.item.genre])
    fdl_item_type = db.item.item_type
    fdl_item_type.writable = False
    fdl_item_type.readable = False
    fdl_item_type.default = 'photoset'

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

    if form.process(dbio=False).accepted:
        # item_id = CT_REG.photoset.create_item(form.vars)
        item_id = application.createItem('photoset', form.vars)
        form.vars.item_id = item_id
        if session.plugin_photoset:
            form.vars.photoset = session.plugin_photoset.photos
        else:
            form.vars.phoset = []
        db.plugin_photoset_content.insert(
            **db.plugin_photoset_content._filter_fields(
                form.vars
            )
        )
        application.indexItem(item_id)
        session.plugin_photoset = None
        redirect(URL('default', 'index.html'))

    return locals()
Пример #5
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()
Пример #6
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()
Пример #7
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()
Пример #8
0
def create():
    if not session.marked_items:
        session.flash = T('You must mark some items first')
        redirect(URL('default', 'index'))

    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 session.marked_items:
        _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 = session.marked_items
        db.plugin_package_content.insert(
            **db.plugin_package_content._filter_fields(form.vars)
        )
        application.indexItem(form.vars.item_id)
        session.marked_items = []
        redirect(URL('default', 'index'))

    return locals()
Пример #9
0
def create():
    if not session.marked_items:
        session.flash = T('You must mark some items first')
        redirect(URL('default', 'index'))

    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 session.marked_items:
        _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 = session.marked_items
        db.plugin_package_content.insert(
            **db.plugin_package_content._filter_fields(form.vars))
        application.indexItem(form.vars.item_id)
        session.marked_items = []
        redirect(URL('default', 'index'))

    return locals()
Пример #10
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()
Пример #11
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()