def test_duplicate_tag(self): class Widget(object): def __init__(self, name): self.name = name with self.assertRaises(ValueError): register_widget(Widget('youtube')) with self.assertRaises(ValueError): register_widget(Widget('problem_table'))
def render(self, request, m): rcontests = recent_contests(request) contests = list(visible_contests(request).difference(rcontests)) contests.sort(key=lambda x: x.creation_date, reverse=True) contests = (rcontests + contests)[:self.TO_SHOW + 1] default_contest = None if rcontests: default_contest = rcontests[0] elif contests: default_contest = contests[0] context = { 'contests': contests[:self.TO_SHOW], 'default_contest': default_contest, 'more_contests': len(contests) > self.TO_SHOW, 'is_teacher': request.user.has_perm('teachers.teacher'), 'is_inactive_teacher': request.user.is_authenticated() and bool( Teacher.objects.filter(user=request.user, is_active=False)) } return render_to_string('teachers/widgets/contest-selection.html', RequestContext(request, context)) register_widget(ContestSelectionWidget())
from django.template.loader import render_to_string from oioioi.gamification.utils import node_progress from oioioi.portals.widgets import register_widget import re class NodeProgressBarWidget(object): name = "gamification_nodeprogressbar" compiled_tag_regex = re.compile( r'\[\[NodeProgressBar\]\]' ) def render(self, request, m): completed, all = node_progress(request.current_node, request.user) progress_text = str(completed) + ' / ' + str(all) progress = (float(completed) / float(all)) if all > 0 else 0.0 return render_to_string( 'gamification/widgets/node-progress.html', {'percentage': progress * 100.0, 'text': progress_text} ) register_widget(NodeProgressBarWidget())
from django.template.loader import render_to_string from oioioi.gamification.utils import node_progress from oioioi.portals.widgets import register_widget import re class NodeProgressBarWidget(object): name = "gamification_nodeprogressbar" compiled_tag_regex = re.compile(r'\[\[NodeProgressBar\]\]') def render(self, request, m): completed, all = node_progress(request.current_node, request.user) progress_text = str(completed) + ' / ' + str(all) progress = (float(completed) / float(all)) if all > 0 else 0.0 return render_to_string('gamification/widgets/node-progress.html', { 'percentage': progress * 100.0, 'text': progress_text }) register_widget(NodeProgressBarWidget())
def ready(self): register_widget(NewsWidget()) register_widget(NewsfeedWidget())
class ContestSelectionWidget(object): name = 'contest_selection' compiled_tag_regex = re.compile(r'\[\[ContestSelection\]\]') TO_SHOW = getattr(settings, 'NUM_RECENT_CONTESTS', 5) def render(self, request, m): rcontests = recent_contests(request) contests = list(visible_contests(request).difference(rcontests)) contests.sort(key=lambda x: x.creation_date, reverse=True) contests = (rcontests + contests)[:self.TO_SHOW+1] default_contest = None if rcontests: default_contest = rcontests[0] elif contests: default_contest = contests[0] context = { 'contests': contests[:self.TO_SHOW], 'default_contest': default_contest, 'more_contests': len(contests) > self.TO_SHOW, 'is_teacher': request.user.has_perm('teachers.teacher'), 'is_inactive_teacher': request.user.is_authenticated() and bool(Teacher.objects.filter(user=request.user, is_active=False)) } return render_to_string('portals/widgets/contest_selection.html', RequestContext(request, context)) register_widget(ContestSelectionWidget())