# Path: project/admin/views.py
# class ModelView(DefaultModelView):
# 
#     column_auto_select_related = True
# 
#     def __init__(self, model, session, basic_auth, *args, **kwargs):
#         super(ModelView, self).__init__(model, session, *args, **kwargs)
#         self.basic_auth = basic_auth
# 
#     def is_accessible(self):
#         if not self.basic_auth.authenticate():
#             raise BasicAuthException('Not authenticated.')
#         else:
#             return True
# 
#     def inaccessible_callback(self, name, **kwargs):
#         return redirect(self.basic_auth.challenge())
# 
# Path: project/user/services/reset_user_password_service.py
# class ResetUserPasswordService:
# 
#     def __init__(self, user, new_password=b"password"):
#         self.user = user
#         self.new_password = new_password
# 
#     def call(self):
#         self.user.password = generate_password_hash(self.new_password).decode('utf-8')
#         db.session.commit()
#         return self.user.password
# 
# Path: project/user/services/generate_user_api_key_service.py
# class GenerateUserApiKeyService:
# 
#     def __init__(self, user, size=32):
#         self.user = user
#         self.size = size
# 
#     def call(self):
#         """
#         For given size, generate random string with all ascii and digits
#         """
#         self.user.api_key = secrets.token_hex(self.size)
#         db.session.commit()
#         return self.user.api_key


from project.admin.views import ModelView
from project.user.services.reset_user_password_service import ResetUserPasswordService
from project.user.services.generate_user_api_key_service import GenerateUserApiKeyService
# !/usr/bin/python
# -*- coding: utf-8 -*-
# Example Admin ModelView: https://github.com/mrjoes/flask-admin/blob/master/examples/sqla/app.py


class UserView(ModelView):

    form_excluded_columns = ['api_key']

    column_exclude_list = ['password']


# Path: project/admin/views.py
# class ModelView(DefaultModelView):
# 
#     column_auto_select_related = True
# 
#     def __init__(self, model, session, basic_auth, *args, **kwargs):
#         super(ModelView, self).__init__(model, session, *args, **kwargs)
#         self.basic_auth = basic_auth
# 
#     def is_accessible(self):
#         if not self.basic_auth.authenticate():
#             raise BasicAuthException('Not authenticated.')
#         else:
#             return True
# 
#     def inaccessible_callback(self, name, **kwargs):
#         return redirect(self.basic_auth.challenge())
# 
# Path: project/user/services/reset_user_password_service.py
# class ResetUserPasswordService:
# 
#     def __init__(self, user, new_password=b"password"):
#         self.user = user
#         self.new_password = new_password
# 
#     def call(self):
#         self.user.password = generate_password_hash(self.new_password).decode('utf-8')
#         db.session.commit()
#         return self.user.password
# 
# Path: project/user/services/generate_user_api_key_service.py
# class GenerateUserApiKeyService:
# 
#     def __init__(self, user, size=32):
#         self.user = user
#         self.size = size
# 
#     def call(self):
#         """
#         For given size, generate random string with all ascii and digits
#         """
#         self.user.api_key = secrets.token_hex(self.size)
#         db.session.commit()
#         return self.user.api_key


# Path: project/user/admin/views.py
from project.admin.views import ModelView
from project.user.services.reset_user_password_service import ResetUserPasswordService
from project.user.services.generate_user_api_key_service import GenerateUserApiKeyService

# !/usr/bin/python
# -*- coding: utf-8 -*-
# Example Admin ModelView: https://github.com/mrjoes/flask-admin/blob/master/examples/sqla/app.py


class UserView(ModelView):

    form_excluded_columns = ['api_key']

    column_exclude_list = ['password']


    column_display_all_relations = True