Exemplo n.º 1
0
    def put(self, id):
        data = Person.parser.parse_args()
        person = PersonModel.find_by_id(id)
        current_user = current_identity.id

        if person:
            person.name = data['name']
            person.admin = current_user
        else:
            person = PersonModel(name=data['name'], admin=current_user)

        person.save_to_db()
        return person.json(), 200
Exemplo n.º 2
0
    def post(self):
        current_user = current_identity.id
        data = CreatePerson.parser.parse_args()
        person = PersonModel(name=data['name'], admin=current_user)

        if PersonModel.find_by_name(data['name']):
            return {
                'message':
                "A person with name '{}' already exists.".format(data['name'])
            }, 400

        person.save_to_db()
        return person.json(), 201
Exemplo n.º 3
0
    def post(self, name):
        if PersonModel.find_by_name(name):
            return {
                'message':
                "A person with name '{}' already exists.".format(name)
            }, 400

        current_user = current_identity.id
        person = PersonModel(name=name, admin=current_user)
        try:
            person.save_to_db()
        except:
            return {"message": "An error occurred creating the site."}, 500

        return person.json(), 201