コード例 #1
0
    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'))
コード例 #2
0
    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'))
コード例 #3
0
    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())
コード例 #4
0
ファイル: widgets.py プロジェクト: papedaniel/oioioi
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())
コード例 #5
0
ファイル: widgets.py プロジェクト: marmistrz/oioioi
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())
コード例 #6
0
ファイル: apps.py プロジェクト: sio2project/oioioi
 def ready(self):
     register_widget(NewsWidget())
     register_widget(NewsfeedWidget())
コード例 #7
0
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())