Ejemplo n.º 1
0
def main(global_config=None, testmode=False, **settings):
    if testmode:
        engine = muesli.testengine()
    else:
        engine = muesli.engine()
    initializeSession(engine)

    # XXX: ugly
    import sqlalchemy as sa
    beaker.ext.sqla.sa = sa
    # Even more ugly, but otherwise the tests won't work
    # as the metadata is shared between tests
    if not 'beaker_cache' in Base.metadata.tables:
        session_table = beaker.ext.sqla.make_cache_table(Base.metadata)
    else:
        session_table = Base.metadata.tables['beaker_cache']
    session_table.create(bind=engine, checkfirst=True)
    settings.update({
        'beaker.session.type': 'ext:sqla',
        'beaker.session.bind': engine,
        'beaker.session.table': session_table,
        'beaker.session.data_dir': tempfile.mkdtemp(),
        'beaker.session.timeout': 7200,
    })
    if not muesli.PRODUCTION_INSTANCE:
        settings.update({
            'debugtoolbar.hosts': '0.0.0.0/0',
        })
    session_factory = pyramid_beaker.session_factory_from_settings(settings)
    jwt_authentication_policy = JWTAuthenticationPolicy(
        muesli.config["api"]["JWT_SECRET_TOKEN"],
        callback=principals_for_user,
        auth_type="Bearer",
        expiration=datetime.timedelta(
            days=muesli.config["api"]["KEY_EXPIRATION"]))
    session_authentication_policy = SessionAuthenticationPolicy(
        callback=principals_for_user)
    authentication_policy = MultiAuthenticationPolicy(
        [session_authentication_policy, jwt_authentication_policy])

    authorization_policy = ACLAuthorizationPolicy()
    config = Configurator(
        authentication_policy=authentication_policy,
        authorization_policy=authorization_policy,
        session_factory=session_factory,
        settings=settings,
    )
    config.include('muesli.web.pyramid_jwt')
    config.set_jwt_authentication_policy(jwt_authentication_policy)
    config.add_static_view('static', 'muesli.web:static')

    config.add_route('start', '/start', factory=GeneralContext)
    config.add_route('contact', '/contact')
    config.add_route('changelog', '/changelog')
    config.add_route('admin', '/admin', factory=GeneralContext)
    config.add_route('index', '/')
    config.add_route('email_users', '/email_users', factory=GeneralContext)
    config.add_route('email_all_users',
                     '/email_all_users',
                     factory=GeneralContext)
    config.add_route('user_update', '/user/update', factory=GeneralContext)
    config.add_route('user_check', '/user/check', factory=GeneralContext)
    config.add_route('user_change_email',
                     '/user/change_email',
                     factory=GeneralContext)
    config.add_route('user_change_password',
                     '/user/change_password',
                     factory=GeneralContext)
    config.add_route('user_logout', '/user/logout')
    config.add_route('user_login', '/user/login')
    config.add_route('user_list', '/user/list', factory=GeneralContext)
    config.add_route('user_edit', '/user/edit/{user_id}', factory=UserContext)
    config.add_route('user_delete',
                     '/user/delete/{user_id}',
                     factory=UserContext)
    config.add_route('user_delete_unconfirmed',
                     '/user/delete_unconfirmed',
                     factory=GeneralContext)
    config.add_route('user_doublets', '/user/doublets', factory=GeneralContext)
    config.add_route('user_resend_confirmation_mail',
                     '/user/resend_confirmation_mail/{user_id}',
                     factory=UserContext)
    config.add_route('user_list_subjects',
                     '/user/list_subjects',
                     factory=GeneralContext)
    config.add_route('user_list_subjects_by_term',
                     '/user/list_subjects_by_term',
                     factory=GeneralContext)
    config.add_route('user_register', '/user/register', factory=GeneralContext)
    config.add_route('user_register_other',
                     '/user/register_other',
                     factory=GeneralContext)
    config.add_route('user_wait_for_confirmation',
                     '/user/wait_for_confirmation',
                     factory=GeneralContext)
    config.add_route('user_change_email_wait_for_confirmation',
                     '/user/change_email_wait_for_confirmation',
                     factory=GeneralContext)
    config.add_route('user_confirm',
                     '/user/confirm/{confirmation}',
                     factory=ConfirmationContext)
    config.add_route('user_confirm_email',
                     '/user/confirm_email/{confirmation}',
                     factory=ConfirmationContext)
    config.add_route('user_reset_password',
                     '/user/reset_password',
                     factory=GeneralContext)
    config.add_route('user_reset_password2',
                     '/user/reset_password2',
                     factory=GeneralContext)
    config.add_route('user_reset_password3',
                     '/user/reset_password3/{confirmation}',
                     factory=ConfirmationContext)

    config.add_route('user_api_keys', '/user/api_keys', factory=GeneralContext)
    config.add_route('remove_api_key',
                     '/user/remove_api_key/{key_id}',
                     factory=GeneralContext)

    config.add_route('user_ajax_complete',
                     '/user/ajax_complete/{lecture_id}/{tutorial_ids:[^/]*}',
                     factory=TutorialContext)
    config.add_route('overview', '/')
    config.add_route('lecture_add', '/lecture/add', factory=GeneralContext)
    config.add_route('lecture_list', '/lecture/list', factory=GeneralContext)
    config.add_route('lecture_edit',
                     '/lecture/edit/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_delete',
                     '/lecture/delete/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_change_assistants',
                     '/lecture/change_assistants/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_preferences',
                     '/lecture/preferences/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_prefhistogram',
                     '/lecture/prefhistogram/{lecture_id}/{time}',
                     factory=LectureContext)
    config.add_route('lecture_remove_tutor',
                     '/lecture/remove_tutor/{lecture_id}/{tutor_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_tutor',
                     '/lecture/add_tutor/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_do_allocation',
                     '/lecture/do_allocation/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_remove_allocation',
                     '/lecture/remove_allocation/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_email_students',
                     '/lecture/email_students/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_email_tutors',
                     '/lecture/email_tutors/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_view',
                     '/lecture/view/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_view_removed_students',
                     '/lecture/view_removed_students/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_set_preferences',
                     '/lecture/set_preferences/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_remove_preferences',
                     '/lecture/remove_preferences/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_exam',
                     '/lecture/add_exam/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_grading',
                     '/lecture/add_grading/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_student',
                     '/lecture/add_student/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_switch_students',
                     '/lecture/switch_students/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_export_students_html',
                     '/lecture/export_students_html/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_export_totals',
                     '/lecture/export_totals/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_export_yaml',
                     '/lecture/export_yaml',
                     factory=GeneralContext)
    config.add_route('lecture_export_yaml_details',
                     '/lecture/export_yaml_details',
                     factory=GeneralContext)  #Canh added
    config.add_route('lecture_export_excel',
                     '/lecture/export_excel/downloadDetailTutorials.xlsx',
                     factory=GeneralContext)

    config.add_route('lecture_view_points',
                     '/lecture/view_points/{lecture_id}',
                     factory=LectureContext)

    config.add_route('tutorial_add',
                     '/tutorial/add/{lecture_id}',
                     factory=LectureContext)
    config.add_route('tutorial_duplicate',
                     '/tutorial/duplicate/{lecture_id}/{tutorial_id}',
                     factory=LectureContext)
    config.add_route('tutorial_delete',
                     '/tutorial/delete/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_view',
                     '/tutorial/view/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_results',
                     '/tutorial/results/{lecture_id}/{tutorial_ids:[^/]*}',
                     factory=TutorialContext)
    config.add_route('tutorial_email',
                     '/tutorial/email/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_email_preference',
                     '/tutorial/email_preference/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_resign_as_tutor',
                     '/tutorial/resign_as_tutor/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_assign_student',
                     '/tutorial/assign_student',
                     factory=AssignStudentContext)

    config.add_route('tutorial_edit',
                     '/tutorial/edit/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_set_tutor', '/tutorial/set_tutor/{tutorial_id}')
    config.add_route('tutorial_take',
                     '/tutorial/take/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_remove_student',
                     '/tutorial/remove_student/{tutorial_ids}/{student_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_subscribe',
                     '/tutorial/subscribe/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_unsubscribe',
                     '/tutorial/unsubscribe/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_occupancy_bar',
                     '/tutorial/occupancy_bar/{count}/{max_count}')
    config.add_route('tutorial_ajax_get_tutorial',
                     '/tutorial/ajax_get_tutorial/{lecture_id}',
                     factory=LectureContext)

    config.add_route(
        'exam_add_or_edit_exercise',
        '/exam/add_or_edit_exercise/{exam_id}/{exercise_id:[^/]*}',
        factory=ExamContext)
    config.add_route('exam_delete_exercise',
                     '/exam/delete_exercise/{exam_id}/{exercise_id}',
                     factory=ExamContext)
    config.add_route('exam_edit', '/exam/edit/{exam_id}', factory=ExamContext)
    config.add_route('exam_delete',
                     '/exam/delete/{exam_id}',
                     factory=ExamContext)
    config.add_route('exam_admission',
                     '/exam/admission/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_statistics',
                     '/exam/statistics/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route(
        'exam_statistics_bar',
        '/exam/statistics_bar/{max}/{lecture_points}/{tutorial_points:[^/]*}')
    config.add_route(
        'exam_histogram_for_exercise',
        '/exam/histogram_for_exercise/{exercise_id}/{tutorial_ids:[^/]*}',
        factory=ExerciseContext)
    config.add_route('exam_histogram_for_exam',
                     '/exam/histogram_for_exam/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_correlation',
                     '/exam/correlation',
                     factory=CorrelationContext)
    config.add_route('exam_enter_points',
                     '/exam/enter_points/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_enter_points_raw',
                     '/exam/enter_points_raw/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route(
        'exam_enter_points_single',
        '/exam/enter_points_single/{exam_id}/{tutorial_ids:[^/]*}',
        factory=ExamContext)
    config.add_route('exam_ajax_get_points',
                     '/exam/ajax_get_points/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_ajax_save_points',
                     '/exam/ajax_save_points/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_export',
                     '/exam/export/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)

    config.add_route('grading_edit',
                     '/grading/edit/{grading_id}',
                     factory=GradingContext)
    config.add_route('grading_export',
                     '/grading/export/{grading_id}.xlsx',
                     factory=GradingContext)
    config.add_route('grading_associate_exam',
                     '/grading/associate_exam/{grading_id}',
                     factory=GradingContext)
    config.add_route('grading_delete_exam_association',
                     '/grading/delete_exam_association/{grading_id}/{exam_id}',
                     factory=GradingContext)
    config.add_route('grading_enter_grades',
                     '/grading/enter_grades/{grading_id}',
                     factory=GradingContext)
    config.add_route('grading_formula_histogram',
                     '/grading/enter_grades/{grading_id}/formula_histogram',
                     factory=GradingContext)
    config.add_route('grading_get_row',
                     '/grading/get_row/{grading_id}',
                     factory=GradingContext)

    # Begin: config for the API-Browser
    config.include('pyramid_apispec.views')
    config.add_route("openapi_spec", "/openapi.json")
    config.pyramid_apispec_add_explorer(spec_route_name='openapi_spec')
    # End: config for the API-Browser

    config.add_route('api_login', '/api/v1/login')
    config.include('pyramid_chameleon')
    # TODO: move the prefix addition into a seperate function for later
    # developed API's.
    config.route_prefix = 'api/v1'
    config.include('cornice')

    if not muesli.PRODUCTION_INSTANCE:
        config.include('pyramid_debugtoolbar')

    config.scan()

    return config.make_wsgi_app()
Ejemplo n.º 2
0
def main(global_config=None, **settings):
    engine = muesli.engine()
    initializeSession(engine)
    #settings.update({
    #})

    # XXX: ugly
    import sqlalchemy as sa
    beaker.ext.sqla.sa = sa
    # Even more ugly, but otherwise the tests won't work
    # as the metadata is shared between tests
    if not 'beaker_cache' in Base.metadata.tables:
        session_table = beaker.ext.sqla.make_cache_table(Base.metadata)
    else:
        session_table = Base.metadata.tables['beaker_cache']
    session_table.create(bind=engine, checkfirst=True)
    settings.update({
            'beaker.session.type': 'ext:sqla',
            'beaker.session.bind': engine,
            'beaker.session.table': session_table,
            'beaker.session.data_dir': tempfile.mkdtemp(),
            'beaker.session.timeout': 7200,
    })
    session_factory = pyramid_beaker.session_factory_from_settings(settings)

    authentication_policy = SessionAuthenticationPolicy(callback=principals_for_user)

    authorization_policy = ACLAuthorizationPolicy()
    config = Configurator(
            authentication_policy=authentication_policy,
            authorization_policy=authorization_policy,
            session_factory=session_factory,
            settings=settings,
            )

    config.add_static_view('static', 'muesli.web:static')

    config.add_route('start', '/start', factory = GeneralContext)
    config.add_route('contact', '/contact')
    config.add_route('changelog', '/changelog')
    config.add_route('admin', '/admin', factory = GeneralContext)
    config.add_route('index', '/')
    config.add_route('email_users', '/email_users', factory = GeneralContext)
    config.add_route('email_all_users','/email_all_users',factory = GeneralContext)
    config.add_route('user_update', '/user/update', factory = GeneralContext)
    config.add_route('user_change_email', '/user/change_email', factory = GeneralContext)
    config.add_route('user_change_password', '/user/change_password', factory = GeneralContext)
    config.add_route('user_logout', '/user/logout')
    config.add_route('user_login', '/user/login')
    config.add_route('user_list', '/user/list', factory = GeneralContext)
    config.add_route('user_edit', '/user/edit/{user_id}', factory = UserContext)
    config.add_route('user_delete', '/user/delete/{user_id}', factory = UserContext)
    config.add_route('user_delete_unconfirmed', '/user/delete_unconfirmed', factory = GeneralContext)
    config.add_route('user_doublets', '/user/doublets', factory = GeneralContext)
    config.add_route('user_resend_confirmation_mail', '/user/resend_confirmation_mail/{user_id}', factory = UserContext)
    config.add_route('user_list_subjects', '/user/list_subjects', factory = GeneralContext)
    config.add_route('user_list_subjects_by_term', '/user/list_subjects_by_term', factory = GeneralContext)
    config.add_route('user_register', '/user/register', factory=GeneralContext)
    config.add_route('user_register_other', '/user/register_other', factory=GeneralContext)
    config.add_route('user_wait_for_confirmation', '/user/wait_for_confirmation', factory=GeneralContext)
    config.add_route('user_change_email_wait_for_confirmation', '/user/change_email_wait_for_confirmation', factory=GeneralContext)
    config.add_route('user_confirm', '/user/confirm/{confirmation}', factory=ConfirmationContext)
    config.add_route('user_confirm_email', '/user/confirm_email/{confirmation}', factory=ConfirmationContext)
    config.add_route('user_reset_password', '/user/reset_password', factory=GeneralContext)
    config.add_route('user_reset_password2', '/user/reset_password2', factory=GeneralContext)
    config.add_route('user_reset_password3', '/user/reset_password3/{confirmation}', factory=ConfirmationContext)
    config.add_route('user_ajax_complete', '/user/ajax_complete/{lecture_id}/{tutorial_ids:[^/]*}', factory = TutorialContext)

    config.add_route('overview', '/')
    config.add_route('lecture_add', '/lecture/add', factory = GeneralContext)
    config.add_route('lecture_list', '/lecture/list', factory = GeneralContext)
    config.add_route('lecture_edit', '/lecture/edit/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_delete', '/lecture/delete/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_change_assistants', '/lecture/change_assistants/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_preferences', '/lecture/preferences/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_prefhistogram', '/lecture/prefhistogram/{lecture_id}/{time}', factory = LectureContext)
    config.add_route('lecture_remove_tutor', '/lecture/remove_tutor/{lecture_id}/{tutor_id}', factory = LectureContext)
    config.add_route('lecture_add_tutor', '/lecture/add_tutor/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_do_allocation', '/lecture/do_allocation/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_remove_allocation', '/lecture/remove_allocation/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_email_students', '/lecture/email_students/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_email_tutors', '/lecture/email_tutors/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_view', '/lecture/view/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_view_removed_students', '/lecture/view_removed_students/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_set_preferences', '/lecture/set_preferences/{lecture_id}', factory=LectureContext)
    config.add_route('lecture_remove_preferences', '/lecture/remove_preferences/{lecture_id}', factory=LectureContext)
    config.add_route('lecture_add_exam', '/lecture/add_exam/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_add_grading', '/lecture/add_grading/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_add_student', '/lecture/add_student/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_export_students_html', '/lecture/export_students_html/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_export_totals', '/lecture/export_totals/{lecture_id}', factory = LectureContext)
    config.add_route('lecture_export_yaml', '/lecture/export_yaml', factory = GeneralContext)
    config.add_route('lecture_export_yaml_details','/lecture/export_yaml_details',factory = GeneralContext) #Canh added
    config.add_route('lecture_export_excel','/lecture/export_excel/downloadDetailTutorials.xlsx',factory = GeneralContext)

    config.add_route('lecture_view_points', '/lecture/view_points/{lecture_id}', factory = LectureContext)


    config.add_route('tutorial_add', '/tutorial/add/{lecture_id}', factory=LectureContext)
    config.add_route('tutorial_delete', '/tutorial/delete/{tutorial_ids}', factory=TutorialContext)
    config.add_route('tutorial_view', '/tutorial/view/{tutorial_ids}', factory = TutorialContext)
    config.add_route('tutorial_results', '/tutorial/results/{lecture_id}/{tutorial_ids:[^/]*}', factory = TutorialContext)
    config.add_route('tutorial_email', '/tutorial/email/{tutorial_ids}', factory = TutorialContext)
    config.add_route('tutorial_resign_as_tutor', '/tutorial/resign_as_tutor/{tutorial_ids}', factory = TutorialContext)
    config.add_route('tutorial_assign_student', '/tutorial/assign_student', factory = AssignStudentContext)


    config.add_route('tutorial_edit', '/tutorial/edit/{tutorial_id}', factory=TutorialContext)
    config.add_route('tutorial_set_tutor', '/tutorial/set_tutor/{tutorial_id}')
    config.add_route('tutorial_take', '/tutorial/take/{tutorial_id}', factory=TutorialContext)
    config.add_route('tutorial_remove_student', '/tutorial/remove_student/{tutorial_ids}/{student_id}', factory=TutorialContext)
    config.add_route('tutorial_subscribe', '/tutorial/subscribe/{tutorial_id}', factory=TutorialContext)
    config.add_route('tutorial_unsubscribe', '/tutorial/unsubscribe/{tutorial_id}', factory=TutorialContext)
    config.add_route('tutorial_occupancy_bar', '/tutorial/occupancy_bar/{count}/{max_count}')
    config.add_route('tutorial_ajax_get_tutorial', '/tutorial/ajax_get_tutorial/{lecture_id}', factory=LectureContext)

    config.add_route('exam_add_or_edit_exercise', '/exam/add_or_edit_exercise/{exam_id}/{exercise_id:[^/]*}', factory=ExamContext)
    config.add_route('exam_delete_exercise', '/exam/delete_exercise/{exam_id}/{exercise_id}', factory=ExamContext)
    config.add_route('exam_edit', '/exam/edit/{exam_id}', factory=ExamContext)
    config.add_route('exam_delete', '/exam/delete/{exam_id}', factory=ExamContext)
    config.add_route('exam_admission', '/exam/admission/{exam_id}/{tutorial_ids:[^/]*}', factory=ExamContext)
    config.add_route('exam_statistics', '/exam/statistics/{exam_id}/{tutorial_ids:[^/]*}', factory=ExamContext)
    config.add_route('exam_statistics_bar', '/exam/statistics_bar/{max}/{lecture_points}/{tutorial_points:[^/]*}')
    config.add_route('exam_histogram_for_exercise', '/exam/histogram_for_exercise/{exercise_id}/{tutorial_ids:[^/]*}', factory=ExerciseContext)
    config.add_route('exam_histogram_for_exam', '/exam/histogram_for_exam/{exam_id}/{tutorial_ids:[^/]*}', factory=ExamContext)
    config.add_route('exam_correlation', '/exam/correlation', factory=CorrelationContext)
    config.add_route('exam_enter_points', '/exam/enter_points/{exam_id}/{tutorial_ids:[^/]*}', factory=ExamContext)
    config.add_route('exam_enter_points_raw', '/exam/enter_points_raw/{exam_id}/{tutorial_ids:[^/]*}', factory=ExamContext)
    config.add_route('exam_enter_points_single', '/exam/enter_points_single/{exam_id}/{tutorial_ids:[^/]*}', factory=ExamContext)
    config.add_route('exam_ajax_get_points', '/exam/ajax_get_points/{exam_id}/{tutorial_ids:[^/]*}', factory=ExamContext)
    config.add_route('exam_ajax_save_points', '/exam/ajax_save_points/{exam_id}/{tutorial_ids:[^/]*}', factory=ExamContext)
    config.add_route('exam_export', '/exam/export/{exam_id}/{tutorial_ids:[^/]*}', factory = ExamContext)

    config.add_route('grading_edit', '/grading/edit/{grading_id}', factory=GradingContext)
    config.add_route('grading_export', '/grading/export/{grading_id}.xlsx', factory=GradingContext)
    config.add_route('grading_associate_exam', '/grading/associate_exam/{grading_id}', factory=GradingContext)
    config.add_route('grading_delete_exam_association', '/grading/delete_exam_association/{grading_id}/{exam_id}', factory=GradingContext)
    config.add_route('grading_enter_grades', '/grading/enter_grades/{grading_id}', factory=GradingContext)
    config.add_route('grading_get_row', '/grading/get_row/{grading_id}', factory=GradingContext)

    config.include('pyramid_chameleon');

    config.scan()

    return config.make_wsgi_app()
Ejemplo n.º 3
0
import muesli
import muesli.models as models
import sqlalchemy as sa

import sys

engine = muesli.engine()
if len(sys.argv) == 1:
    from alembic.config import Config
    from alembic import command
    models.Base.metadata.create_all(engine)
    alembic_cfg = Config("alembic.ini")
    command.stamp(alembic_cfg, "head")
else:
    admin_user_mail = sys.argv[1]
    import muesli.models as models
    from muesli.models import *
    import sqlalchemy as sa
    models.initializeSession(engine)
    session = models.Session()
    user = session.query(User).filter(User.email == admin_user_mail).one()
    user.is_admin = 1
    session.commit()
    print("%s is admin now" % admin_user_mail)
Ejemplo n.º 4
0
def main(global_config=None, **settings):
    engine = muesli.engine()
    initializeSession(engine)
    #settings.update({
    #})

    # XXX: ugly
    import sqlalchemy as sa
    beaker.ext.sqla.sa = sa
    # Even more ugly, but otherwise the tests won't work
    # as the metadata is shared between tests
    if not 'beaker_cache' in Base.metadata.tables:
        session_table = beaker.ext.sqla.make_cache_table(Base.metadata)
    else:
        session_table = Base.metadata.tables['beaker_cache']
    session_table.create(bind=engine, checkfirst=True)
    settings.update({
        'beaker.session.type': 'ext:sqla',
        'beaker.session.bind': engine,
        'beaker.session.table': session_table,
        'beaker.session.data_dir': tempfile.mkdtemp(),
        'beaker.session.timeout': 7200,
    })
    session_factory = pyramid_beaker.session_factory_from_settings(settings)

    authentication_policy = SessionAuthenticationPolicy(
        callback=principals_for_user)

    authorization_policy = ACLAuthorizationPolicy()
    config = Configurator(
        authentication_policy=authentication_policy,
        authorization_policy=authorization_policy,
        session_factory=session_factory,
        settings=settings,
    )

    config.add_static_view('static', 'muesli.web:static')

    config.add_route('start', '/start', factory=GeneralContext)
    config.add_route('contact', '/contact')
    config.add_route('changelog', '/changelog')
    config.add_route('admin', '/admin', factory=GeneralContext)
    config.add_route('index', '/')
    config.add_route('email_users', '/email_users', factory=GeneralContext)
    config.add_route('email_all_users',
                     '/email_all_users',
                     factory=GeneralContext)
    config.add_route('user_update', '/user/update', factory=GeneralContext)
    config.add_route('user_change_email',
                     '/user/change_email',
                     factory=GeneralContext)
    config.add_route('user_change_password',
                     '/user/change_password',
                     factory=GeneralContext)
    config.add_route('user_logout', '/user/logout')
    config.add_route('user_login', '/user/login')
    config.add_route('user_list', '/user/list', factory=GeneralContext)
    config.add_route('user_edit', '/user/edit/{user_id}', factory=UserContext)
    config.add_route('user_delete',
                     '/user/delete/{user_id}',
                     factory=UserContext)
    config.add_route('user_delete_unconfirmed',
                     '/user/delete_unconfirmed',
                     factory=GeneralContext)
    config.add_route('user_doublets', '/user/doublets', factory=GeneralContext)
    config.add_route('user_resend_confirmation_mail',
                     '/user/resend_confirmation_mail/{user_id}',
                     factory=UserContext)
    config.add_route('user_list_subjects',
                     '/user/list_subjects',
                     factory=GeneralContext)
    config.add_route('user_list_subjects_by_term',
                     '/user/list_subjects_by_term',
                     factory=GeneralContext)
    config.add_route('user_register', '/user/register', factory=GeneralContext)
    config.add_route('user_register_other',
                     '/user/register_other',
                     factory=GeneralContext)
    config.add_route('user_wait_for_confirmation',
                     '/user/wait_for_confirmation',
                     factory=GeneralContext)
    config.add_route('user_change_email_wait_for_confirmation',
                     '/user/change_email_wait_for_confirmation',
                     factory=GeneralContext)
    config.add_route('user_confirm',
                     '/user/confirm/{confirmation}',
                     factory=ConfirmationContext)
    config.add_route('user_confirm_email',
                     '/user/confirm_email/{confirmation}',
                     factory=ConfirmationContext)
    config.add_route('user_reset_password',
                     '/user/reset_password',
                     factory=GeneralContext)
    config.add_route('user_reset_password2',
                     '/user/reset_password2',
                     factory=GeneralContext)
    config.add_route('user_reset_password3',
                     '/user/reset_password3/{confirmation}',
                     factory=ConfirmationContext)
    config.add_route('user_ajax_complete',
                     '/user/ajax_complete/{lecture_id}/{tutorial_ids:[^/]*}',
                     factory=TutorialContext)

    config.add_route('overview', '/')
    config.add_route('lecture_add', '/lecture/add', factory=GeneralContext)
    config.add_route('lecture_list', '/lecture/list', factory=GeneralContext)
    config.add_route('lecture_edit',
                     '/lecture/edit/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_delete',
                     '/lecture/delete/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_change_assistants',
                     '/lecture/change_assistants/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_preferences',
                     '/lecture/preferences/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_prefhistogram',
                     '/lecture/prefhistogram/{lecture_id}/{time}',
                     factory=LectureContext)
    config.add_route('lecture_remove_tutor',
                     '/lecture/remove_tutor/{lecture_id}/{tutor_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_tutor',
                     '/lecture/add_tutor/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_do_allocation',
                     '/lecture/do_allocation/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_remove_allocation',
                     '/lecture/remove_allocation/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_email_students',
                     '/lecture/email_students/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_email_tutors',
                     '/lecture/email_tutors/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_view',
                     '/lecture/view/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_view_removed_students',
                     '/lecture/view_removed_students/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_set_preferences',
                     '/lecture/set_preferences/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_remove_preferences',
                     '/lecture/remove_preferences/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_exam',
                     '/lecture/add_exam/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_grading',
                     '/lecture/add_grading/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_student',
                     '/lecture/add_student/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_export_students_html',
                     '/lecture/export_students_html/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_export_totals',
                     '/lecture/export_totals/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_export_yaml',
                     '/lecture/export_yaml',
                     factory=GeneralContext)
    config.add_route('lecture_export_yaml_details',
                     '/lecture/export_yaml_details',
                     factory=GeneralContext)  #Canh added
    config.add_route('lecture_export_excel',
                     '/lecture/export_excel/downloadDetailTutorials.xlsx',
                     factory=GeneralContext)

    config.add_route('lecture_view_points',
                     '/lecture/view_points/{lecture_id}',
                     factory=LectureContext)

    config.add_route('tutorial_add',
                     '/tutorial/add/{lecture_id}',
                     factory=LectureContext)
    config.add_route('tutorial_delete',
                     '/tutorial/delete/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_view',
                     '/tutorial/view/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_results',
                     '/tutorial/results/{lecture_id}/{tutorial_ids:[^/]*}',
                     factory=TutorialContext)
    config.add_route('tutorial_email',
                     '/tutorial/email/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_resign_as_tutor',
                     '/tutorial/resign_as_tutor/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_assign_student',
                     '/tutorial/assign_student',
                     factory=AssignStudentContext)

    config.add_route('tutorial_edit',
                     '/tutorial/edit/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_set_tutor', '/tutorial/set_tutor/{tutorial_id}')
    config.add_route('tutorial_take',
                     '/tutorial/take/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_remove_student',
                     '/tutorial/remove_student/{tutorial_ids}/{student_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_subscribe',
                     '/tutorial/subscribe/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_unsubscribe',
                     '/tutorial/unsubscribe/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_occupancy_bar',
                     '/tutorial/occupancy_bar/{count}/{max_count}')
    config.add_route('tutorial_ajax_get_tutorial',
                     '/tutorial/ajax_get_tutorial/{lecture_id}',
                     factory=LectureContext)

    config.add_route(
        'exam_add_or_edit_exercise',
        '/exam/add_or_edit_exercise/{exam_id}/{exercise_id:[^/]*}',
        factory=ExamContext)
    config.add_route('exam_delete_exercise',
                     '/exam/delete_exercise/{exam_id}/{exercise_id}',
                     factory=ExamContext)
    config.add_route('exam_edit', '/exam/edit/{exam_id}', factory=ExamContext)
    config.add_route('exam_delete',
                     '/exam/delete/{exam_id}',
                     factory=ExamContext)
    config.add_route('exam_admission',
                     '/exam/admission/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_statistics',
                     '/exam/statistics/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route(
        'exam_statistics_bar',
        '/exam/statistics_bar/{max}/{lecture_points}/{tutorial_points:[^/]*}')
    config.add_route(
        'exam_histogram_for_exercise',
        '/exam/histogram_for_exercise/{exercise_id}/{tutorial_ids:[^/]*}',
        factory=ExerciseContext)
    config.add_route('exam_histogram_for_exam',
                     '/exam/histogram_for_exam/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_correlation',
                     '/exam/correlation',
                     factory=CorrelationContext)
    config.add_route('exam_enter_points',
                     '/exam/enter_points/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_enter_points_raw',
                     '/exam/enter_points_raw/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route(
        'exam_enter_points_single',
        '/exam/enter_points_single/{exam_id}/{tutorial_ids:[^/]*}',
        factory=ExamContext)
    config.add_route('exam_ajax_get_points',
                     '/exam/ajax_get_points/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_ajax_save_points',
                     '/exam/ajax_save_points/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_export',
                     '/exam/export/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)

    config.add_route('grading_edit',
                     '/grading/edit/{grading_id}',
                     factory=GradingContext)
    config.add_route('grading_export',
                     '/grading/export/{grading_id}.xlsx',
                     factory=GradingContext)
    config.add_route('grading_associate_exam',
                     '/grading/associate_exam/{grading_id}',
                     factory=GradingContext)
    config.add_route('grading_delete_exam_association',
                     '/grading/delete_exam_association/{grading_id}/{exam_id}',
                     factory=GradingContext)
    config.add_route('grading_enter_grades',
                     '/grading/enter_grades/{grading_id}',
                     factory=GradingContext)
    config.add_route('grading_get_row',
                     '/grading/get_row/{grading_id}',
                     factory=GradingContext)

    config.include('pyramid_chameleon')

    config.scan()

    return config.make_wsgi_app()
Ejemplo n.º 5
0
def populate_config(config):
    config.set_security_policy(
        MuesliSecurityPolicy(muesli.config["api"]["JWT_SECRET_TOKEN"],
                             muesli.config["api"]["KEY_EXPIRATION"]))

    config.add_static_view('static', 'muesli.web:static')

    config.add_route('start', '/start', factory=GeneralContext)
    config.add_route('overview', '/overview', factory=GeneralContext)
    config.add_route('contact', '/contact')
    config.add_route('changelog', '/changelog')
    config.add_route('admin', '/admin', factory=GeneralContext)
    config.add_route('test_exceptions',
                     'test_exception',
                     factory=GeneralContext)
    config.add_route('index', '/')
    config.add_route('email_users', '/email_users', factory=GeneralContext)
    config.add_route('email_all_users',
                     '/email_all_users',
                     factory=GeneralContext)

    config.add_route('user_update', '/user/update', factory=GeneralContext)
    config.add_route('user_check', '/user/check', factory=GeneralContext)
    config.add_route('user_change_email',
                     '/user/change_email',
                     factory=GeneralContext)
    config.add_route('user_change_password',
                     '/user/change_password',
                     factory=GeneralContext)
    config.add_route('user_logout', '/user/logout')
    config.add_route('user_login', '/user/login')
    config.add_route('user_list', '/user/list', factory=GeneralContext)
    config.add_route('user_edit', '/user/edit/{user_id}', factory=UserContext)
    config.add_route('user_delete',
                     '/user/delete/{user_id}',
                     factory=UserContext)
    config.add_route('user_delete_gdpr',
                     '/user/delete_gdpr/{user_id}',
                     factory=UserContext)
    config.add_route('user_delete_unconfirmed',
                     '/user/delete_unconfirmed',
                     factory=GeneralContext)
    config.add_route('user_doublets', '/user/doublets', factory=GeneralContext)
    config.add_route('user_resend_confirmation_mail',
                     '/user/resend_confirmation_mail/{user_id}',
                     factory=UserContext)
    config.add_route('user_list_subjects',
                     '/user/list_subjects',
                     factory=GeneralContext)
    config.add_route('user_list_subjects_by_term',
                     '/user/list_subjects_by_term',
                     factory=GeneralContext)
    config.add_route('user_register', '/user/register', factory=GeneralContext)
    config.add_route('user_register_other',
                     '/user/register_other',
                     factory=GeneralContext)
    config.add_route('user_wait_for_confirmation',
                     '/user/wait_for_confirmation',
                     factory=GeneralContext)
    config.add_route('user_change_email_wait_for_confirmation',
                     '/user/change_email_wait_for_confirmation',
                     factory=GeneralContext)
    config.add_route('user_confirm',
                     '/user/confirm/{confirmation}',
                     factory=ConfirmationContext)
    config.add_route('user_confirm_email',
                     '/user/confirm_email/{confirmation}',
                     factory=ConfirmationContext)
    config.add_route('user_reset_password',
                     '/user/reset_password',
                     factory=GeneralContext)
    config.add_route('user_reset_password2',
                     '/user/reset_password2',
                     factory=GeneralContext)
    config.add_route('user_reset_password3',
                     '/user/reset_password3/{confirmation}',
                     factory=ConfirmationContext)

    config.add_route('user_api_keys', '/user/api_keys', factory=GeneralContext)
    config.add_route('remove_api_key',
                     '/user/remove_api_key/{key_id}',
                     factory=GeneralContext)

    config.add_route('user_ajax_complete',
                     '/user/ajax_complete/{lecture_id}/{tutorial_ids:[^/]*}',
                     factory=TutorialContext)
    config.add_route('lecture_add', '/lecture/add', factory=GeneralContext)
    config.add_route('lecture_list', '/lecture/list', factory=GeneralContext)
    config.add_route('lecture_edit',
                     '/lecture/edit/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_delete',
                     '/lecture/delete/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_change_assistants',
                     '/lecture/change_assistants/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_preferences',
                     '/lecture/preferences/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_prefhistogram',
                     '/lecture/prefhistogram/{lecture_id}/{time}',
                     factory=LectureContext)
    config.add_route('lecture_remove_tutor',
                     '/lecture/remove_tutor/{lecture_id}/{tutor_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_tutor',
                     '/lecture/add_tutor/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_do_allocation',
                     '/lecture/do_allocation/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_remove_allocation',
                     '/lecture/remove_allocation/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_email_students',
                     '/lecture/email_students/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_email_tutors',
                     '/lecture/email_tutors/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_view',
                     '/lecture/view/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_view_removed_students',
                     '/lecture/view_removed_students/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_set_preferences',
                     '/lecture/set_preferences/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_remove_preferences',
                     '/lecture/remove_preferences/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_exam',
                     '/lecture/add_exam/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_grading',
                     '/lecture/add_grading/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_add_student',
                     '/lecture/add_student/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_switch_students',
                     '/lecture/switch_students/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_export_students_html',
                     '/lecture/export_students_html/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_export_totals',
                     '/lecture/export_totals/{lecture_id}',
                     factory=LectureContext)
    config.add_route('lecture_export_yaml',
                     '/lecture/export_yaml',
                     factory=GeneralContext)
    config.add_route('lecture_export_yaml_details',
                     '/lecture/export_yaml_details',
                     factory=GeneralContext)  #Canh added
    config.add_route('lecture_export_yaml_emails',
                     '/lecture/export_yaml_emails',
                     factory=GeneralContext)
    config.add_route('lecture_export_excel',
                     '/lecture/export_excel/downloadDetailTutorials.xlsx',
                     factory=GeneralContext)

    config.add_route('lecture_view_points',
                     '/lecture/view_points/{lecture_id}',
                     factory=LectureContext)

    config.add_route('tutorial_add',
                     '/tutorial/add/{lecture_id}',
                     factory=LectureContext)
    config.add_route('tutorial_duplicate',
                     '/tutorial/duplicate/{lecture_id}/{tutorial_id}',
                     factory=LectureContext)
    config.add_route('tutorial_delete',
                     '/tutorial/delete/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_view',
                     '/tutorial/view/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_results',
                     '/tutorial/results/{lecture_id}/{tutorial_ids:[^/]*}',
                     factory=TutorialContext)
    config.add_route('tutorial_email',
                     '/tutorial/email/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_email_preference',
                     '/tutorial/email_preference/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_resign_as_tutor',
                     '/tutorial/resign_as_tutor/{tutorial_ids}',
                     factory=TutorialContext)
    config.add_route('tutorial_assign_student',
                     '/tutorial/assign_student',
                     factory=AssignStudentContext)

    config.add_route('tutorial_edit',
                     '/tutorial/edit/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_set_tutor', '/tutorial/set_tutor/{tutorial_id}')
    config.add_route('tutorial_take',
                     '/tutorial/take/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_remove_student',
                     '/tutorial/remove_student/{tutorial_ids}/{student_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_subscribe',
                     '/tutorial/subscribe/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_unsubscribe',
                     '/tutorial/unsubscribe/{tutorial_id}',
                     factory=TutorialContext)
    config.add_route('tutorial_ajax_get_tutorial',
                     '/tutorial/ajax_get_tutorial/{lecture_id}',
                     factory=LectureContext)

    config.add_route('exam_auto_admit',
                     '/exam/auto_admit/{exam_id}',
                     factory=ExamContext)
    config.add_route('exam_interactive_admission',
                     '/exam/interactive_admission/{exam_id}',
                     factory=ExamContext)
    config.add_route(
        'exam_add_or_edit_exercise',
        '/exam/add_or_edit_exercise/{exam_id}/{exercise_id:[^/]*}',
        factory=ExamContext)
    config.add_route('exam_delete_exercise',
                     '/exam/delete_exercise/{exam_id}/{exercise_id}',
                     factory=ExamContext)
    config.add_route('exam_edit', '/exam/edit/{exam_id}', factory=ExamContext)
    config.add_route('exam_delete',
                     '/exam/delete/{exam_id}',
                     factory=ExamContext)
    config.add_route('exam_admission',
                     '/exam/admission/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_statistics',
                     '/exam/statistics/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route(
        'exam_statistics_bar',
        '/exam/statistics_bar/{max}/{lecture_points}/{tutorial_points:[^/]*}')
    config.add_route(
        'exam_histogram_for_exercise',
        '/exam/histogram_for_exercise/{exercise_id}/{tutorial_ids:[^/]*}',
        factory=ExerciseContext)
    config.add_route('exam_histogram_for_exam',
                     '/exam/histogram_for_exam/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_correlation',
                     '/exam/correlation',
                     factory=CorrelationContext)
    config.add_route('exam_enter_points',
                     '/exam/enter_points/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_enter_points_raw',
                     '/exam/enter_points_raw/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route(
        'exam_enter_points_single',
        '/exam/enter_points_single/{exam_id}/{tutorial_ids:[^/]*}',
        factory=ExamContext)
    config.add_route('exam_ajax_get_points',
                     '/exam/ajax_get_points/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_ajax_save_points',
                     '/exam/ajax_save_points/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)
    config.add_route('exam_export',
                     '/exam/export/{exam_id}/{tutorial_ids:[^/]*}',
                     factory=ExamContext)

    config.add_route('grading_edit',
                     '/grading/edit/{grading_id}',
                     factory=GradingContext)
    config.add_route('grading_export',
                     '/grading/export/{grading_id}.xlsx',
                     factory=GradingContext)
    config.add_route('grading_associate_exam',
                     '/grading/associate_exam/{grading_id}',
                     factory=GradingContext)
    config.add_route('grading_delete_exam_association',
                     '/grading/delete_exam_association/{grading_id}/{exam_id}',
                     factory=GradingContext)
    config.add_route('grading_enter_grades',
                     '/grading/enter_grades/{grading_id}',
                     factory=GradingContext)
    config.add_route('grading_formula_histogram',
                     '/grading/enter_grades/{grading_id}/formula_histogram',
                     factory=GradingContext)
    config.add_route('grading_get_row',
                     '/grading/get_row/{grading_id}',
                     factory=GradingContext)

    # Begin: config for the API-Browser
    config.include('pyramid_apispec.views')
    config.add_route("openapi_spec", "/openapi.json")
    config.pyramid_apispec_add_explorer(spec_route_name='openapi_spec')
    # End: config for the API-Browser

    config.add_route('api_login', '/api/v1/login')
    config.include('pyramid_chameleon')
    # TODO: move the prefix addition into a seperate function for later
    # developed API's.
    config.route_prefix = 'api/v1'
    config.include('cornice')

    config.registry.engine = muesli.engine()
    config.registry.db_maker = sessionmaker(bind=config.registry.engine)

    config.scan()
Ejemplo n.º 6
0
import muesli
import muesli.models as models
import sqlalchemy as sa

import sys
from alembic.config import Config
from alembic import command

engine = muesli.engine()
if len(sys.argv)==1:
	models.Base.metadata.create_all(engine)
	alembic_cfg = Config("alembic.ini")
	command.stamp(alembic_cfg, "head")
else:
	admin_user_mail = sys.argv[1]
	import muesli.models as models
	from muesli.models import *
	import sqlalchemy as sa
	models.initializeSession(engine)
	session = models.Session()
	user = session.query(User).filter(User.email==admin_user_mail).one()
	user.is_admin = True
	session.commit()
	print "%s is admin now" % admin_user_mail