def teamdata(self, request, response, pathmatch): team = Team(id=pathmatch.group('id')) print(team.members()[0]) response.send_template("ajax_teamdata.mustache", { 'team': [team], 'persons': team.members() })
def new_team(self, request, response, pathmatch): if 'name' not in request.params or not request.params['name']: response.send(code=400, body="<p>Nicht alle notwendigen Felder ausgefüllt. 'Name' fehlt.</p>") return persons = [] if 'person' in request.params and request.params['person']: if isinstance(request.params['person'], list): persons = request.params['person'] else: persons = [request.params['person']] team = Team(name=request.params['name'], persons=persons) team.store() response.send(code=200, body="")
def new_person(self, request, response, pathmatch): d=dict() for p in ['firstname', 'lastname', 'email']: if p not in request.params or not request.params[p]: response.send(code=400, body="<p>Nicht alle notwendigen Felder ausgefüllt. {} fehlt.</p>".format(p)) return d[p]=request.params[p] for p in ['hobby', 'team']: if p in request.params and request.params[p]: if isinstance(request.params[p], list): d[p]=request.params[p] else: d[p]=[request.params[p]] else: d[p]=[] person = Person(firstname=d['firstname'], lastname=d['lastname'], email=d['email'], hobbies=d['hobby']) person.store() for tid in d['team']: try: team = Team(id=tid) team.add_person(person) team.store() except Exception: pass response.send(code=200, body="")
def delete_person_team(self, request, response, pathmatch): """Remove a person from an existing team.""" person = Person(id=pathmatch.group('id')) try: team = Team(id=pathmatch.group('teamid')) team.remove_person(person) team.store() response.send(code=200, body="") except Exception: # TODO: raise better exceptions in team model class response.send(code=404, body="Team does not exists.")
def new_person_form(self, request, response, pathmatch): teams = Team.find() response.send_template("ajax_new_person.mustache", locals())
def persondata(self, request, response, pathmatch): person = Person(id=pathmatch.group('id')) response.send_template("ajax_persondata.mustache", {'person': [person], 'teams': person.get_teams(), 'allteams': Team.find()})
def delete_team(self, request, response, pathmatch): team = Team(id=pathmatch.group('id')) team.delete(); response.send(code=200, body="")
def teams(self, request, response, pathmatch): teams = Team.find() response.send_template("ajax_teams.mustache", {'teams': teams})
def teamlist(self, request, response, pathmatch): teams = Team.find() response.send_template("teams.mustache", {})