コード例 #1
0
ファイル: menu.py プロジェクト: tmkkk/oioioi
 def decorator(view_func):
     name = view_func.__name__
     suffix_to_remove = '_view'
     if name.endswith(suffix_to_remove):
         name = name[: -len(suffix_to_remove)]
     if hasattr(view_func, 'condition'):
         current_condition = view_func.condition
     else:
         current_condition = Condition(lambda request: True)
     if condition is not None:
         current_condition = current_condition & condition
     self.register(name, text, url_generator, current_condition, attrs, order)
     return view_func
コード例 #2
0
ファイル: tests.py プロジェクト: marmistrz/oioioi
    def test_custom_main_page(self):
        @register_main_page_view(order=0,
                                 condition=Condition(lambda request: False))
        def inaccessible(request):
            pass

        @register_main_page_view(order=1)
        def accessible(request):
            return TemplateResponse(request, 'index.html')

        response = self.client.get('/')
        self.assertIn('This is a test index template', response.content)

        unregister_main_page_view(inaccessible)
        unregister_main_page_view(accessible)
コード例 #3
0
ファイル: actions.py プロジェクト: marmistrz/oioioi
def _register_portal_action(actions, name, condition, menu_text,
                            menu_url_generator, menu_order):
    if condition is None:
        condition = Condition(lambda request: True)

    def decorator(view):
        view = enforce_condition(condition, login_redirect=False)(view)
        actions[name] = view

        if menu_text is not None:
            portal_admin_menu_registry.register(name, menu_text,
                    menu_url_generator, condition, order=menu_order)

        return view

    return decorator
コード例 #4
0
ファイル: tests.py プロジェクト: jakubste/oioioi
    def test_custom_main_page(self):
        @register_main_page_view(order=0,
                                 condition=Condition(lambda request: False))
        def inaccessible(request):
            pass

        @register_main_page_view(order=1)
        def accessible(request):
            return TemplateResponse(request, 'index.html')

        try:
            response = self.client.get('/')
            self.assertIn('This is a test index template', response.content)
        finally:
            # Perform cleanup regardless of the test failure/success
            unregister_main_page_view(inaccessible)
            unregister_main_page_view(accessible)
コード例 #5
0
    def __init__(self, name, text, url_generator, condition=None, attrs=None,
                 order=sys.maxsize):

        if condition is None:
            condition = Condition(lambda request: True)

        if attrs is None:
            attrs = {}

        if order is None:
            order = sys.maxsize

        self.name = name
        self.text = text
        self.url_generator = url_generator
        self.condition = condition
        self.attrs = attrs
        self.order = order
コード例 #6
0
def register_main_page_view(order=sys.maxsize, condition=None):
    """Decorator for a view, which registers it as a main page.

       A view registered this way can be shown as the main page of the website
       (at URL /). If multiple views are registered, one with the lowest
       ``order`` for which the ``condition`` holds true is selected.

       :param order: value determining the order in which the main page is
                     selected
       :type order: int
       :param condition: decides if a main page can be selected
       :type condition: :class:`oioioi.base.permissions.Condition`
    """

    if condition is None:
        condition = Condition(lambda request: True)

    def decorator(view):
        _main_page_registry.register(_MainPageEntry(view, condition), order)
        return view

    return decorator
コード例 #7
0
ファイル: contest_dashboard.py プロジェクト: marmistrz/oioioi
def register_contest_dashboard_view(order=sys.maxint, condition=None):
    """Decorator for a view, which registers it as a contest dashboard.

       A view registered this way can be shown as the main page of the contest.
       If multiple views are registered, one with the lowest ``order`` for
       which the ``condition`` holds true is selected.

       :param order: value determining the order in which the dashboard is
                     selected
       :type order: int
       :param condition: decides if a dashboard can be selected
       :type condition: :class:`oioioi.base.permissions.Condition`
    """

    if condition is None:
        condition = Condition(lambda request: True)

    def decorator(view):
        _contest_dashboard_registry.register(
            _ContestDashboardEntry(view, condition), order)
        return view

    return decorator
コード例 #8
0
ファイル: tests.py プロジェクト: jakubste/oioioi
 def setUp(self):
     self.alwaysTrue = Condition(lambda x: True)
     self.alwaysFalse = Condition(lambda x: False)
     self.returnArg = Condition(lambda x: x)
     self.factory = self._fake_request_factory()