Exemplo n.º 1
0
 def add_hobby(self, request, response, pathmatch):
     person = Person(id=pathmatch.group('id'))
     hobby = unquote(pathmatch.group('hobby'))  # path parts aren't decoded by server framework
     if hobby not in person.get_hobbies():
         person.hobbies.append(hobby)
         person.store()
     response.send(code=200, body="")
Exemplo n.º 2
0
    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="")
Exemplo n.º 3
0
 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.")
Exemplo n.º 4
0
 def delete_hobby(self, request, response, pathmatch):
     person = Person(id=pathmatch.group('id'))
     hobbies = person.get_hobbies()
     try:
         hobby = unquote(pathmatch.group('hobby'))  # path parts aren't decoded by server framework
         hobbies.remove(hobby)
         person.hobbies = hobbies
         person.store()
         response.send(code=200, body="")
     except ValueError:
         response.send(code=404, body="<p>Fehler: Hobby '{}' nicht gefunden.</p>".format(hobby))
Exemplo n.º 5
0
 def delete_person(self, request, response, pathmatch):
     person = Person(id=pathmatch.group('id'))
     person.delete()
     response.send(code=200, body='')
Exemplo n.º 6
0
 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()})
Exemplo n.º 7
0
 def persons(self, request, response, pathmatch):
     persons = Person.find()
     response.send_template("ajax_persons.mustache", {'persons': persons})
Exemplo n.º 8
0
 def new_team_form(self, request, response, pathmatch):
     persons = Person.find()
     response.send_template("ajax_new_team.mustache", locals())
Exemplo n.º 9
0
 def teamdata(self, request, response, pathmatch):
     team = Team(id=pathmatch.group('id'))
     response.send_template("ajax_teamdata.mustache", {'team': [team], 'persons': team.members(), 'allpersons': Person.find()})