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()
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()
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()
def index(): """ Edit content """ item = application.getItemByUUID(request.args(0)) db.plugin_picture_info.thumbnail.readable = False db.plugin_picture_info.thumbnail.writable = False db.plugin_picture_info.renditions.readable = False db.plugin_picture_info.renditions.writable = False content = db.plugin_picture_info(item_id=item.unique_id) form = SQLFORM( db.plugin_picture_info, record=content, showid=False, submit_button=T('Save')) if form.process().accepted: application.notifyChanges(item.unique_id) application.indexItem(item.unique_id) response.flash = None return dict(form=form, item=item, content=content)
def index(): """ Edit/Show package content """ pkg_item = application.getItemByUUID(request.args(0)) content = db.plugin_package_content(item_id=pkg_item.unique_id) form = SQLFORM(db.plugin_package_content, record=content, showid=False) if form.process().accepted: application.indexItem(pkg_item.unique_id) redirect(URL('default', 'index')) return locals()
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()
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()
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()
def index(): """ Edit/Show package content """ pkg_item = application.getItemByUUID(request.args(0)) content = db.plugin_package_content(item_id=pkg_item.unique_id) form = SQLFORM( db.plugin_package_content, record=content, showid=False) if form.process().accepted: application.indexItem(pkg_item.unique_id) redirect(URL('default', 'index')) return locals()
def edit_form(): item = application.getItemByUUID(request.args(0)) content = db.plugin_photoset_content(item_id=item.unique_id) db.plugin_photoset_content.photoset.readable = False db.plugin_photoset_content.photoset.writable = False db.plugin_photoset_content.item_id.readable = False db.plugin_photoset_content.item_id.writable = False form = SQLFORM(db.plugin_photoset_content, record=content, showid=False, submit_button=T('Save')) if form.process().accepted: application.notifyChanges(item.unique_id) application.indexItem(item.unique_id) response.flash = T('Saved') return form
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()
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()
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()
def edit_form(): item = application.getItemByUUID(request.args(0)) content = db.plugin_photoset_content(item_id=item.unique_id) db.plugin_photoset_content.photoset.readable = False db.plugin_photoset_content.photoset.writable = False db.plugin_photoset_content.item_id.readable = False db.plugin_photoset_content.item_id.writable = False form = SQLFORM( db.plugin_photoset_content, record=content, showid=False, submit_button=T('Save') ) if form.process().accepted: application.notifyChanges(item.unique_id) application.indexItem(item.unique_id) response.flash = T('Saved') return form
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)
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)
def index(): """ Edit content """ item = application.getItemByUUID(request.args(0)) db.plugin_picture_info.renditions.readable = False db.plugin_picture_info.renditions.writable = False content = db.plugin_picture_info(item_id=item.unique_id) form = SQLFORM( db.plugin_picture_info, record=content, showid=False, submit_button=T('Save')) if form.process().accepted: application.notifyChanges(item.unique_id) application.indexItem(item.unique_id) response.flash = None return dict(form=form, item=item, content=content)
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()