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)
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']): item.name = request.form['name'] item.update() # todo: check for null edits new_edit(request.form['uid'], request.form['desc'], userid, request.remote_addr) uid = request.form['uid'] flash('Edited item!') 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)
def untag_item(item_id, tag_ob): try: item = SiteItem.create(item_id) except NoItem: return page_not_found() pd = PageData() item.remove_tag(pd.decode(tag_ob)) return redirect('/item/' + str(item.uid))
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)
def reallydelete_item(item_id): try: delitem = SiteItem.create(item_id) except NoItem: return page_not_found() delitem.delete() if request_wants_json(): return '{}' else: return redirect(url_for('index'))
def delete_item(item_id): try: delitem = SiteItem.create(item_id) except NoItem: return page_not_found() pd = PageData() pd.title=delitem.name pd.accessreq = 255 pd.conftext = "Items may take some time to disappear from the indexes." pd.conftarget = "/item/" + str(delitem.uid) + "/reallydelete" pd.conflinktext = "I want to delete '{}' and accept the consequences of this action.".format(delitem.name) return render_template('confirm.html', pd=pd)
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)
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)
def delete_item(item_id): try: delitem = SiteItem.create(item_id) except NoItem: return page_not_found() pd = PageData() pd.title = delitem.name pd.accessreq = 255 pd.conftext = "Deleting item " + delitem.name + ". This will also delete all trades but not the associated PMs. If this item has open trades you are going to confuse people. Are you really sure you want to do this?" pd.conftarget = "/item/" + str(delitem.uid) + "/reallydelete" pd.conflinktext = "Yup, I'm sure" return render_template('confirm.html', pd=pd)
def tagitem(): pd = PageData() if request.method == 'POST': if 'username' in session: userid = pd.authuser.uid else: userid = 0 if 'tag' in request.form: if request.form['tag'] == '': return redirect_back('index') try: item = SiteItem.create(request.form['uid']) item.add_tag(request.form['tag'][:64]) return redirect('/item/' + str(item.uid)) except NoItem: return page_not_found()
def reallydelete_item(item_id): try: delitem = SiteItem.create(item_id) except NoItem: return page_not_found() delitem.delete() if request_wants_json(): return '{}' else: pd = PageData() pd.title = delitem.name + " has been deleted" pd.accessreq = 255 pd.conftext = delitem.name + " has been deleted. I hope you meant to do that." pd.conftarget = "" pd.conflinktext = "" return render_template('confirm.html', pd=pd)
def ownwant(item_id, user_id, values): moditem = SiteItem.create(item_id) # why is this here? OwnWant(item_id, user_id).update(values)
def trade(username, itemid=None, messageid=None): return page_not_found() pd = PageData() status = tradestatus['active_trade'] try: pd.tradeuser = SiteUser.create(username) except NoUser: return page_not_found() 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 = None 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.create(itemid) except NoItem: if messageid: try: pd.trademessage = TradeMessage.create(deobfuscate(messageid)) except NoItem: return page_not_found() else: return page_not_found() return render_template('trade.html', pd=pd)
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 * body_rendered - rendered content * 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 edit: showitem.old = True showitem.edit = edit else: showitem.old = False showitem.edit = None showitem.description_content = showitem.body(edit) except NoItem: return page_not_found() if request_wants_json(): values = showitem.values() 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)
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)