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 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 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)
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)