Example #1
0
    def post(self):
        data = self.parser.parse_args()

        if data["form_type"] == "add":

            # since put it will update regardless
            # TODO delete
            if PeopleModel.find_person(data['user']):
                return {'message': "This user already exists"}, 400

            person = PeopleModel(data["user"])
            try:
                person.save_to_db()
            except Exception as e:
                return {
                    "message": "An error occurred while saving the item.",
                    "error": "{}".format(e)
                }, 500

            return redirect(url_for("home"))

        elif data["form_type"] == "del":
            person = PeopleModel.find_person(data['user'])
            if person:
                try:
                    person.delete_from_db()
                except Exception as e:
                    return {
                        "message": "An error occurred while deleting",
                        "error": "{}".format(e)
                    }, 500
            else:
                return {'message': "Doesn't exist."}, 400

            return redirect(url_for("home"))
Example #2
0
def people():
    p = PeopleModel.query.all()

    # POST method is used when you want to tell the server to accept
    # blocks of data, usually to create something.
    if request.method == 'POST':
        first_name = request.form['fname']
        last_name = request.form['lname']
        gender = request.form['gender']
        email = request.form['email']
        phone = request.form['phone']

        # to confirm whether we are actually getting user's input from
        # the html form, we print the variable name eg
        print(first_name)
        print(last_name)
        print(gender)
        print(email)
        print(phone)

        # create an instance of the PeopleModel class and pass in the data you want to send to the db
        person = PeopleModel(first_name=first_name,
                             last_name=last_name,
                             gender=gender,
                             email=email,
                             phone_number=phone)
        # call the create record method to insert the record in the database.
        person.create_record()

        return redirect(url_for('people'))

        #to confirm that we have actually inserted the record we are going to print out a string.
        print('Imeingia')

    return render_template('people.html', x=p)
Example #3
0
    def put(self, name, **kwargs):
        data = People.parser.parse_args()

        person = PeopleModel.find_by_name(name)

        if person:
            person.role = data['role']
            person.email = data['email']
        else:
            person = PeopleModel(name, **data)

        person.save_to_db()

        return person.json(), 201
Example #4
0
    def post(self, name, **kwargs):
        if PeopleModel.find_by_name(name):
            return {
                'message': f"A person with name '{name}' already exists"
            }, 400

        data = People.parser.parse_args()

        person = PeopleModel(name, **data)

        try:
            person.save_to_db()
        except Exception as e:
            return {"message": f"An error occurred: {e}"}, 500

        return person.json(), 201
    def put(self, name):
        data = Character.parser.parse_args()

        character = PeopleModel.find_by_name(name)
        updated_character = PeopleModel(name, data['Id'], data['isAlive'],
                                        data['placeId'], data['isKing'])

        if character is None:
            try:
                updated_character.insert()
            except:
                return {"message": "Error al añadir el personaje"}, 500
        else:
            try:
                updated_character.update()
            except:
                return {"message": "Error al actualizar el personaje"}, 500
        return character  #Return el character actualizado/creado para reflejar el cambio
    def post(self, name):
        #Si el usuario intenta crear un personaje ya existente en la base de datos, la solicitud del usuario es incorrecta. Hay que avisar al usuario, y devolver el codigo 400 (bad-request)
        if PeopleModel.find_by_name(name):
            return {
                'message': 'El personaje ' + str(name) + ' ya existe.'
            }, 400

        data = Character.parser.parse_args()
        character = PeopleModel(name, data['Id'], data['isAlive'],
                                data['isKing'], data['placeId'])
        try:
            character.insert()
            return character.json()
        except:
            return {
                'message':
                'Error al intentar añadir el personaje a la base de datos'
            }, 500  #Http: Devolvemos un internal-server-error
#!/usr/bin/python
import rospy
from models.people import PeopleModel

if __name__ == "__main__":

    try:
        rospy.init_node('model_people', anonymous=True)
        node = PeopleModel()
        rospy.spin()
    except rospy.ROSInterruptException:
        pass
Example #8
0
 def __init__(self, reader: AbstractReader):
     self.planet = PlanetsModel(reader)
     self.people = PeopleModel(reader)
     self.vehicle = VehicleModel(reader)
     self.specie = SpecieModel(reader)
     self.starship = StarshipModel(reader)