本文整理匯總了Python中main.PageData.item方法的典型用法代碼示例。如果您正苦於以下問題:Python PageData.item方法的具體用法?Python PageData.item怎麽用?Python PageData.item使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類main.PageData
的用法示例。
在下文中一共展示了PageData.item方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: edititem
# 需要導入模塊: from main import PageData [as 別名]
# 或者: from main.PageData import item [as 別名]
def edititem(item_id=None):
pd = PageData()
if request.method == 'POST':
if 'username' in session:
userid = pd.authuser.uid
else:
userid = 0
if 'desc' in request.form:
if request.form['name'] == '':
flash('No name for this item?')
return redirect_back("/item/new")
try:
item = SiteItem.create(request.form['uid'])
item_id = uid_by_item(request.form['name'])
if not item_id or item_id == int(request.form['uid']):
uid = request.form['uid']
ip = request.remote_addr
if item.name != request.form['name']:
item.name = request.form['name']
item.update()
old = core.digest(item.body())
new = core.digest(request.form['desc'])
# silently discard null edits
if old != new:
new_edit(uid, request.form['desc'], userid, ip)
logger.info('item {} edited by user {} ({})'.format(uid, userid, ip))
else:
logger.info('null edit discarded for item {} by user {} ({})'.format(uid, userid, ip))
return redirect('/item/' + str(uid))
else:
flash(item.name + " already exists!")
item_id = request.form['uid']
except NoItem:
if uid_by_item(request.form['name']):
flash(request.form['name'] + " already exists!")
return redirect_back("/item/new")
uid = new_item(request.form['name'], request.form['desc'], userid, request.remote_addr)
return redirect('/item/' + str(uid))
if item_id:
try:
pd.item = SiteItem.create(item_id)
except NoItem:
return page_not_found()
pd.title="Editing: %s" % pd.item.name
else:
pd.title="Editing: New Item"
return render_template('edititem.html', pd=pd)
示例2: show_item_history
# 需要導入模塊: from main import PageData [as 別名]
# 或者: from main.PageData import item [as 別名]
def show_item_history(item_id):
pd = PageData()
try:
showitem = SiteItem.create(item_id)
except NoItem:
return redirect("/item/" + item_id + "/edit")
pd.title = showitem.name
pd.item = showitem
return render_template('itemhistory.html', pd=pd)
示例3: revert_item_edit
# 需要導入模塊: from main import PageData [as 別名]
# 或者: from main.PageData import item [as 別名]
def revert_item_edit(item_id, edit):
pd = PageData()
try:
item = SiteItem.create(item_id)
item.old = True
item.edit = edit
except NoItem:
return page_not_found()
pd.title="Reverting: " + item.name
pd.item_name = item.name
pd.item = item
return render_template('edititem.html', pd=pd)
示例4: trade
# 需要導入模塊: from main import PageData [as 別名]
# 或者: from main.PageData import item [as 別名]
def trade(username, itemid=None, messageid=None):
pd = PageData()
status = messagestatus['unread_trade']
try:
pd.tradeuser = SiteUser.create(username)
except NoUser:
return page_not_found(404)
if 'username' in session:
if request.method == 'POST':
authuseritems = request.form.getlist('authuseritem')
tradeuseritems = request.form.getlist('tradeuseritem')
message = request.form['body']
subject = request.form['subject']
if 'parent' in request.form:
parent = request.form['parent']
else:
if messageid:
parent = core.deobfuscate(messageid)
messageid = parent
status = messagestatus['unread_pm']
flashmsg = 'Message sent!'
else:
parent = None
messageid = None
flashmsg = 'Submitted trade request!'
if message and subject:
pmid = send_pm(pd.authuser.uid, pd.tradeuser.uid, subject, message, status, parent)
if not messageid:
messageid = pmid
elif tradeuseritems or authuseritems:
flashmsg = 'Trade updated'
for item in authuseritems:
add_tradeitem(item, messageid, pd.authuser.uid, tradeitemstatus['accepted'])
for item in tradeuseritems:
add_tradeitem(item, messageid, pd.tradeuser.uid, tradeitemstatus['unmarked'])
flash(flashmsg)
return redirect('/user/' + pd.authuser.username + '/pm/' + obfuscate(messageid))
if message == '':
flash('Please add a message')
return redirect_back('/')
pd.title = "Trading with {}".format(username)
try:
pd.authuser.ownwant = pd.authuser.query_collection(itemid)
except AttributeError:
pass
try:
pd.tradeuser.ownwant = pd.tradeuser.query_collection(itemid)
pd.item = SiteItem(itemid)
except NoItem:
if messageid:
try:
pd.trademessage = TradeMessage.create(deobfuscate(messageid))
except NoItem:
return page_not_found(404)
else:
return page_not_found(404)
return render_template('trade.html', pd=pd)
示例5: show_item
# 需要導入模塊: from main import PageData [as 別名]
# 或者: from main.PageData import item [as 別名]
def show_item(item_id, edit=None):
"""
:URLs:
* /item/<item_id>/history/<edit>
* /item/<item_id>
:Methods: GET
Setting the accept:application/json header will return JSON.
:Sample response:
.. code-block:: javascript
{
"added": "2016-05-23 20:52:12",
"body": "",
"body_rendered": "",
"description": 384,
"images": [
443,
444
],
"modified": "2016-05-23 20:53:19",
"name": "SSFC",
"tags": {
"FO": false,
"Front Office": true,
"MLS": true,
},
"uid": 388
}
* added - Date added, always UTC
* modified - Late modified, also always UTC
* name - Item's name
* body - raw unrendered description body for the active edit
* body_rendered - rendered content for the active edit
* description - edit identifier
* images - array of image ids associated with this item
* tags - dict of tags, keys are the tag title. the value is a bool which will be set to true if the tag was directly applied and false if inherited.
"""
if item_id is 'new':
return redirect("/item/" + item_id + "/edit")
try:
showitem = SiteItem.create(item_id)
if showitem.deleted:
return page_not_found()
if edit:
edit = int(edit)
showitem.edit = edit
if edit and edit not in [int(i.uid) for i in showitem.history()]:
return page_not_found()
except (NoItem, ValueError):
return page_not_found()
if request_wants_json():
values = showitem.values(edit)
values['body_rendered'] = render_markdown(values['body'])
return json.dumps(values)
else:
pd = PageData()
pd.title = showitem.name
pd.item = showitem
return render_template('item.html', pd=pd)