def post(self): parser = reqparse.RequestParser( ) # create parameters parser from request # define al input parameters need and its type parser.add_argument(n.USR, type=str, required=True, help="Username") parser.add_argument(n.PSW, type=str, required=True, help="Password") data = parser.parse_args() with lock.lock: user = AccountsModel.find_by_username(data[n.USR]) if user: return {n.MSG: "User already in database"}, 400 user = AccountsModel(data[n.USR]) user.hash_password(data[n.PSW]) user.save_to_db() return user.json(), 200
new_artist2 = ArtistModel('Txarango', 'Spain', 'POP') db.session.add(new_artist2) new_artist3 = ArtistModel('Bad Gyal', 'Spain', 'TRAP') db.session.add(new_artist3) new_artist4 = ArtistModel('Billie Eilish', 'USA', 'INDIE') db.session.add(new_artist4) new_event1 = EventModel('Festival Cruilla 2020', 'Parc del Forum', 'Barcelona', '2020-07-03', 60, 15000) new_event1.artists.append(new_artist1) new_event1.artists.append(new_artist2) db.session.add(new_event1) new_event2 = EventModel('Canet Rock 2020', 'Canet de Mar Beach', 'Barcelona', '2020-07-05', 45, 35000) new_event2.artists.append(new_artist1) new_event2.artists.append(new_artist4) db.session.add(new_event2) new_user1 = AccountsModel(username='******') new_user1.hash_password('1234') db.session.add(new_user1) new_user1 = AccountsModel(username='******', is_admin=1) new_user1.hash_password('admin') db.session.add(new_user1) db.session.commit() db.session.close()