本文整理汇总了Python中gluon.current.response方法的典型用法代码示例。如果您正苦于以下问题:Python current.response方法的具体用法?Python current.response怎么用?Python current.response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gluon.current
的用法示例。
在下文中一共展示了current.response方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: notifyChanges
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
def notifyChanges(self, item_id):
response = self.response
auth = self.auth
T = self.T
item = self.getItemByUUID(item_id)
message = response.render(
'changes_email.txt',
dict(item=item, user=auth.user)
)
subject = T("Changes on %s") % (item.headline,)
self.notifyCollaborators(
item.unique_id,
subject,
message
)
示例2: index
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
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)
示例3: index
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
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)
示例4: process
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
def process(self):
"""
$ curl http://127.0.0.1:8000/collection/default/api
$ curl http://127.0.0.1:8000/collection/default/api/book
$ curl http://127.0.0.1:8000/collection/default/api/book?page=1&per_page=20
$ curl http://127.0.0.1:8000/collection/default/api/book?search=title contains "the"
$ curl http://127.0.0.1:8000/collection/default/api/bookcase
$ curl http://127.0.0.1:8000/collection/default/api/bookcase/1
$ curl -X POST -d 'title=GEB' http://127.0.0.1:8000/collection/default/api/book
{"row": {"id": 91}}
$ curl -X DELETE http://127.0.0.1:8000/collection/default/api/book/93
{"count": 1}
$ curl -X DELETE http://127.0.0.1:8000/collection/default/api/book/93
{"count": 0}
"""
# this is the only part web2py specific!
from gluon import URL, current
request, response = current.request, current.response
res = self.handle_request(URL(), request.env.request_method,
request.args(0), request.args(1), request.vars)
if 'status' in res and res['status'] != 200:
response.status = res['status']
response.headers['Content-Type'] = 'application/json'
return response.json(res, indent=2)+'\n'
示例5: _
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
def _():
# add items menu
create_items = []
registry = application.registry
for content_type in registry:
icon = registry[content_type].get_icon()
name = registry[content_type].get_name()
url = URL('item', 'create.html', args=[content_type])
create_items.append(
(CAT(icon, ' ', name), False, url, [])
)
response.menu += [(T('Add Items'), False, "#", create_items)]
示例6: __init__
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
def __init__(self):
super(Application, self).__init__()
# copy current context
self.db = current.db
self.T = current.T
self.auth = current.auth
self.request = current.request
self.response = current.response
self.session = current.session
self.mail = current.mail
self.conf = current.conf
self.registry = Storage()
self.cache = Cache(self.request)
示例7: has_notifications
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
def has_notifications():
query = (db.notification.id > 0)
query &= (db.notification.seen == False)
query &= (db.notification.to_user == auth.user.id)
nots = db(query).select(db.notification.ALL)
if nots:
return response.json(True)
return response.json(False)
示例8: index
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
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)
示例9: download
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
def download():
"""
allows downloading of uploaded files
http://..../[app]/default/download/[filename]
"""
return response.download(request, db)
示例10: search
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
def search():
if not request.vars.item_per_load:
item_per_load = 5
else:
item_per_load = int(request.vars.item_per_load)
desk = db.desk(session.desk_id)
search_keys = request.vars.search_keys
results = Whoosh().search(search_keys, 1, pagelen=item_per_load+1)
# remove from result the item not accesible for the user
# TODO: e more elegant way of doing this
results = [x for x in results if application.canReadItem(x)]
# --
query = db.item.unique_id.belongs(results)
if request.vars.opt == 'desk':
# search only in desk
query &= db.item.id.belongs(desk.item_list)
item_list = db(
query
).select(
orderby=[~db.item.created_on],
limitby=(0, item_per_load+1)
)
response.view = 'desk/item_list.load'
return locals()
示例11: export
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
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 ''
示例12: process
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
def process(self, **kwargs):
"""
Perform the .validate() method but returns the form
Usage in controllers::
# directly on return
def action():
#some code here
return dict(form=FORM(...).process(...))
You can use it with FORM, SQLFORM or FORM based plugins::
# response.flash messages
def action():
form = SQLFORM(db.table).process(message_onsuccess='Sucess!')
return dict(form=form)
# callback function
# callback receives True or False as first arg, and a list of args.
def my_callback(status, msg):
response.flash = "Success! "+msg if status else "Errors occured"
# after argument can be 'flash' to response.flash messages
# or a function name to use as callback or None to do nothing.
def action():
return dict(form=SQLFORM(db.table).process(onsuccess=my_callback)
"""
kwargs['dbio'] = kwargs.get('dbio', True)
# necessary for SQLHTML forms
self.validate(**kwargs)
return self
示例13: process
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
def process(self, **kwargs):
"""
Perform the .validate() method but returns the form
Usage in controllers::
# directly on return
def action():
#some code here
return dict(form=FORM(...).process(...))
You can use it with FORM, SQLFORM or FORM based plugins::
# response.flash messages
def action():
form = SQLFORM(db.table).process(message_onsuccess='Sucess!')
return dict(form=form)
# callback function
# callback receives True or False as first arg, and a list of args.
def my_callback(status, msg):
response.flash = "Success! "+msg if status else "Errors occured"
# after argument can be 'flash' to response.flash messages
# or a function name to use as callback or None to do nothing.
def action():
return dict(form=SQLFORM(db.table).process(onsuccess=my_callback)
"""
kwargs['dbio'] = kwargs.get('dbio', True) # necessary for SQLHTML forms
self.validate(**kwargs)
return self
示例14: upload_photo
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
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'})
示例15: share
# 需要导入模块: from gluon import current [as 别名]
# 或者: from gluon.current import response [as 别名]
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()