def diff(): item = application.getItemByUUID(request.args(0)) if item is None: raise HTTP(404) content = db.plugin_text_text(item_id=item.unique_id) archive = db.plugin_text_text_archive(request.args(1)) fields = [] fields_archived = [] fields_names = [] for f in db.plugin_text_text: # if values diff if content[f.name] != archive[f.name]: fields_names.append(f.name) f.comment = None fields.append(f) db.plugin_text_text_archive[f.name].comment = None fields_archived.append(db.plugin_text_text_archive[f.name]) # build two readonly forms form_actual = SQLFORM.factory(*fields, record=content, readonly=True, showid=False, formstyle='divs') form_archive = SQLFORM.factory(*fields, record=archive, readonly=True, showid=False, formstyle='divs') return locals()
def index(): """ Make it the same as all_items or search views but showing only one item. """ item = application.getItemByUUID(request.args(0)) return locals()
def view_photoset(): item = application.getItemByUUID(request.args(0)) content = db.plugin_photoset_content(item_id=item.unique_id) photos = content.photoset if not photos: photos = [] return locals()
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()
def index(): item = application.getItemByUUID(request.args(0)) if item is None: raise HTTP(404) short = request.vars.short if request.vars.short is not None else False tbl = db.plugin_comment_comment tbl.item_id.default = item.unique_id form = SQLFORM( tbl, submit_button=T('Comment'), formstyle='bootstrap3_stacked') rows = db( (tbl.id > 0) & (tbl.item_id == item.unique_id) ).select(orderby=~tbl.created_on) if form.process().accepted: response.js = "jQuery('#%s').get(0).reload();" % request.cid # send notifications to the users, except the current one subject = T("Comments on %s", (item.headline,)) # get the comment body comment = tbl(form.vars.id) message = response.render( 'plugin_comment/someone_commented.txt', dict(item=item, comment=comment, user=auth.user) ) application.notifyCollaborators( item.unique_id, subject, message ) return dict(form=form, comments=rows, short=short, item=item)
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()
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()
def export(): """ Create a zip file from the item content """ item = application.getItemByUUID(request.args(0)) export_dir = tempfile.mkdtemp() application.exportItem(item.unique_id, export_dir) tmpdir = tempfile.mkdtemp() try: tmparchive = os.path.join(tmpdir, item.slugline) archive = shutil.make_archive(tmparchive, 'zip', export_dir) response.stream(archive, chunk_size=4096, request=request, attachment=True, filename="{}.zip".format(item.slugline)) finally: shutil.rmtree(tmpdir) shutil.rmtree(export_dir) return ''
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 diff(): item = application.getItemByUUID(request.args(0)) content = db.plugin_picture_info(item_id=item.unique_id) archive = db.plugin_picture_info_archive(request.args(1)) fields = [] fields_archived = [] fields_names = [] for f in db.plugin_picture_info: # if values diff if content[f.name] != archive[f.name]: fields_names.append(f.name) f.comment = None fields.append(f) db.plugin_picture_info_archive[f.name].comment = None fields_archived.append(db.plugin_picture_info_archive[f.name]) # build two readonly forms form_actual = SQLFORM.factory( *fields, record=content, readonly=True, showid=False, formstyle='divs' ) form_archive = SQLFORM.factory( *fields, record=archive, readonly=True, showid=False, formstyle='divs') return locals()
def export(): """ Create a zip file from the item content """ item = application.getItemByUUID(request.args(0)) export_dir = tempfile.mkdtemp() application.exportItem(item.unique_id, export_dir) tmpdir = tempfile.mkdtemp() try: tmparchive = os.path.join(tmpdir, item.slugline) archive = shutil.make_archive(tmparchive, 'zip', export_dir) response.stream( archive, chunk_size=4096, request=request, attachment=True, filename="{}.zip".format(item.slugline) ) finally: shutil.rmtree(tmpdir) shutil.rmtree(export_dir) return ''
def index(): item = application.getItemByUUID(request.args(0)) if item is None: raise HTTP(404) short = request.vars.short if request.vars.short is not None else False tbl = db.plugin_comment_comment tbl.item_id.default = item.unique_id form = SQLFORM(tbl, submit_button=T('Comment'), formstyle='bootstrap3_stacked') rows = db((tbl.id > 0) & (tbl.item_id == item.unique_id)).select( orderby=~tbl.created_on) if form.process().accepted: response.js = "jQuery('#%s').get(0).reload();" % request.cid # send notifications to the users, except the current one subject = T("Comments on %s", (item.headline, )) # get the comment body comment = tbl(form.vars.id) message = response.render( 'plugin_comment/someone_commented.txt', dict(item=item, comment=comment, user=auth.user)) application.notifyCollaborators(item.unique_id, subject, message) return dict(form=form, comments=rows, short=short, item=item)
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()
def toogle_mark(): if session.marked_items is None: session.marked_items = [] item = application.getItemByUUID(request.args(0)) session.marked_items.append(item.unique_id) return ''
def preview_photo(): item = application.getItemByUUID(request.args(0)) photo = db.plugin_photoset_photo(request.args(1)) return IMG( _src=URL('default', 'download', args=[photo.picture]), _class="img-responsive center-block", _alt=item.slugline, )
def index(): """ Make it the same as all_items or search views but showing only one item. """ # We never will have a pure item, so we redirect to the apropiate C/T # plugin # redirect(application.getItemURL(request.args(0))) item = application.getItemByUUID(request.args(0)) return locals()
def delete_photo(): item = application.getItemByUUID(request.args(0)) content = db.plugin_photoset_content(item_id=item.unique_id) photo = db.plugin_photoset_photo(request.args(1)) content.photoset.remove(photo.id) del db.plugin_photoset_photo[photo.id] content.update_record() application.notifyChanges(item.unique_id) return CAT('')
def toogle_mark(): if session.marked_items is None: session.marked_items = [] item = application.getItemByUUID(request.args(0)) if item.unique_id in session.marked_items: session.marked_items.remove(item.unique_id) else: session.marked_items.append(item.unique_id) return ''
def delete(): """ Delete an Item. """ item = application.getItemByUUID(request.args(0)) item_id = item.id # remove the item from the index # TODO: move this to Application if needed Whoosh().remove(item.unique_id) db(db.item.id == item.id).delete() return ''
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 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('')
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()
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 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 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 changelog(): """ Show item change log over the time """ item = application.getItemByUUID(request.args(0)) if item is None: raise HTTP(404) content = db.plugin_text_text(item_id=item.unique_id) query = (db.plugin_text_text_archive.current_record == content.id) db.plugin_text_text_archive.modified_on.label = T('Date & Time') db.plugin_text_text_archive.modified_on.readable = True db.plugin_text_text_archive.modified_by.label = T('User') db.plugin_text_text_archive.modified_by.readable = True fields = [ db.plugin_text_text_archive.modified_on, db.plugin_text_text_archive.modified_by ] def gen_links(row): diff = A( SPAN(_class="glyphicon glyphicon-random"), _href=URL('diff', args=[item.unique_id, row.id]), _class="btn btn-default", _title=T("Differences"), ) return CAT(diff) links = [dict(header='', body=gen_links)] changes = SQLFORM.grid( query, orderby=[~db.plugin_text_text_archive.modified_on], fields=fields, args=request.args[:1], create=False, editable=False, details=False, deletable=False, searchable=False, csv=False, links=links, ) return locals()
def upload_photo(): """upload one or more photos""" if not session.plugin_photoset: session.plugin_photoset = Storage() session.plugin_photoset.photos = [] for r in request.vars: if r == "qqfile": filename = request.vars.qqfile photo_id = db.plugin_photoset_photo.insert( picture=db.plugin_photoset_photo.picture.store( request.body, filename ) ) # generate the thumbnail photo = db.plugin_photoset_photo(photo_id) (filename, stream) = db.plugin_photoset_photo.picture.retrieve( photo.picture ) filename = stream.name im = Image.open(filename) # -------------------------------- size = (200, 200) im.thumbnail(size) fl = NamedTemporaryFile(suffix=".jpg", delete=True) fl.close() im.save(fl.name, "JPEG") thumb = db.plugin_photoset_photo.thumbnail.store( open(fl.name, 'rb'), fl.name) photo.update_record(thumbnail=thumb) os.unlink(fl.name) # cleanup # if a photoset is given add this photo to the set if request.args(0): item = application.getItemByUUID(request.args(0)) photoset = db.plugin_photoset_content(item_id=item.unique_id) if photoset.photoset is None: photoset.photoset = [photo_id] else: photoset.photoset.append(photo_id) photoset.update_record() else: # in the create stage, i guess session.plugin_photoset.photos.append(photo_id) return response.json({'success': 'true'})
def changelog(): """ Show item change log over the time """ item = application.getItemByUUID(request.args(0)) if item is None: raise HTTP(404) content = db.plugin_text_text(item_id=item.unique_id) query = (db.plugin_text_text_archive.current_record == content.id) db.plugin_text_text_archive.modified_on.label = T('Date & Time') db.plugin_text_text_archive.modified_on.readable = True db.plugin_text_text_archive.modified_by.label = T('User') db.plugin_text_text_archive.modified_by.readable = True fields = [ db.plugin_text_text_archive.modified_on, db.plugin_text_text_archive.modified_by ] def gen_links(row): diff = A( SPAN(_class="glyphicon glyphicon-random"), _href=URL( 'diff', args=[item.unique_id, row.id]), _class="btn btn-default", _title=T("Differences"), ) return CAT(diff) links = [dict(header='', body=gen_links)] changes = SQLFORM.grid( query, orderby=[~db.plugin_text_text_archive.modified_on], fields=fields, args=request.args[:1], create=False, editable=False, details=False, deletable=False, searchable=False, csv=False, links=links, ) return locals()
def diff(): """ Show the diff betwen the actual item and the archive one """ item = application.getItemByUUID(request.args(0)) if item is None: raise HTTP(404) item_archive = db.item_archive(request.args(1)) if item_archive is None: raise HTTP(503) fields = [] fields_archived = [] # allow view of administrative metadata db.item.modified_by.readable = True db.item.modified_on.readable = True db.item_archive.modified_by.readable = True db.item_archive.modified_on.readable = True for f in db.item: if item[f.name] != item_archive[f.name]: f.comment = None fields.append(f) db.item_archive[f.name].comment = None fields_archived.append(db.item_archive[f.name]) # build two readonly forms form_actual = SQLFORM.factory( *fields, record=item, readonly=True, showid=False, formstyle='divs' ) form_archive = SQLFORM.factory( *fields_archived, record=item_archive, readonly=True, showid=False, formstyle='divs') return dict(item=item, form_actual=form_actual, form_archive=form_archive)
def toogle_pin(): dash = db.dashboard(request.args(0)) item = application.getItemByUUID(request.args(1)) response.js = "" if item.unique_id in dash.item_list: new_list = dash.item_list new_list.remove(item.unique_id) if request.vars.remove_item == "True": response.js += "$('#item-{}').hide();".format(item.id) else: new_list = dash.item_list new_list.append(item.unique_id) dash.update_record(item_list=new_list) response.js += "jQuery('#dashboard_cmp').get(0).reload();" return CAT('')
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 diff(): """ Show the diff betwen the actual item and the archive one """ item = application.getItemByUUID(request.args(0)) if item is None: raise HTTP(404) item_archive = db.item_archive(request.args(1)) if item_archive is None: raise HTTP(503) fields = [] fields_archived = [] # allow view of administrative metadata db.item.modified_by.readable = True db.item.modified_on.readable = True db.item_archive.modified_by.readable = True db.item_archive.modified_on.readable = True for f in db.item: if item[f.name] != item_archive[f.name]: f.comment = None fields.append(f) db.item_archive[f.name].comment = None fields_archived.append(db.item_archive[f.name]) # build two readonly forms form_actual = SQLFORM.factory(*fields, record=item, readonly=True, showid=False, formstyle='divs') form_archive = SQLFORM.factory(*fields_archived, record=item_archive, readonly=True, showid=False, formstyle='divs') return dict(item=item, form_actual=form_actual, form_archive=form_archive)
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 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 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 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 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()
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 index(): item = application.getItemByUUID(request.args(0)) content = db.plugin_photoset_content(item_id=item.id) return locals()
def diff(): item = application.getItemByUUID(request.args(0)) content = db.plugin_package_content(item_id=item.unique_id) archive = db.plugin_package_content_archive(request.args(1)) return locals()
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()