Ejemplo n.º 1
0
def viewProblem(request, *args, **kwargs):
    problem = Problem.get(kwargs.get('id'))
    user = User.getCurrent(request)

    contest = Contest.getCurrent()

    if not problem:
        return JsonResponse(data='', safe=False)

    if not user.isAdmin():
        # Hide the problems till the contest begins for non-admin users
        if not Contest.getCurrent():
            return JsonResponse(data='', safe=False)
        if problem not in Contest.getCurrent().problems:
            return JsonResponse(data='', safe=False)
    contents = []
    if contest == None or contest.showProblInfoBlocks == "On":
        contents = [
            Card("Problem Statement", formatMD(problem.statement), cls="stmt"),
            Card("Input Format", formatMD(problem.input), cls="inp"),
            Card("Output Format", formatMD(problem.output), cls="outp"),
            Card("Constraints",
                 formatMD(problem.constraints),
                 cls="constraints"),
        ]
    contents.append(
        div(cls="samples",
            contents=list(
                map(lambda x: getSample(x[0], x[1]),
                    zip(problem.sampleData, range(problem.samples))))))

    return HttpResponse(
        Page(
            h.input(type="hidden", id="problem-id", value=problem.id),
            h2(problem.title, cls="page-title"),
            div(cls="problem-description", contents=contents), CodeEditor(),
            div(cls="stmt card ui-sortable-handle blk-custom-input",
                contents=[
                    div(cls="card-header",
                        contents=[h2("Custom Input", cls="card-title")]),
                    div(cls="card-contents",
                        contents=[h.textarea(id="custom-input", cls="col-12")])
                ]),
            div(cls="align-right",
                id="custom-code-text",
                contents=[
                    h.input("Custom Input",
                            type="checkbox",
                            id="use-custom-input"),
                    h.button("Test Code",
                             cls="button test-samples button-white"),
                    h.button("Submit Code", cls="button submit-problem")
                ])))
Ejemplo n.º 2
0
    def __init__(self, prob: Problem, user: User):
        probpath = f"/problems/{prob.id}"

        btn = f"rejudgeAll('{prob.id}')" if user.isAdmin() else None

        title = prob.title
        if not user.isAdmin():
            # Compute problem status
            icon = ''
            result = ''
            for sub in Submission.all():
                if sub.problem != prob or sub.user != user or sub.status == Submission.STATUS_REVIEW:
                    continue

                if sub.user == user and "ok" == sub.result:
                    icon = "check"
                    break
                else:
                    icon = "times"

            if icon != '':
                result = f'<i class="fa fa-{icon}"></i> '

            title = result + title

        self.html = Card(title, prob.description, probpath, rejudge=btn)
Ejemplo n.º 3
0
 def __init__(self, contest: Contest):
     self.html = Card(contest.name,
                      div(
                          h.span(contest.start,
                                 cls='time-format',
                                 data_timestamp=contest.start), " - ",
                          h.span(contest.end,
                                 cls='time-format',
                                 data_timestamp=contest.end)),
                      link=f"/contests/{contest.id}",
                      delete=f"deleteContest('{contest.id}')",
                      cls=contest.id)
Ejemplo n.º 4
0
    def __init__(self, msglist, user):
        msg = msglist[0]
        msgType = "Announcement" if msg.isGeneral else "Message"

        body = msg.message
        for reply in msglist[1:]:
            body += f"""\n<br><br>Reply from {formatFrom(reply.fromUser, user)} at 
                <span class='time-format'>{reply.timestamp}</span>:<br>
                {reply.message}"""

        self.html = Card(
            f"{msgType} from {formatFrom(msg.fromUser, user)} at <span class='time-format'>{msg.timestamp}</span>",
            body,
            reply=f"reply('{msg.fromUser.id}', '{msg.id}')"
            if msg.isAdmin and user.isAdmin() else None)
Ejemplo n.º 5
0
def getSample(datum, num: int) -> Card:
    if datum.input == None: datum.input = ""
    if datum.output == None: datum.output = ""
    return Card(
        "Sample #{}".format(num),
        div(cls="row",
            contents=[
                div(cls="col-12",
                    contents=[
                        h.p("Input:", cls="no-margin"),
                        h.code(code_encode(datum.input))
                    ]),
                div(cls="col-12",
                    contents=[
                        h.p("Output:", cls="no-margin"),
                        h.code(code_encode(datum.output))
                    ])
            ]))
Ejemplo n.º 6
0
 def __init__(self, user: User):
     cls = "blue" if user.isAdmin() else ""
     self.html = div(cls="col-3",
                     contents=[
                         Card(div(
                             h.strong(h.i("Username:"******"username-hidden"),
                             h.br(cls="username-hidden"),
                             h.p("&quot;", cls="username-hidden"),
                             h2(user.username, cls="card-title"),
                             h.p("&quot;", cls="username-hidden")),
                              div(h.strong(h.i("Fullname:")), h.br(),
                                  f"&quot;{user.fullname}&quot;", h.br(),
                                  h.strong(h.i("Password:"******"&quot;{user.password}&quot;"),
                              delete=f"deleteUser('{user.username}')",
                              cls=cls)
                     ])
Ejemplo n.º 7
0
def editContest(request, *args, **kwargs):
    id = kwargs.get('id')
    contest = Contest.get(id)

    title = "New Contest"
    chooseProblem = ""
    existingProblems = []
    start = time.time() * 1000
    end = (time.time() + 3600) * 1000
    scoreboardOff = end
    displayFullname = False
    showProblInfoBlocks = ""

    showProblInfoBlocks_option = [
        h.option("On", value="On"),
        h.option("Off", value="Off")
    ]

    tieBreaker = False
    if contest:
        title = contest.name
        start = contest.start
        end = contest.end
        scoreboardOff = contest.scoreboardOff

        displayFullname = contest.displayFullname

        showProblInfoBlocks = contest.showProblInfoBlocks
        if showProblInfoBlocks == "Off":
            showProblInfoBlocks_option = [
                h.option("Off", value="Off"),
                h.option("On", value="On")
            ]
        tieBreaker = contest.tieBreaker

        chooseProblem = div(cls="actions",
                            contents=[
                                h.button("+ Choose Problem",
                                         cls="button",
                                         onclick="chooseProblemDialog()")
                            ])

        problems = [ProblemCard(prob) for prob in contest.problems]
        problemOptions = [
            h.option(prob.title, value=prob.id) for prob in Problem.all()
            if prob not in contest.problems
        ]

        existingProblems = [
            Modal(
                "Choose Problem",
                h.select(cls="form-control problem-choice",
                         contents=[h.option("-"), *problemOptions]),
                div(
                    h.button(
                        "Cancel", **{
                            "type": "button",
                            "class": "button button-white",
                            "data-dismiss": "modal"
                        }),
                    h.button(
                        "Add Problem", **{
                            "type": "button",
                            "class": "button",
                            "onclick": "chooseProblem()"
                        }))),
            div(cls="problem-cards", contents=problems)
        ]

    return HttpResponse(
        Page(
            h.input(type="hidden", id="contest-id", value=id),
            h.input(type="hidden", id="pageId", value="Contest"),
            h2(title, cls="page-title"),
            chooseProblem,
            Card(
                "Contest Details",
                div(
                    cls="contest-details",
                    contents=[
                        h.form(
                            cls="row",
                            contents=[
                                div(cls="form-group col-12",
                                    contents=[
                                        h.label(
                                            **{
                                                "for": "contest-name",
                                                "contents": "Name"
                                            }),
                                        h.input(cls="form-control",
                                                name="contest-name",
                                                id="contest-name",
                                                value=title)
                                    ]),
                                h.input(type="hidden", id="start",
                                        value=start),
                                div(cls="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for": "contest-start-date",
                                                "contents": "Start Date"
                                            }),
                                        h.input(cls="form-control",
                                                name="contest-start-date",
                                                id="contest-start-date",
                                                type="date")
                                    ]),
                                div(cls="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for": "contest-start-time",
                                                "contents": "Start Time"
                                            }),
                                        h.input(cls="form-control",
                                                name="contest-start-time",
                                                id="contest-start-time",
                                                type="time")
                                    ]),
                                h.input(type="hidden", id="end", value=end),
                                div(cls="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for": "contest-end-date",
                                                "contents": "End Date"
                                            }),
                                        h.input(cls="form-control",
                                                name="contest-end-date",
                                                id="contest-end-date",
                                                type="date")
                                    ]),
                                div(cls="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for": "contest-end-time",
                                                "contents": "End Time"
                                            }),
                                        h.input(cls="form-control",
                                                name="contest-end-time",
                                                id="contest-end-time",
                                                type="time")
                                    ]),
                                h.input(type="hidden",
                                        id="showProblInfoBlocks",
                                        value=showProblInfoBlocks),
                                div(cls="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for":
                                                "show-problem-info-blocks",
                                                "contents":
                                                "Show Problem Info Blocks"
                                            }),
                                        h.select(
                                            cls="form-control custom-select",
                                            name="show-problem-info-blocks",
                                            id="show-problem-info-blocks",
                                            contents=showProblInfoBlocks_option
                                        )
                                    ]),
                                h.input(type="hidden",
                                        id="scoreboardOff",
                                        value=scoreboardOff),
                                div(cls="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for":
                                                "scoreboard-off-time",
                                                "contents":
                                                "Turn Scoreboard Off Time"
                                            }),
                                        h.input(cls="form-control",
                                                name="scoreboard-off-time",
                                                id="scoreboard-off-time",
                                                type="time")
                                    ]),
                                div(cls="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for":
                                                "scoreboard-tie-breaker",
                                                "contents":
                                                "Sample Data Breaks Ties"
                                            }),
                                        h.select(
                                            cls="form-control",
                                            name="scoreboard-tie-breaker",
                                            id="scoreboard-tie-breaker",
                                            contents=[
                                                *[
                                                    h.option(
                                                        text,
                                                        value=val,
                                                        selected="selected")
                                                    if tieBreaker == val else
                                                    h.option(text, value=val)
                                                    for text, val in zip(
                                                        ("On", "Off"), (True,
                                                                        False))
                                                ]
                                            ])
                                    ]),

                                # Option to display a users' fullname
                                h.input(type="hidden",
                                        id="displayFullname",
                                        value=displayFullname),
                                div(cls="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for":
                                                "contest-display-fullname",
                                                "contents": "Show Full Name"
                                            }),
                                        h.select(
                                            cls="form-control",
                                            name="contest-display-fullname",
                                            id="contest-display-fullname",
                                            contents=[
                                                *[
                                                    h.option(
                                                        text,
                                                        value=val,
                                                        selected="selected") if
                                                    displayFullname == val else
                                                    h.option(text, value=val)
                                                    for text, val in zip(
                                                        ("On", "Off"), (True,
                                                                        False))
                                                ]
                                            ])
                                    ]),
                            ]),
                        div(cls="align-right col-12",
                            contents=[
                                h.button("Save",
                                         cls="button",
                                         onclick="editContest()")
                            ])
                    ])),
            *existingProblems))
Ejemplo n.º 8
0
 def __init__(self, prob: Problem):
     self.html = Card(prob.title,
                      prob.description,
                      link=f"/problems/{prob.id}/edit",
                      delete=f"deleteContestProblem('{prob.id}')",
                      cls=prob.id)