本文整理匯總了Python中gluon.HTTP屬性的典型用法代碼示例。如果您正苦於以下問題:Python gluon.HTTP屬性的具體用法?Python gluon.HTTP怎麽用?Python gluon.HTTP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類gluon
的用法示例。
在下文中一共展示了gluon.HTTP屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: index
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [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)
示例2: __oauth_login
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [as 別名]
def __oauth_login(self, next):
"""
This method redirects the user to the authenticating form
on authentication server if the authentication code
and the authentication token are not available to the
application yet.
Once the authentication code has been received this method is
called to set the access token into the session by calling
accessToken()
"""
token = self.accessToken()
if not token:
current.session.redirect_uri = self.__redirect_uri(next)
data = dict(redirect_uri=current.session.redirect_uri,
response_type='code',
client_id=self.client_id)
if self.args:
data.update(self.args)
auth_request_url = self.auth_url + "?" + urlencode(data)
raise HTTP(302,
"You are not authenticated: you are being redirected to the <a href='" + auth_request_url + "'> authentication server</a>",
Location=auth_request_url)
return
示例3: index
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [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)
示例4: diff
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [as 別名]
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()
示例5: wrapper
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [as 別名]
def wrapper(f):
def g(data):
try:
output = f(data)
return XML(ouput)
except (TypeError, ValueError) as e:
raise HTTP(405, '%s serialization error' % e)
except ImportError as e:
raise HTTP(405, '%s not available' % e)
except Exception as e:
raise HTTP(405, '%s error' % e)
return g
示例6: pdflatex_from_html
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [as 別名]
def pdflatex_from_html(html):
if os.system('which pdflatex > /dev/null') == 0:
markmin = TAG(html).element('body').flatten(markmin_serializer)
out, warnings, errors = markmin2pdf(markmin)
if errors:
current.response.headers['Content-Type'] = 'text/html'
raise HTTP(405, HTML(BODY(H1('errors'),
UL(*errors),
H1('warnings'),
UL(*warnings))).xml())
else:
return XML(out)
示例7: __build_url_opener
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [as 別名]
def __build_url_opener(self, uri):
"""
Build the url opener for managing HTTP Basic Athentication
"""
# Create an OpenerDirector with support
# for Basic HTTP Authentication...
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(realm=None,
uri=uri,
user=self.client_id,
passwd=self.client_secret)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
return opener
示例8: wrapper
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [as 別名]
def wrapper(f):
def g(data):
try:
output = f(data)
return XML(ouput)
except (TypeError, ValueError), e:
raise HTTP(405, '%s serialization error' % e)
except ImportError, e:
raise HTTP(405, '%s not available' % e)
except Exception, e:
raise HTTP(405, '%s error' % e)
return g
示例9: create
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [as 別名]
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()
示例10: meta
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [as 別名]
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()
示例11: changelog
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [as 別名]
def changelog():
"""
Show item change log over the time
"""
item = application.getItemByUUID(request.args(0))
if item is None:
raise HTTP(404)
query = (db.item_archive.current_record == item.id)
db.item_archive.modified_on.label = T('Date & Time')
db.item_archive.modified_on.readable = True
db.item_archive.modified_by.label = T('User')
db.item_archive.modified_by.readable = True
fields = [
db.item_archive.modified_on,
db.item_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.item_archive.modified_on],
fields=fields,
args=request.args[:1],
create=False, editable=False, details=False, deletable=False,
searchable=False,
csv=False,
links=links,
)
return dict(item=item, changes=changes)
示例12: diff
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [as 別名]
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)
示例13: changelog
# 需要導入模塊: import gluon [as 別名]
# 或者: from gluon import HTTP [as 別名]
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()