def test_side_menus_registry(self): admin = User.objects.get(username='******') user = User.objects.get(username='******') old_keys = side_pane_menus_registry.keys old_items = side_pane_menus_registry.items side_pane_menus_registry.keys = [] side_pane_menus_registry.items = [] try: side_pane_menus_registry.register(menu_registry, order=200) admin_menu_registry = MenuRegistry("Admin Menu", is_superuser) side_pane_menus_registry.register(admin_menu_registry, order=100) menu_registry.register('test', 'Test Menu Item', lambda request: '/test_menu_link', order=2) admin_menu_registry.register('test_admin', 'Test Admin Item', lambda request: '/spam', order=100) response = self._render_menu(user=user) self.assertIn('class="contesticon"', response) self.assertNotIn('User Menu', response) self.assertNotIn('Admin Menu', response) response = self._render_menu(user=admin) self.assertNotIn('class="contesticon"', response) self.assertIn('User Menu', response) self.assertIn('Admin Menu', response) self.assertLess(response.index('Test Admin Item'), response.index('Test Menu Item')) finally: side_pane_menus_registry.keys = old_keys side_pane_menus_registry.items = old_items
for model, model_admin in self._registry.items(): cls = model_admin.__class__ cls = getattr(cls, '__unmixed_class__', cls) self._registry[model] = cls(model, self) def get_urls(self): self._reinit_model_admins() return super(AdminSite, self).get_urls() def login(self, request, extra_context=None): query = urllib.urlencode({'next': request.get_full_path()}) return HttpResponseRedirect(reverse('auth_login') + '?' + query) site = AdminSite(name='oioioiadmin') system_admin_menu_registry = MenuRegistry(_("System Administration"), is_superuser) side_pane_menus_registry.register(system_admin_menu_registry, order=10) class OioioiUserAdmin(UserAdmin, ObjectWithMixins): __metaclass__ = ModelAdminMeta # This is handled by AdminSite._reinit_model_admins allow_too_late_mixins = True fieldsets = ( (None, {'fields': ('username', 'password')}), (_("Personal info"), {'fields': ('first_name', 'last_name', 'email')}), (_("Permissions"), {'fields': ('is_active', 'is_superuser', 'groups')}), (_("Important dates"), {'fields': ('last_login', 'date_joined')}),
from django.template.response import TemplateResponse from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.decorators import login_required from oioioi.contests.models import Submission from oioioi.base.permissions import enforce_condition from oioioi.contests.views import submission_template_context from oioioi.contests.utils import can_enter_contest from oioioi.rankings.views import any_ranking_visible from oioioi.base.menu import MenuRegistry, menu_registry from oioioi.base.permissions import not_anonymous from oioioi.messages.views import messages_template_context, \ visible_messages import itertools top_links_registry = MenuRegistry() top_links_registry.register('problems_list', _("Problems"), lambda request: reverse('problems_list', kwargs={'contest_id': request.contest.id}), order=100) top_links_registry.register('submit', _("Submit"), lambda request: reverse('submit', kwargs={'contest_id': request.contest.id}), order=200) top_links_registry.register('ranking', _("Ranking"), lambda request: reverse('default_ranking', kwargs={'contest_id': request.contest.id}), condition=any_ranking_visible, order=200) menu_registry.register('dashboard', _("Dashboard"),
from django.utils.translation import ugettext_lazy as _ from oioioi.base.menu import MenuRegistry navbar_links_registry = MenuRegistry(_("Navigation Bar Menu"))
from django.utils.translation import ugettext_lazy as _ from oioioi.base.menu import MenuRegistry, side_pane_menus_registry from oioioi.contests.utils import (can_see_personal_data, contest_exists, is_contest_basicadmin, is_contest_observer) contest_admin_menu_registry = MenuRegistry( _("Contest Administration"), contest_exists & is_contest_basicadmin) side_pane_menus_registry.register(contest_admin_menu_registry, order=100) contest_observer_menu_registry = MenuRegistry( _("Observer Menu"), contest_exists & is_contest_observer & (~is_contest_basicadmin)) side_pane_menus_registry.register(contest_observer_menu_registry, order=200) personal_data_menu_registry = MenuRegistry( _("Personal Data Menu"), contest_exists & can_see_personal_data) side_pane_menus_registry.register(personal_data_menu_registry, order=300)
import sys from django.core.urlresolvers import reverse from oioioi.base.menu import MenuRegistry from oioioi.base.permissions import Condition, enforce_condition from oioioi.portals.conditions import is_portal_admin portal_actions = {} node_actions = {} DEFAULT_ACTION_NAME = 'show_node' portal_admin_menu_registry = MenuRegistry(condition=is_portal_admin) 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
from django.utils.translation import ugettext_lazy as _ from oioioi.base.menu import MenuRegistry, side_pane_menus_registry teacher_menu_registry = MenuRegistry(_("Teacher Menu"), lambda request: request.user.has_perm('teachers.teacher')) side_pane_menus_registry.register(teacher_menu_registry, order=50)
from django.utils.translation import ugettext_lazy as _ from oioioi.base.menu import MenuRegistry from oioioi.base.permissions import not_anonymous from oioioi.contests.utils import contest_exists top_links_registry = MenuRegistry(_("Top Links Menu"), contest_exists & not_anonymous)
from django.utils.translation import ugettext_lazy as _ from oioioi.base.menu import MenuRegistry, side_pane_menus_registry from oioioi.contests.utils import is_contest_admin, is_contest_observer, \ contest_exists contest_admin_menu_registry = MenuRegistry(_("Contest Administration"), contest_exists & is_contest_admin) side_pane_menus_registry.register(contest_admin_menu_registry, order=100) contest_observer_menu_registry = MenuRegistry( _("Observer Menu"), contest_exists & is_contest_observer & (~is_contest_admin)) side_pane_menus_registry.register(contest_observer_menu_registry, order=200)
from django.template.response import TemplateResponse from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.decorators import login_required from oioioi.contests.models import Submission from oioioi.base.permissions import enforce_condition from oioioi.contests.views import submission_template_context from oioioi.contests.utils import can_enter_contest from oioioi.rankings.views import any_ranking_visible from oioioi.base.menu import MenuRegistry, menu_registry from oioioi.base.permissions import not_anonymous from oioioi.messages.views import messages_template_context, \ visible_messages import itertools top_links_registry = MenuRegistry() top_links_registry.register( 'problems_list', _("Problems"), lambda request: reverse('problems_list', kwargs={'contest_id': request.contest.id}), order=100) top_links_registry.register( 'submit', _("Submit"), lambda request: reverse('submit', kwargs={'contest_id': request.contest.id}), order=200)
from oioioi.base.menu import MenuRegistry teacher_menu_registry = MenuRegistry()
cls = model_admin.__class__ cls = getattr(cls, '__unmixed_class__', cls) self._registry[model] = cls(model, self) def get_urls(self): self._reinit_model_admins() return super(AdminSite, self).get_urls() def login(self, request, extra_context=None): query = urllib.urlencode({'next': request.get_full_path()}) return HttpResponseRedirect(reverse('auth_login') + '?' + query) site = AdminSite(name='oioioiadmin') contest_admin_menu_registry = MenuRegistry() system_admin_menu_registry = MenuRegistry() #contest_admin_menu_registry.register('dashboard', _("Dashboard"), # lambda request: reverse('oioioiadmin:index'), order=10) class OioioiUserAdmin(UserAdmin): fieldsets = ( (None, { 'fields': ('username', 'password') }), (_('Personal info'), { 'fields': ('first_name', 'last_name', 'email') }), (_('Permissions'), {