class UserUsedExperimentPanel(InstructorModelView): can_edit = can_delete = can_create = False column_searchable_list = ('origin', ) column_list = [ 'user', 'experiment', 'start_date', 'end_date', 'origin', 'city', 'country' ] column_labels = dict(user=lazy_gettext("User"), experiment=lazy_gettext("Experiment"), start_date=lazy_gettext("Start date"), end_date=lazy_gettext("End date"), origin=lazy_gettext("Origin"), city=lazy_gettext("City"), country=lazy_gettext("Country")) column_filters = ('user', 'start_date', 'end_date', 'experiment', 'origin', 'coord_address') def __init__(self, session, **kwargs): super(UserUsedExperimentPanel, self).__init__(model.DbUserUsedExperiment, session, **kwargs) def search_placeholder(self): return gettext("Search") def get_query(self): query = super(UserUsedExperimentPanel, self).get_query() query = apply_instructor_filters_to_logs(self, self.session, query) return query def get_count_query(self): query = super(UserUsedExperimentPanel, self).get_count_query() query = apply_instructor_filters_to_logs(self, self.session, query) return query
class MyAccessesPanel(admin_views.UserUsedExperimentPanel): column_list = ('experiment', 'start_date', 'end_date', 'origin', 'details') column_filters = ('start_date', 'end_date', 'experiment', 'origin') column_labels = dict(experiment=lazy_gettext("Experiment"), start_date=lazy_gettext("Start date"), end_date=lazy_gettext("End date"), origin=lazy_gettext("Origin"), details=lazy_gettext("Details")) def is_accessible(self): return get_app_instance(self).get_user_information() is not None def _apply_filters(self, query): permissions = get_app_instance(self).get_permissions() # TODO: take permissions and if it says "do not use other logs", only show those logs # of the current IP address. This would be useful for the demo. user_information = get_app_instance(self).get_user_information() user = self.session.query( model.DbUser).filter_by(login=user_information.login).one() return query.filter_by(user=user) def get_query(self): query = super(MyAccessesPanel, self).get_query() return self._apply_filters(query) def get_count_query(self): query = super(MyAccessesPanel, self).get_count_query() return self._apply_filters(query) def get_files_query(self, id): uf = super(MyAccessesPanel, self).get_file(id) if uf is None: return None user_information = get_app_instance(self).get_user_information() user = self.session.query( model.DbUser).filter_by(login=user_information.login).one() if uf.experiment_use.user == user: return uf return None
class ProfileEditForm(Form): full_name = DisabledTextField(lazy_gettext("Full name:")) login = DisabledTextField(lazy_gettext(u"Login:"******"E-mail:")) facebook = TextField( lazy_gettext(u"Facebook id:"), description=lazy_gettext("Facebook identifier (number)."), validators=[NumberRange(min=1000)]) password = PasswordField(lazy_gettext(u"Password:"******"Password."))
def __init__(self, app, cfg_manager, core_server, bypass_authz = False): super(AdministrationApplication, self).__init__() app.json_encoder = CustomJSONEncoder self.cfg_manager = cfg_manager pub_directory = os.path.join(os.path.abspath(self.cfg_manager.get('deployment_dir', '')), 'pub') self.config = cfg_manager db.initialize(cfg_manager) self.core_server = core_server db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=db.engine)) files_directory = cfg_manager.get_doc_value(configuration_doc.CORE_STORE_STUDENTS_PROGRAMS_PATH) core_server_url = cfg_manager.get_value( 'core_server_url', '' ) self.script_name = urlparse.urlparse(core_server_url).path.split('/weblab')[0] or '' self.app = app static_folder = os.path.abspath(os.path.join(os.path.dirname(web.__file__), 'static')) # Not allowed @app.route('/weblab/not_allowed') def not_allowed(): return "You are logged in, but not allowed to see this content. Please log in with a proper account" # Back @app.route('/weblab/back') def back_to_client(): return redirect(url_for('core_webclient.labs')) ################################################ # # Administration panel for administrators # # admin_url = '/weblab/admin' category_system = lazy_gettext("System") category_users = lazy_gettext("Users") category_logs = lazy_gettext("Logs") category_experiments = lazy_gettext("Experiments") category_permissions = lazy_gettext("Permissions") self.admin = Admin(index_view = admin_views.HomeView(db_session, url = admin_url),name = lazy_gettext('WebLab-Deusto Admin'), url = admin_url, endpoint = admin_url, base_template = 'weblab-master.html', template_mode = 'bootstrap3') self.admin.weblab_admin_app = self self.admin.add_view(admin_views.SystemProperties(db_session, category = category_system, name = lazy_gettext('Settings'), endpoint = 'system/settings', url='settings')) self.admin.add_view(admin_views.AuthsPanel(db_session, category = category_system, name = lazy_gettext('Authentication'), endpoint = 'system/auth', url='auth')) if not os.path.exists(pub_directory): try: os.mkdir(pub_directory) except (IOError, OSError) as e: print("WARNING: %s not found. Create it to upload files to it." % pub_directory) if os.path.exists(pub_directory): self.admin.add_view(admin_views.AdministratorFileAdmin(pub_directory, category = category_system, name = lazy_gettext('Public directory'), endpoint = 'system/pub', url='pub')) self.admin.add_view(admin_views.UsersAddingView(db_session, category = category_users, name = lazy_gettext('Add multiple users'), endpoint = 'users/multiple')) self.admin.add_view(admin_views.UsersPanel(db_session, category = category_users, name = lazy_gettext('Users'), endpoint = 'users/users', url='users')) self.admin.add_view(admin_views.GroupsPanel(db_session, category = category_users, name = lazy_gettext('Groups'), endpoint = 'users/groups', url='groups')) self.admin.add_view(admin_views.UserUsedExperimentPanel(files_directory, db_session, category = category_logs, name = lazy_gettext('User logs'), endpoint = 'logs/users', url='logs')) self.admin.add_view(admin_views.ExperimentCategoryPanel(db_session, category = category_experiments, name = lazy_gettext('Categories'), endpoint = 'experiments/categories', url='experiments/categories')) self.admin.add_view(admin_views.ExperimentPanel(db_session, category = category_experiments, name = lazy_gettext('Experiments'), endpoint = 'experiments/experiments', url='experiments')) # TODO: Until finished, do not display # self.admin.add_view(admin_views.SchedulerPanel(db_session, category = category_experiments, name = lazy_gettext('Schedulers'), endpoint = 'experiments/schedulers')) self.admin.add_view(admin_views.PermissionsAddingView(db_session, category = category_permissions, name = lazy_gettext('Create'), endpoint = 'permissions/create', url='permissions')) self.admin.add_view(admin_views.UserPermissionPanel(db_session, category = category_permissions, name = lazy_gettext('User'), endpoint = 'permissions/user')) self.admin.add_view(admin_views.GroupPermissionPanel(db_session, category = category_permissions, name = lazy_gettext('Group'), endpoint = 'permissions/group')) self.admin.add_view(admin_views.RolePermissionPanel(db_session, category = category_permissions, name = lazy_gettext('Roles'), endpoint = 'permissions/role')) self.admin.add_link(MenuLink(endpoint='instructor.index', name = lazy_gettext('Instructor panel'), icon_type='glyph', icon_value='glyphicon-stats')) self.admin.add_link(MenuLink(endpoint='profile.index', name = lazy_gettext('My profile'), icon_type='glyph', icon_value='glyphicon-user')) self.admin.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.admin.init_app(self.app) self.full_admin_url = self.script_name + admin_url ################################################ # # Profile panel # profile_url = '/weblab/profile' self.profile = Admin(index_view = profile_views.ProfileHomeView(db_session, url = profile_url, endpoint = 'profile'),name = lazy_gettext('WebLab-Deusto profile'), url = profile_url, endpoint = profile_url, base_template = 'weblab-master.html', template_mode='bootstrap3') self.profile.weblab_admin_app = self self.profile.add_view(profile_views.ProfileEditView(db_session, name = lazy_gettext('Edit'), endpoint = 'edit')) self.profile.add_view(profile_views.MyAccessesPanel(files_directory, db_session, name = lazy_gettext('My accesses'), endpoint = 'accesses')) self.profile.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.profile.init_app(self.app) ################################################ # # Instructors panel # # TODO. There should be able a new M2M relation between instructors and groups. # # Instructor should be able to: # # a) Create new groups (of which they are in charge) # b) Make other instructors in charge of these groups # c) Add students (and only students) to the system; forcing a group # d) Edit users (only students; of those groups that the administrator is in charge of) # e) Assign permissions on these courses # f) Manage the permissions on these courses # g) See the logs of their own students # h) See a panel with analytics of each of these groups (this panel is common to the administrator, and has not been implemented) instructor_url = '/weblab/instructor' instructor_home = instructor_views.InstructorHomeView(db_session, url = instructor_url, endpoint = 'instructor') instructor_home.static_folder = static_folder self.instructor = Admin(index_view = instructor_home, name = lazy_gettext("Weblab-Deusto instructor"), url = instructor_url, endpoint = instructor_url, base_template = 'weblab-master.html', template_mode='bootstrap3') self.instructor.weblab_admin_app = self category_general = lazy_gettext("General") category_stats = lazy_gettext("Stats") self.instructor.add_view(instructor_views.UsersPanel(db_session, category = category_general, name = lazy_gettext('Users'), endpoint = 'users')) self.instructor.add_view(instructor_views.GroupsPanel(db_session, category = category_general, name = lazy_gettext('Groups'), endpoint = 'groups')) self.instructor.add_view(instructor_views.UserUsedExperimentPanel(db_session, category = category_general, name = lazy_gettext('Raw accesses'), endpoint = 'logs')) self.instructor.add_view(instructor_views.GroupStats(db_session, category = category_stats, name = lazy_gettext('Group'), endpoint = 'stats/groups')) self.instructor.add_link(MenuLink(endpoint='profile.index', name = lazy_gettext('My profile'), icon_type='glyph', icon_value='glyphicon-user')) self.instructor.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.instructor.init_app(self.app) ################################################ # # Other # self.bypass_authz = bypass_authz
def __init__(self, app, cfg_manager, core_server, bypass_authz = False): super(AdministrationApplication, self).__init__() app.json_encoder = CustomJSONEncoder self.cfg_manager = cfg_manager pub_directory = os.path.join(os.path.abspath(self.cfg_manager.get('deployment_dir', '')), 'pub') self.config = cfg_manager db.initialize(cfg_manager) self.core_server = core_server db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=db.engine)) files_directory = cfg_manager.get_doc_value(configuration_doc.CORE_STORE_STUDENTS_PROGRAMS_PATH) core_server_url = cfg_manager.get_value( 'core_server_url', '' ) self.script_name = urlparse.urlparse(core_server_url).path.split('/weblab')[0] or '' self.app = app static_folder = os.path.abspath(os.path.join(os.path.dirname(web.__file__), 'static')) # Not allowed @app.route('/weblab/not_allowed') def not_allowed(): return "You are logged in, but not allowed to see this content. Please log in with a proper account" # Back @app.route('/weblab/back') def back_to_client(): return redirect(url_for('core_webclient.labs')) ################################################ # # Administration panel for administrators # # admin_url = '/weblab/admin' category_system = lazy_gettext("System") category_users = lazy_gettext("Users") category_logs = lazy_gettext("Logs") category_experiments = lazy_gettext("Experiments") category_permissions = lazy_gettext("Permissions") self.admin = Admin(index_view = admin_views.HomeView(db_session, url = admin_url),name = lazy_gettext('WebLab-Deusto Admin'), url = admin_url, endpoint = admin_url, base_template = 'weblab-master.html', template_mode = 'bootstrap3') self.admin.weblab_admin_app = self self.admin.add_view(admin_views.SystemProperties(db_session, category = category_system, name = lazy_gettext('Settings'), endpoint = 'system/settings', url='settings')) self.admin.add_view(admin_views.AuthsPanel(db_session, category = category_system, name = lazy_gettext('Authentication'), endpoint = 'system/auth', url='auth')) if not os.path.exists(pub_directory): try: os.mkdir(pub_directory) except (IOError, OSError) as e: print("WARNING: %s not found. Create it to upload files to it." % pub_directory) if os.path.exists(pub_directory): self.admin.add_view(admin_views.AdministratorFileAdmin(pub_directory, category = category_system, name = lazy_gettext('Public directory'), endpoint = 'system/pub', url='pub')) self.admin.add_view(admin_views.UsersAddingView(db_session, category = category_users, name = lazy_gettext('Add multiple users'), endpoint = 'users/multiple')) self.admin.add_view(admin_views.UsersPanel(db_session, category = category_users, name = lazy_gettext('Users'), endpoint = 'users/users', url='users')) self.admin.add_view(admin_views.GroupsPanel(db_session, category = category_users, name = lazy_gettext('Groups'), endpoint = 'users/groups', url='groups')) self.admin.add_view(admin_views.InvitationsPanel(db_session, category = category_users, name = lazy_gettext('Invitations'), endpoint = 'users/invitations', url='invitations')) self.admin.add_view(admin_views.UserUsedExperimentPanel(files_directory, db_session, category = category_logs, name = lazy_gettext('User logs'), endpoint = 'logs/users', url='logs')) self.admin.add_view(admin_views.ExperimentCategoryPanel(db_session, category = category_experiments, name = lazy_gettext('Categories'), endpoint = 'experiments/categories', url='experiments/categories')) self.admin.add_view(admin_views.ExperimentPanel(db_session, category = category_experiments, name = lazy_gettext('Experiments'), endpoint = 'experiments/experiments', url='experiments')) # TODO: Until finished, do not display # self.admin.add_view(admin_views.SchedulerPanel(db_session, category = category_experiments, name = lazy_gettext('Schedulers'), endpoint = 'experiments/schedulers')) self.admin.add_view(admin_views.PermissionsAddingView(db_session, category = category_permissions, name = lazy_gettext('Create'), endpoint = 'permissions/create', url='permissions')) self.admin.add_view(admin_views.UserPermissionPanel(db_session, category = category_permissions, name = lazy_gettext('User'), endpoint = 'permissions/user')) self.admin.add_view(admin_views.GroupPermissionPanel(db_session, category = category_permissions, name = lazy_gettext('Group'), endpoint = 'permissions/group')) self.admin.add_view(admin_views.RolePermissionPanel(db_session, category = category_permissions, name = lazy_gettext('Roles'), endpoint = 'permissions/role')) self.admin.add_link(MenuLink(endpoint='instructor.index', name = lazy_gettext('Instructor panel'), icon_type='glyph', icon_value='glyphicon-stats')) self.admin.add_link(MenuLink(endpoint='profile.index', name = lazy_gettext('My profile'), icon_type='glyph', icon_value='glyphicon-user')) self.admin.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.admin.init_app(self.app) self.full_admin_url = self.script_name + admin_url ################################################ # # Profile panel # profile_url = '/weblab/profile' self.profile = Admin(index_view = profile_views.ProfileHomeView(db_session, url = profile_url, endpoint = 'profile'),name = lazy_gettext('WebLab-Deusto profile'), url = profile_url, endpoint = profile_url, base_template = 'weblab-master.html', template_mode='bootstrap3') self.profile.weblab_admin_app = self self.profile.add_view(profile_views.ProfileEditView(db_session, name = lazy_gettext('Edit'), endpoint = 'edit')) self.profile.add_view(profile_views.MyAccessesPanel(files_directory, db_session, name = lazy_gettext('My accesses'), endpoint = 'accesses')) self.profile.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.profile.init_app(self.app) ################################################ # # Instructors panel # # TODO. There should be able a new M2M relation between instructors and groups. # # Instructor should be able to: # # a) Create new groups (of which they are in charge) # b) Make other instructors in charge of these groups # c) Add students (and only students) to the system; forcing a group # d) Edit users (only students; of those groups that the administrator is in charge of) # e) Assign permissions on these courses # f) Manage the permissions on these courses # g) See the logs of their own students # h) See a panel with analytics of each of these groups (this panel is common to the administrator, and has not been implemented) instructor_url = '/weblab/instructor' instructor_home = instructor_views.InstructorHomeView(db_session, url = instructor_url, endpoint = 'instructor') instructor_home.static_folder = static_folder self.instructor = Admin(index_view = instructor_home, name = lazy_gettext("Weblab-Deusto instructor"), url = instructor_url, endpoint = instructor_url, base_template = 'weblab-master.html', template_mode='bootstrap3') self.instructor.weblab_admin_app = self category_general = lazy_gettext("General") category_stats = lazy_gettext("Stats") self.instructor.add_view(instructor_views.UsersPanel(db_session, category = category_general, name = lazy_gettext('Users'), endpoint = 'users')) self.instructor.add_view(instructor_views.GroupsPanel(db_session, category = category_general, name = lazy_gettext('Groups'), endpoint = 'groups')) self.instructor.add_view(instructor_views.UserUsedExperimentPanel(db_session, category = category_general, name = lazy_gettext('Raw accesses'), endpoint = 'logs')) self.instructor.add_view(instructor_views.GroupStats(db_session, category = category_stats, name = lazy_gettext('Group'), endpoint = 'stats/groups')) self.instructor.add_link(MenuLink(endpoint='profile.index', name = lazy_gettext('My profile'), icon_type='glyph', icon_value='glyphicon-user')) self.instructor.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.instructor.init_app(self.app) ################################################ # # Other # self.bypass_authz = bypass_authz