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 create(): org = db.organization(session.org_id) tbl = db.desk tbl.item_list.readable = False tbl.item_list.writable = False tbl.name.requires = IS_NOT_EMPTY() form = SQLFORM(db.desk) form.add_button(T('Cancel'), URL('org', 'view', args=[org.id])) if form.process().accepted: # add the new desk to the org list desk_id = form.vars.id # add current users as the one with permission to update manage # this desk auth.add_permission( auth.user_group(auth.user.id), 'update', db.desk, desk_id) desk_list = org.desks desk_list.insert(0, desk_id) org.update_record(desks=desk_list) # return to the org desk list redirect(URL('org', 'view', args=[org.id])) return locals()
def create_new(self): # permission is checked here if self.auth.has_membership("author", self.auth.user_id): self.db.Post.author.default = self.auth.user_id self.context.form = SQLFORM(self.db.Post, formstyle='divs').process(onsuccess=lambda form: redirect(URL('show', args=form.vars.id))) else: self.context.form = "You can't post, only logged in users, members of 'author' group can post"
def edit(self): self.get() self.context.form = SQLFORM(self.db.Page, self.context.page, formstyle='divs') if self.context.form.process().accepted: redirect(self.CURL("show", args=self.context.form.vars.id))
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 create(): """Create a new organization""" tbl = db.organization tbl.users.readable = False tbl.users.writable = False tbl.desks.readable = False tbl.desks.writable = False tbl.name.requires = [ IS_NOT_EMPTY(error_message=T("Cannot be empty")), IS_NOT_IN_DB( db, 'organization.name', error_message=T( "An Organization witch that name is allready in nStock")) ] form = SQLFORM(tbl) form.add_button(T('Cancel'), URL('index')) if form.process().accepted: # add the new organization g_id = auth.user_group(auth.user.id) # give the user all perms over this org auth.add_permission(g_id, 'update', tbl, form.vars.id) auth.add_permission(g_id, 'read', tbl, form.vars.id) auth.add_permission(g_id, 'delete', tbl, form.vars.id) redirect(URL('index')) return locals()
def reportcontent(self): if not self.db.auth.user: vrs = { "_next": self.CURL('page', 'reportcontent', args=self.db.request.args) } redirect(self.CURL('person', 'account', args=['login'], vars=vrs)) self.response.meta.title = "%s | %s" % ( self.db.T("Report content"), self.db.config.meta.title, ) self.db.Report.content_type.default = self.db.T( self.db.request.args(0)) self.db.Report.item_id.default = int(self.db.request.args(1)) self.db.Report.slug.default = self.db.request.args(2) self.db.Report.content_type.writable = \ self.db.Report.item_id.writable = \ self.db.Report.slug.writable = False self.context.form = SQLFORM(self.db.Report, formstyle='divs') self.context.form.insert(0, H1(self.db.T("Report content or user"))) if self.context.form.process().accepted: self.db.response.flash = self.db.T( "Thank you for reporting this content")
def getEditgameUpdateForm(game): """ Gets an update for the edit game page. Keyword Arguments: game -- row representing the current game Return Values: formUpdate -- web2py form """ from gluon import current, redirect, URL, SQLFORM db = current.db #Hide some fields of the form hideFields(db.game, ['id', 'host_id', 'game_status', 'password']) formUpdate = SQLFORM(db.game, game.id) formUpdate.add_class('assassins-form') if formUpdate.process().accepted: resizeImage(db.game, game.id) redirect(getUrl('edit', game.id)) return formUpdate
def edit(self): self.context.customfield = customfield self.get() self.db.article.thumbnail.compute = lambda r: THUMB2( r['picture'], gae=self.request.env.web2py_runtime_gae) self.db.article.medium_thumbnail.compute = lambda r: THUMB2( r['picture'], gae=self.request.env.web2py_runtime_gae, nx=400, ny=400, name='medium_thumb') self.context.article_form = SQLFORM(self.db.article, self.context.article) content, article_data = self.get_content( self.context.article.content_type_id.classname, self.context.article.id) if self.context.article_form.process().accepted: article_data.update_record( **content.entity._filter_fields(self.request.vars)) self.new_article_event( 'update_article', data={ 'event_link': "%s/%s" % (self.context.article.id, IS_SLUG()( self.context.article_form.vars.title)[0]), 'event_text': self.context.article_form.vars.description, 'event_to': "%s (%s)" % (self.context.article.content_type_id.title, self.context.article.title), 'event_image': self.get_image( self.context.article.thumbnail, self.context.article.content_type_id.identifier) }) self.session.flash = self.T( "%s updated." % self.context.article.content_type_id.title) self.context.article.update_record(search_index="|".join( str(value) for value in self.request.vars.values())) redirect( self.CURL('article', 'show', args=[ self.context.article.id, IS_SLUG()(self.request.vars.title)[0] ])) self.context.content_form = SQLFORM(content.entity, article_data)
def edit_post(self, post_id): post = self.db.Post[post_id] # permission is checked here if not post or post.author != self.auth.user_id: redirect(URL("post", "index")) self.context.form = SQLFORM( self.db.Post, post.id, formstyle='divs').process(onsuccess=lambda form: redirect( URL('show', args=form.vars.id)))
def edit(): desk = db.desk(request.args(0)) session.desk_id = desk.id db.desk.item_list.readable = False db.desk.item_list.writable = False form = SQLFORM(db.desk, record=desk, showid=False) if form.process().accepted: redirect(URL('index', args=[desk.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 edit(): org = db.organization(request.args(0)) tbl = db.organization tbl.users.readable = False tbl.users.writable = False tbl.desks.readable = False tbl.desks.writable = False tbl.name.requires = [IS_NOT_EMPTY()] # edit form form = SQLFORM(db.organization, record=org, showid=False) if form.process().accepted: redirect(URL('view', args=[org.id])) return locals()
def linked_create_form(): """ creates a form to insert a new entry into the linked table which populates the ajaxSelect widget """ print 'Starting linked_create_form' try: tablename = request.args[0] fieldname = request.args[1] wrappername = request.vars['wrappername'] table = db[tablename] field = table[fieldname] linktable = get_linktable(field) formname = '{}_create'.format(wrappername) form = SQLFORM(db[linktable]) comp_url = URL('plugin_ajaxselect', 'set_widget.load', args=[tablename, fieldname], vars=request.vars) if form.process(formname=formname).accepted: response.flash = 'form accepted' response.js = "window.setTimeout(" \ "web2py_component('{}', '{}'), " \ "500);".format(comp_url, wrappername) print 'linked create form accepted' print 'linked create form vars:' pprint(form.vars) if form.errors: response.error = 'form was not processed' response.flash = 'form was not processed' print 'error processing linked_create_form' print form.errors else: print 'form not processed but no errors' pass except Exception: import traceback print traceback.format_exc(5) form = traceback.format_exc(5) return dict(form=form)
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 linked_edit_form(): """ creates a form to edit, update, or delete an intry in the linked table which populates the AjaxSelect widget. """ try: tablename = request.args[0] fieldname = request.args[1] table = db[tablename] field = table[fieldname] linktable = get_linktable(field) this_row = request.args[2] wrappername = request.vars['wrappername'] formname = '{}/edit'.format(tablename) form = SQLFORM(db[linktable], this_row) comp_url = URL('plugin_ajaxselect', 'set_widget.load', args=[tablename, fieldname], vars=request.vars) if form.process(formname=formname).accepted: response.flash = 'form accepted' response.js = "web2py_component('%s', '%s');" % (comp_url, wrappername) if form.errors: response.error = 'form was not processed' print('error processing linked_create_form') print(form.errors) else: pass except Exception: import traceback print('error in whole of linked_edit_form') print(traceback.format_exc(5)) form = traceback.format_exc(5) return {'form': 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 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 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)) 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 comment_internal(self): is_author = False if self.session.auth and self.session.auth.user: is_author = True if self.session.auth.user.id == self.context.article.author else False self.db.Comments.article_id.default = self.context.article.id self.db.Comments.user_id.default = self.session.auth.user.id self.db.Comments.commenttime.default = self.request.now self.db.Comments.comment_text.label = self.T("Post your comment") from plugin_ckeditor import CKEditor ckeditor = CKEditor() self.db.Comments.comment_text.widget = ckeditor.basicwidget form = SQLFORM(self.db.Comments, formstyle='divs') if form.process( message_onsuccess=self.T('Comment included')).accepted: self.new_article_event( 'new_article_comment', self.session.auth.user, data={ 'event_text': form.vars.comment_text, 'event_link': "%s/%s#comment_%s" % (self.context.article.id, self.context.article.slug, form.vars.id) }) else: form = A( self.T("Login to post comments"), _class="button", _href=self.CURL( 'default', 'user', args='login', vars=dict(_next=self.CURL('article', 'show', args=[ self.context.article.id, self.context.article.slug ])))) comments = self.db( self.db.Comments.article_id == self.context.article.id).select( orderby=self.db.Comments.created_on) if comments and is_author: edit_in_place = ckeditor.bulk_edit_in_place( ["comment_%(id)s" % comment for comment in comments], URL('editcomment')) elif comments and self.session.auth and self.session.auth.user: usercomments = comments.find( lambda row: row.user_id == self.session.auth.user.id) if usercomments: edit_in_place = ckeditor.bulk_edit_in_place( ["comment_%(id)s" % comment for comment in usercomments], URL('editcomment')) else: edit_in_place = ('', '') else: edit_in_place = ('', '') return DIV(H4( IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='board.24.png')), self.T("Comments")), UL( *[ LI(H5( A(self.T("%s %s" % (comment.nickname or comment.user_id, self.db.pdate(comment.commenttime))), _href=self.CURL('person', 'show', args=comment.nickname or comment.user_id))), DIV( XML(comment.comment_text), **{ '_class': 'editable commentitem', '_data-object': 'comment', '_data-id': comment.id, '_id': "comment_%s" % comment.id }), _class="comment_li") for comment in comments ], **dict(_class="comment_ul")), edit_in_place[1], form, _class="internal-comments article-box")
def testpage(): form = SQLFORM(db.address) return dict(form=form)
def change_user_image(): form = SQLFORM(db.auth_user.picture) return dict(form=form)
def messages(): form = SQLFORM(db.address) return dict(form=form)
def lfg(): form = SQLFORM(db.address) return dict(form=form)