def pm(username): pd = PageData() try: pd.recipient = SiteUser.create(username) except (NoItem, NoUser): return page_not_found(404) if 'username' in session: if request.method == 'POST': message = request.form['body'] subject = request.form['subject'] if 'parent' in request.form: parent = deobfuscate(request.form['parent']) else: parent = None if message and subject: messageid = send_pm(pd.authuser.uid, pd.recipient.uid, subject, message, messagestatus['unread_pm'], parent) if messageid: flash('Message sent!') if parent: return redirect_back('/user/' + username + '/pm') else: return redirect('/user/' + pd.authuser.username + '/pm/' + obfuscate((messageid))) else: # TODO re-fill form flash('No message or subject') return redirect_back('/user/' + username + '/pm') return render_template('sendpm.html', pd=pd)
def pm_action(username, messageid, action): """ :URL: /user/<username>/pm/<messageid>/<action> :Methods: GET, POST :Actions: * read * unread * delete * undelete Setting the accept:application/json header will return JSON instead of a redirect. """ pd = PageData() dmid = deobfuscate(messageid) if not 'username' in session or pd.authuser.username != username or dmid is None: return render_template('pm_error.html', pd=pd) pm = TradeMessage.create(dmid) if action == 'read': pm.read(pd.authuser.username) elif action == 'unread': pm.unread(pd.authuser.username) elif action == 'delete': pm.delete(pd.authuser.username) elif action == 'undelete': pm.undelete(pd.authuser.username) if request_wants_json(): return '{}' else: return redirect_back('/')
def pm_action(username, messageid, action): """ :URL: /user/<username>/pm/<messageid>/<action> :Methods: GET :Actions: * read * unread * delete * undelete Setting the accept:application/json header will return JSON instead of a redirect. """ pd = PageData() dmid = deobfuscate(messageid) if not 'username' in session or pd.authuser.username != username or dmid is None: return render_template('pm_error.html', pd=pd) pm = TradeMessage.create(dmid) if action == 'read': pm.read(pd.authuser.username) elif action == 'unread': pm.unread(pd.authuser.username) elif action == 'delete': pm.delete(pd.authuser.username) elif action == 'undelete': pm.undelete(pd.authuser.username) if request_wants_json(): return '{}' else: return redirect_back('/')
def accepttradeitem(username, messageid, action, item=None): return page_not_found() pd = PageData() if not pd.authuser.username == username: return page_not_found() if 'username' in session: if item: try: ti = TradeItem(item) except NoItem: return page_not_found() if action == "accept": ti.accept() elif action == "reject": ti.reject() else: return page_not_found() else: try: t = TradeMessage.create(deobfuscate(messageid)) except NoItem: return page_not_found() if action == "settle": t.settle() elif action == "cancel": t.cancel() elif action == "reject": t.reject() elif action == "reopen": # FIXME pass elif action == "add": flash('Coming soon...') return redirect_back('/') else: return page_not_found() return redirect_back('index')
def pm(username): pd = PageData() try: pmuser = SiteUser.create(username) except (NoItem, NoUser): return page_not_found() if 'username' in session: if session['username'] == username: pd.profileuser = pmuser return render_template('profile/messages.html', pd=pd) else: pd.recipient = pmuser if request.method == 'POST': message = request.form['body'] subject = request.form['subject'] if 'parent' in request.form: parent = deobfuscate(request.form['parent']) else: parent = None if message and subject: messageid = send_pm(pd.authuser.uid, pd.recipient.uid, subject, message, None, parent) if messageid: flash('Message sent!') if parent: return redirect_back('/user/' + username + '/pm') else: return redirect('/user/' + pd.authuser.username + '/pm/' + obfuscate((messageid))) else: # TODO re-fill form flash('No message or subject') return redirect_back('/user/' + username + '/pm') return render_template('sendpm.html', pd=pd)
def viewpm(username, messageid): pd = PageData() dmid = deobfuscate(messageid) if not 'username' in session or pd.authuser.username != username or dmid is None: return render_template('pm_error.html', pd=pd) if 'username' in session: pm = TradeMessage.create(dmid) if pm.delete_status(session['username']): return render_template('pm_error.html', pd=pd) if session['username'] is pm.to_user: pd.tradeuser = pm.from_user pm.read(pm.to_user) else: pd.tradeuser = pm.to_user pd.pm = pm pd.title = pm.subject return render_template('pm.html', pd=pd)
def viewpm(username, messageid): pd = PageData() dmid = deobfuscate(messageid) if not 'username' in session or pd.authuser.username != username or dmid is None: return render_template('pm_error.html', pd=pd) if 'username' in session: pm = TradeMessage.create(dmid) if pm.messagestatus < messagestatus['unread_pm']: pm = TradeMessage.create(messageid) if session['username'] is pm.to_user: pd.tradeuser = pm.from_user pm.read() else: pd.tradeuser = pm.to_user pd.pm = pm pd.title = pm.subject return render_template('pm.html', pd=pd)
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)