示例#1
0
def submission_body(sub, hidden=True):
    class_ = join_classes('cs-submission__content', hidden and 'hidden')
    grade = str(int(sub.feedback.final_grade_pc or 0)
                if sub.has_feedback else _('Not given'))

    # Collect submission data
    sub_data_title = h3(_('Submission data'), class_="banner")
    sub_data = submission_data(sub)
    sub_data = \
        sub_data and \
        div('cs-submission__data')[
            submission_title,
            sub_data,
        ]

    return \
        div(class_=class_)[
            div(class_='cs-submission__description')[
                str(sub),

            ],

            div(class_='cs-submission__detail')[
                h3(_('Details'), class_='banner'),
                dl()[
                    dt(_('Grade')), dd(grade),
                    dt(_('Date of submission')), dd(str(sub.created)),
                ],
            ],

            sub_data,
        ]
示例#2
0
def feedback(feedback):
    raise NotImplementedError

    if feedback.is_correct:
        return \
            div(class_='cs-feedback')[
                p(CONGRATULATIONS, class_='cs-feedback__congratulations')
            ]
    else:
        with div(class_='cs-feedback') as root:
            root << h3(_(feedback.title), class_="iospec-feedback-title")

            if feedback.is_build_error:
                root << simple_error_message(feedback, _(
                    'An error occured while preparing your program for '
                    'execution. Please check the source code syntax.'
                ))

            elif feedback.is_timeout_error:
                root << p(_(
                    'Program execution was cancelled because it was taking '
                    'too long.'
                ))

            elif feedback.is_runtime_error:
                root << simple_error_message(feedback, _(
                    'An error occurred during program execution.'
                ))

            else:  # wrong answer/presentation
                root << feedback_wrong_answer(feedback)

        return root
示例#3
0
def submission_list(submissions, progress):
    """
    List all submissions and display extra information from progress.
    """

    final_grade = str(int(progress.final_grade_pc))
    num_submissions = str(progress.num_submissions)
    return \
        div(style='width: 100%')[
            div()[
                h2(_('Your grade')),
                dl()[
                    dt(_('Grade')), dd(final_grade + '%'),
                    dt(_('Num submissions')), dd(num_submissions),
                ]

            ],
            div()[
                h2(_('List of submissions')),
                p(_('(Click on an option to expand)')),
                mdl.div(shadow=4)[
                    [submission(sub) for sub in submissions],
                ]
            ],
            submission_script,
        ]
示例#4
0
def submission_body(sub, hidden=True):
    class_ = join_classes('cs-submission__content', hidden and 'hidden')
    grade = str(
        int(sub.feedback.final_grade_pc or 0) if sub.
        has_feedback else _('Not given'))

    # Collect submission data
    sub_data_title = h3(_('Submission data'), class_="banner")
    sub_data = submission_data(sub)
    sub_data = \
        sub_data and \
        div('cs-submission__data')[
            submission_title,
            sub_data,
        ]

    return \
        div(class_=class_)[
            div(class_='cs-submission__description')[
                str(sub),

            ],

            div(class_='cs-submission__detail')[
                h3(_('Details'), class_='banner'),
                dl()[
                    dt(_('Grade')), dd(grade),
                    dt(_('Date of submission')), dd(str(sub.created)),
                ],
            ],

            sub_data,
        ]
示例#5
0
def submission_list(submissions, progress):
    """
    List all submissions and display extra information from progress.
    """

    final_grade = str(int(progress.final_grade_pc))
    num_submissions = str(progress.num_submissions)
    return \
        div(style='width: 100%')[
            div()[
                h2(_('Your grade')),
                dl()[
                    dt(_('Grade')), dd(final_grade + '%'),
                    dt(_('Num submissions')), dd(num_submissions),
                ]

            ],
            div()[
                h2(_('List of submissions')),
                p(_('(Click on an option to expand)')),
                mdl.div(shadow=4)[
                    [submission(sub) for sub in submissions],
                ]
            ],
            submission_script,
        ]
示例#6
0
def feedback(feedback):
    raise NotImplementedError

    if feedback.is_correct:
        return \
            div(class_='cs-feedback')[
                p(CONGRATULATIONS, class_='cs-feedback__congratulations')
            ]
    else:
        with div(class_='cs-feedback') as root:
            root << h3(_(feedback.title), class_="iospec-feedback-title")

            if feedback.is_build_error:
                root << simple_error_message(
                    feedback,
                    _('An error occured while preparing your program for '
                      'execution. Please check the source code syntax.'))

            elif feedback.is_timeout_error:
                root << p(
                    _('Program execution was cancelled because it was taking '
                      'too long.'))

            elif feedback.is_runtime_error:
                root << simple_error_message(
                    feedback, _('An error occurred during program execution.'))

            else:  # wrong answer/presentation
                root << feedback_wrong_answer(feedback)

        return root
示例#7
0
def feedback_wrong_answer(feedback):
    return [
        div()[h4(_('Your response')),
              html(feedback.testcase), ],
        div()[h4(_('Expected answer')),
              html(feedback.answer_key), ]
    ]
示例#8
0
def feedback_wrong_answer(feedback):
    return [
        div()[
            h4(_('Your response')),
            html(feedback.testcase),
        ],
        div()[
            h4(_('Expected answer')),
            html(feedback.answer_key),
        ]
    ]
示例#9
0
def testcase_to_html(testcase, **kwargs):
    if len(testcase) == 0:
        return \
            div(**with_class(kwargs, 'iospec-testcase--empty'))[
                code('-- %s --' % str(EMPTY))
            ]
    return \
        div(**kwargs)[
            code()[
                [atom_to_html(x) for x in testcase]
            ]
        ]
示例#10
0
 def render_message(self):
     if self.is_correct:
         return super().render_message()
     return \
         div()[
             pre(self.error_message)
         ]
示例#11
0
def footer(class_=None, **kwargs):
    """
    Renders the default foot element.
    """

    class_ = join_classes('cs-foot', class_)
    return \
        div(class_=class_, **kwargs)[
            div(class_="cs-foot__copyright")[
                p([
                    'Copyright 2016 - ',
                    link('Codeschool <http://github.com/cslms/cs-server>')
                ]),
                p('Site gerenciado por Fábio M. Mendes na UnB/Gama.')
            ]
        ]
示例#12
0
def footer(class_=None, **kwargs):
    """
    Renders the default foot element.
    """

    class_ = join_classes('cs-foot', class_)
    return \
        div(class_=class_, **kwargs)[
            div(class_="cs-foot__copyright")[
                p([
                    'Copyright 2016 - ',
                    link('Codeschool <http://github.com/cslms/cs-server>')
                ]),
                p('Site gerenciado por Fábio M. Mendes na UnB/Gama.')
            ]
        ]
示例#13
0
 def render_message(self):
     if self.is_correct:
         return super().render_message()
     return \
         div()[
             pre(self.error_message)
         ]
示例#14
0
def iospec_to_html(iospec, **kwargs):
    """
    Renders IoSpec object as bricks HTML tags.
    """

    return \
        div(**kwargs)[
            tag_join(map(testcase_to_html, iospec)),
        ]
示例#15
0
def navbar(sections=None,
           class_=('cs-stripes-layout__sidebar', ),
           admin=False,
           admin_links=(),
           admin_perms=None,
           user=None,
           page=None):
    """
    Construct a navbar from a list of nav sections.

    Args:
        sections:
            List of sections.
        class:
            Optional class to root navbar div
        user:
            User making request.
        page:
            Page associated with request. Necessary for
        admin:
            If True or a callable of admin(page, user), it builds an admin
            section for allowed users.
        admin_perms:
            The permissions required to use the admin.
        admin_links:
            Any extra links to be included in the default admin section.
    """

    sections = list(sections or [])

    # Insert admin sections
    if admin:
        page_args = () if page is None else (page, )
        if admin_perms and user.has_perms(admin_perms, *page_args) or \
                user.is_superuser:
            if callable(admin):
                admin = admin(page, user)
            else:
                admin = navsection_page_admin(page, user, admin_links)
            sections.insert(0, admin)

    return div(class_=('cs-nav', ) + tuple(class_))[
        div(sections),
        img(class_='cs-nav__dingbat', src='/static/img/dingbat.svg')]
示例#16
0
def _head_nav(children=None, fabletter=None):
    return \
        nav(class_="cs-head__nav")[
            div(children, class_="cs-head__links"),
            mdl.button(class_='cs-head__fab', colored=True, fab=True,
                       id='cs-head--dropdown-trigger')[
                span(fabletter or '?', class_='dropdown-trigger')
            ],
            _head_menu(),
        ]
示例#17
0
def _head_nav(children=None, fabletter=None):
    return \
        nav(class_="cs-head__nav")[
            div(children, class_="cs-head__links"),
            mdl.button(class_='cs-head__fab', colored=True, fab=True,
                       id='cs-head--dropdown-trigger')[
                span(fabletter or '?', class_='dropdown-trigger')
            ],
            _head_menu(),
        ]
示例#18
0
def card_container(cards,
                   title=None,
                   description=None,
                   class_=None,
                   empty=None,
                   **kwargs):
    """
    A container for simple card elements.

    Args:
        cards:
            A list of cards.
        title:
            Title to show to the LHS of the container.
        description:
            Short description bellow title.
    """
    lhs_aside = None
    if title:
        cls = 'cs-card-container__aside mdl-cell mdl-cell--3-col'
        lhs_aside = \
            aside(class_=cls)[
                h1(title),
                description and p(description)
            ]

    ncols = 9 if title else 12
    cls = join_classes('cs-card-container mdl-grid mdl-grid--no-spacing',
                       class_)
    return \
        div(class_='bg-primary layout-wfull')[
            section(class_=cls)[
                ifset(title, lhs_aside),

                article(class_='mdl-cell mdl-cell--%s-col' % ncols)[
                    div(class_='cs-card-aside__content mdl-grid')[
                        cards or [empty],
                    ]
                ],
            ]
        ]
示例#19
0
def navbar(sections=None, class_=('cs-stripes-layout__sidebar',),
           admin=False, admin_links=(), admin_perms=None, user=None, page=None):
    """
    Construct a navbar from a list of nav sections.

    Args:
        sections:
            List of sections.
        class:
            Optional class to root navbar div
        user:
            User making request.
        page:
            Page associated with request. Necessary for
        admin:
            If True or a callable of admin(page, user), it builds an admin
            section for allowed users.
        admin_perms:
            The permissions required to use the admin.
        admin_links:
            Any extra links to be included in the default admin section.
    """

    sections = list(sections or [])

    # Insert admin sections
    if admin:
        page_args = () if page is None else (page,)
        if admin_perms and user.has_perms(admin_perms, *page_args) or \
                user.is_superuser:
            if callable(admin):
                admin = admin(page, user)
            else:
                admin = navsection_page_admin(page, user, admin_links)
            sections.insert(0, admin)

    return div(class_=('cs-nav',) + tuple(class_))[
        div(sections),
        img(class_='cs-nav__dingbat', src='/static/img/dingbat.svg')
    ]
示例#20
0
    def serve_ajax_submission(self, client, source=None, **kwargs):
        """
        Handles student responses via AJAX and a bricks program.
        """

        if source is None:
            client.dialog(div()[
                h2(_('Error')),
                p(class_='dialog-text')[_('Cannot send empty submissions.')]])

        return super().serve_ajax_submission(
            client=client,
            source=source,
        )
示例#21
0
def simple_card(title=None,
                text=None,
                href=None,
                icon='help',
                faded=False,
                onclick=None,
                id=None,
                class_=None,
                empty=False):
    """
    Returns HTML for a cs-card block.

    This function accepts multiple dispatch and clients might register
    different implementations for specific models/types.

    Args:
        title:
            Card title.
        text:
            Card description and main content.
        href:
            Optional address for the class icon.
        icon:
            Material icon for card.
        faded:
            If True, card is rendered with the faded state.
        onclick:
            Action to be associated with the onclick event.
        id/class_:
            Card's id/class attributes.
    """
    # Defaults for empty cards
    if empty:
        faded = True
        title = title or _('Empty')
        text = text or _('Not found'),
        icon = icon or 'do_not_disturb',

    class_ = js_class('cs-card mdl-shadow--4dp', 'mdl-cell', faded
                      and 'cs-card--faded', class_)
    icon = mdl.icon(class_='cs-card__icon')[icon]
    icon = a_or_span(href=href, onclick=onclick, class_='cs-card__link')[icon]

    return \
        div(class_=class_, id=id)[
            icon,
            title and h1(class_='cs-card__title')[title],
            text and p(text)
        ]
示例#22
0
    def serve_ajax_submission(self, client, source=None, **kwargs):
        """
        Handles student responses via AJAX and a bricks program.
        """

        if source is None:
            client.dialog(
                div()[
                    h2(_('Error')),
                    p(class_='dialog-text')[_('Cannot send empty submissions.')]
                ]
            )

        return super().serve_ajax_submission(
            client=client,
            source=source,
        )
示例#23
0
def head(links=None, user=None, class_=None, **kwargs):
    """
    Renders the default head element.

    Args:
        links:
            A list of hyperlinks that enter the main navigation area.
        user:
            The user requesting the page. The user name is used to set the
            fab button icon.
    """

    fabletter = None
    if user and not user.is_anonymous:
        fabletter = user.first_name[0:1] or user.username[0]

    return \
        div(class_=join_classes('cs-head', class_), **kwargs)[
            _head_logo(),
            _head_nav(links, fabletter=fabletter),
            _head_script(),

        ]
示例#24
0
def head(links=None, user=None, class_=None, **kwargs):
    """
    Renders the default head element.

    Args:
        links:
            A list of hyperlinks that enter the main navigation area.
        user:
            The user requesting the page. The user name is used to set the
            fab button icon.
    """

    fabletter = None
    if user and not user.is_anonymous:
        fabletter = user.first_name[0:1] or user.username[0]

    return \
        div(class_=join_classes('cs-head', class_), **kwargs)[
            _head_logo(),
            _head_nav(links, fabletter=fabletter),
            _head_script(),

        ]
示例#25
0
def _head_logo():
    return \
        div(class_="cs-logo")[
            img(class_="cs-logo__img", src='/static/img/logo.svg')
        ]
示例#26
0
def _head_logo():
    return \
        div(class_="cs-logo")[
            img(class_="cs-logo__img", src='/static/img/logo.svg')
        ]