def post(self, *args, **kwargs): form = Form( uuid="Weapon not found", ) if form.validate(self.request.arguments): user = self.get_current_user() weapon = ArmoryWeapon.by_uuid(self.request.arguments['uuid'][0]) if user == None or weapon == None: self.render("store/weapons.html", errors=None, weapons=ArmoryWeapon.get_all_visible()) elif user.gold < weapon.cost: self.render("store/weapons.html", errors=['You cannot afford this weapon'], weapons=ArmoryWeapon.get_all_visible()) else: user.gold -= weapon.cost new_weapon = Weapon( user_id=user.id, name=weapon.name, description=weapon.description, required_level=weapon.required_level, damage=weapon.damage, rating=weapon.rating, advanced=weapon.advanced, classification=weapon.classification, avatar=weapon.avatar, ) self.dbsession.add(new_weapon) self.dbsession.add(user) self.dbsession.flush() self.render("store/purchase.html", item=weapon.name) else: self.render("store/weapons.html", errors=form.errors, weapons=ArmoryWeapon.get_all_visible())
def get(self, *args, **kwargs): ''' Sends item details via ajax ''' try: classification = self.get_argument("cls") uuid = self.get_argument("uuid") except: self.write(json.dumps({"Error": "Missing parameter"})) return if classification == "weapon": weapon = ArmoryWeapon.by_uuid(uuid) details = { 'Name': weapon.name, 'Description': weapon.description, 'Avatar': weapon.avatar, 'RequiredLevel': weapon.required_level, 'Rating': weapon.rating, 'Damage': weapon.damage, 'Advanced': str(weapon.advanced), 'Classification': weapon.classification, } self.write(json.dumps(details)) elif classification == "armor": armor = ArmoryArmor.by_uuid(uuid) details = { 'Name': armor.name, 'Description': armor.description, 'RequiredLevel': armor.required_level, 'Avatar': armor.avatar, 'Rating': armor.rating, 'Classification': armor.classification, } self.write(json.dumps(details)) else: self.write(json.dump({"Error": "Item not found"})) self.finish()
def get(self, *args, **kwargs): ''' Renders weapons store page ''' self.render("store/weapons.html", errors=None, weapons=ArmoryWeapon.get_all_visible())