def _save_character(form, key, value, section, survey): """Save characters with metadata.""" index = key.split('_')[1] # Since our form is immutable, we may wind up with additional responses; # If we've already saved this index, skip saving it again. if int(index) in map(lambda x: x.index, survey.overview.characters): return # Retrieve species data. species_category = form.getlist('chr_{}_category'.format(index)) species_text = form.get('chr_{}_species'.format(index), ', '.join(species_category)) reason = form.get('chr_{}_reason'.format(index), '') primary_character = form.get('chr_{}_primary'.format(index), '') != '' deprecated_character = \ form.get('chr_{}_deprecated'.format(index), '') != '' # Do not save blank species. if not species_category and not species_text: return survey.overview.characters.append( models.Character(index=index, species_category=species_category, species_text=models.PotentiallySubjectiveResponse( subjective=True, value=species_text[:2000]), primary_character=primary_character, deprecated_character=deprecated_character, reason=models.PotentiallySubjectiveResponse( subjective=True, value=reason[:2000])))
def init_db(): import models db.create_all() db.session.add_all([models.City(name=city_name, color=city_color) for city_name,city_color in constants.CITIES.items()]) db.session.add_all([models.Character(name=name, first_name=first_name, middle_name=middle_name, icon=icon) for name,(first_name,middle_name,icon) in constants.CHARACTERS.items()]) db.session.commit()
def unit_test_character(): obj = data["Character"] c = models.Character(obj["type"], obj["integrity"], obj["description"], obj["inventory_limit"], "character name") assert c.name() == "character name" assert c.pickItem("a") == True assert c.pickItem("b") == True assert c.inventory() == ["a", "b"] assert c.pickItem("c") == True assert c.pickItem("d") == False assert c.dropItem(1) == True assert c.inventory() == ["a", "c"] assert c.kind() == obj["type"] assert c.loseIntegrity() == True assert c.integrity() == obj["integrity"]-1 assert c.description == obj["description"]
def test_character_insert(db): test_character = { "name": "Kieran", "titles": "Lord of the Python Tests", "father": "OOP", "mother": "JavaScript", "spouse": "Madam Tests.py", "house": "Slytherin", "actor": "Himself", "imageLink": "-" } c = models.Character(**test_character) db.session.add(c) result = db.session.query( models.Character).filter(models.Character.name == "Kieran").first() TESTOR.assertEqual(result.titles, "Lord of the Python Tests") TESTOR.assertEqual(result.father, "OOP") TESTOR.assertEqual(result.mother, "JavaScript") TESTOR.assertEqual(result.spouse, "Madam Tests.py") TESTOR.assertEqual(result.house, "Slytherin") TESTOR.assertEqual(result.actor, "Himself")
def getCharacters(filterList): #NOTE: There are several pages of characters for each character class # as such, we will just guess up to 10 pages of characters, and stop iteration if no characters exist on a page #Similarly, we dont know the rarity of each character without search for the rarity #explicity, so we must iterate once for each rarity to pull that information #Similarly, we dont know the type of character (AKA Defender), so we must use that as a search term too characters = [] for classId in CHARACTER_CLASSES: for characterType in CHARACTER_TYPES: for rarity in RARITIES: for page in range(10): if page == 0: continue #there is no page 0 parser = beautifulsoup_helper.getParserForUrl(BASE_URL + '/character_list?id=%d&type=%d&rare=%s&p=%d' % (classId, characterType, rarity, page)) characterRows = parser.find_all(class_='character') for charRow in characterRows: character = models.Character(charRow, classId, rarity, characterType) if filterList and len(filterList) > 0 and character.Id not in filterList: print "Skipping due to not being in filter list %s" % filterList continue print 'merging character specific details %s' % character.Id loadMoreCharacterDetail(character) characters.append(character) if len(filterList) > 0: break; #filter list has stuff in it, no need to process any more than one record else: break #if there are no character rows, break the iteration early return characters
from flask import abort from flask_restful import Resource, reqparse import models, parsers, config character_model = models.Character() class ModelResource(Resource): model = None def get(self, id): if not self.model.exists(id): abort(404, 'Resource does not exist.') return self.model.get(id) class ModelListResource(Resource): model = None def get(self, limit=config.PAGINATION_MAX_ELEMS_PER_PAGE): args = parsers.pagination_parser.parse_args() results = self.model.all()[limit * (args['page'] - 1):limit * args['page']] return { 'count': len(self.model.all()), 'page': args['page'], 'next': len(self.model.all()) > limit * args['page'], 'previous': args['page'] > 1,
def json_to_media_cast_member(node): return models.MediaCastMember(character=models.Character( name=node['character'], cast_order=int(node['order']), ), talent_id=node['id'])
import random import messages import models from components import DocumentPlanner, Realizer eggs = models.Object(name='eggs') sleep = models.Action(name='sleep', transitive=False) get_eggs = models.Action(name='get eggs', transitive=True, obj=eggs) henry = models.Character(name=models.Name(name='Henry', proper=True), gender='male', age=25, transit_modes=['walk', 'bike', 'drive', 'bus'], posture='standing', desires=[get_eggs]) home = models.Location( name=models.Name(name='home', proper=True), size='building', satisfies=[], ) bedroom = models.Location( name=models.Name(name='bedroom', proper=False), size='room', satisfies=[sleep], objects_present=[ models.Object(name=models.Name(name='bed', proper=False)), models.Object(name=models.Name(name='desk', proper=False)), models.Object(name=models.Name(name='chair', proper=False)),
) adam.set_password('adampassword') parker = models.User( username='******', email='*****@*****.**', displayname='Parker' ) parker.set_password('parkerpassword') db.session.add(parker) db.session.add(adam) db.session.commit() # Create Character hector = models.Character(name='Hector Barrelwaite') hector.player_id = parker.id beatty = models.Character(name='Elsinore Beatty', tactician=0, level_headed=2) beatty.player_id = parker.id eclipse = models.Character(name='The Eclipse', tactician=2, level_headed=0, quick=True, hesitant=False) eclipse.player_id = parker.id sukorb = models.Character(name='Sukorb Tsif') sukorb.player_id = adam.id db.session.add(hector) db.session.add(beatty) db.session.add(eclipse) db.session.add(sukorb) db.session.commit() # Create System
def save(): c = models.Character(1, char1.stringifyStats(), char2.stringifyStats()) db.session.add(c) db.session.commit() return "Save successful"