Example #1
0
def create_tables():
    db.create_all()

    if len([item for item in UserRightModel.find_all()]) == 0:
        # we need to create Rights only once!
        right = UserRightModel('blocked')
        right.save_to_db()
        right = UserRightModel('customer')
        right.save_to_db()
        right = UserRightModel('operator')
        right.save_to_db()
        right = UserRightModel('chief operator')
        right.save_to_db()
        right = UserRightModel('manager')
        right.save_to_db()
        right = UserRightModel('regional manager')
        right.save_to_db()
        right = UserRightModel('admin')
        right.save_to_db()

    if len([item for item in CountryModel.find_all()]) == 0:
        country = CountryModel("USA")
        country.save_to_db()
        country = CountryModel("Germany")
        country.save_to_db()
        country = CountryModel("Finland")
        country.save_to_db()
        country = CountryModel("UK")
        country.save_to_db()
    if len([item for item in UserModel.find_all()]) == 0:
        user = UserModel("*****@*****.**", "test")
        user.right_id = 7
        user.save_to_db()
        user = UserModel("*****@*****.**", "test")
        user.right_id = 3
        user.save_to_db()
        user = UserModel("*****@*****.**", "test")
        user.right_id = 2
        user.save_to_db()
Example #2
0
 def get(self):
     users = user_list_schema.dump(UserModel.find_all())
     return {'users': users}
Example #3
0
 def get(self):
     items = UserModel.find_all()
     if items:
         return {"users": [item.json() for item in items]}, 200
     return {"message": "Users not found."}, 404