示例#1
0
def add():
    trader1 = getUserByField('username', str(session['user']))
    requestList = [i.details['name'] for i in trader1.enumerateWantedMerch()]
    tradingList = [x.details['name'] for x in trader1.enumerateMerch()]
    return render_template('add.html',
                           user=session['user'],
                           tradingList=tradingList,
                           requestList=requestList)
示例#2
0
def delete():
    r = request.form['value']
    r = r.replace(' ', '').strip('\n')
    trader1 = getUserByField('username', str(session['user']))
    item = [i.details['name'] for i in trader1.enumerateMerch()]
    ite = [i for i in trader1.enumerateMerch()]
    i = item.index(str(r))
    remove = ite[i]
    trader1.destroyMerch(remove)
    return 'OK'
示例#3
0
def addItemGet():
    item = str(request.form['item'])
    trader1 = getUserByField('username', str(session['user']))
    item = Merchandise({'name': item})
    trader1.addWantedMerch(item)
    return 'OK'
示例#4
0
#!/usr/bin/env python2

from trader import Merchandise, Trader, getUserByField


# This registers graboy and grebby and returns them. If you want instances of
# pre-existing users, use Merchandise.getTrader(), or specify how I should give
# them to you.

# user1 = Trader({'username': '******', 'password': '******'})
# user2 = Trader({'username': '******', 'password': '******'})

# This gets registered users
user1 = getUserByField('username', 'graboy')
user2 = getUserByField('username', 'grebby')

# The dictionary you pass it is stored in .details
apple = Merchandise({'name': 'apple'})
grape = Merchandise({'name': 'grape'})
pear  = Merchandise({'name': 'pear'})
pumpkin  = Merchandise({'name': 'pumpkin'})

# e.g.: apple.details['name'] == 'apple'

# createMerch: called when a user wants to put a new item of theirs up for
# trade.
user1.createMerch(apple) 
user1.createMerch(pear) 

user2.createMerch(grape) 
user2.createMerch(pumpkin)