Exemplo n.º 1
0
    def get_html(self):
        contest_data = self.get_data()
        card_content_table = TABLE(_class="bordered centered highlight",
                                   _style="line-height: 20px")
        tbody = TBODY()

        for contest in contest_data:
            tbody.append(
                TR(
                    TD(contest[0]),
                    TD(
                        IMG(_src=current.get_static_url("images/%s_small.png" %
                                                        str(contest[1])),
                            _class="parent-site-icon-small")),
                    TD(
                        A(I(_class="fa fa-external-link-square"),
                          _class=
                          "btn-floating btn-small accent-4 green view-contest",
                          _href=contest[2],
                          _target="_blank"))))

        card_content_table.append(tbody)

        card_html = BaseCard.get_html(
            self,
            **dict(card_title=self.card_title,
                   card_content=card_content_table,
                   cta_links=self.get_cta_html(),
                   card_color_class="white",
                   card_text_color_class="black-text"))
        return card_html
def render_trending_table(caption, problems, column_name, user_id):
    """
        Create trending table from the rows
    """
    T = current.T

    table = TABLE(_class="bordered centered")
    thead = THEAD(
        TR(TH(T("Problem")), TH(T("Recent Submissions")), TH(column_name)))
    table.append(thead)
    tbody = TBODY()

    for problem in problems:
        tr = TR()
        link_class = get_link_class(problem[0], user_id)
        link_title = (" ".join(link_class.split("-"))).capitalize()

        tr.append(
            TD(
                problem_widget(problem[1]["name"], problem[0], link_class,
                               link_title)))
        tr.append(TD(problem[1]["total_submissions"]))
        tr.append(TD(len(problem[1]["users"]) + \
                     len(problem[1]["custom_users"])))
        tbody.append(tr)

    table.append(tbody)
    table = DIV(H5(caption, _class="center"), HR(), table)

    return table
    def get_html(self):
        contest_data = self.get_data()
        card_content_table = TABLE(_class="bordered centered highlight",
                                   _style="line-height: 20px")
        tbody = TBODY()

        for contest in contest_data:
            try:
                start_time = datetime.datetime.strptime(
                    contest["start_time"], "%Y-%m-%dT%H:%M:%S.000Z")
                end_time = datetime.datetime.strptime(
                    contest["end_time"], "%Y-%m-%dT%H:%M:%S.000Z")

            except Exception as e:
                print "Unable to parse datetime", contest
                start_time = datetime.datetime.strptime(
                    contest["start_time"], "%Y-%m-%d %H:%M:%S %Z")
                end_time = datetime.datetime.strptime(contest["end_time"],
                                                      "%Y-%m-%d %H:%M:%S %Z")

            start_time += datetime.timedelta(minutes=330)
            end_time += datetime.timedelta(minutes=330)

            contest["start_time"] = start_time
            contest["end_time"] = end_time

            tbody.append(
                TR(
                    TD(contest["name"]),
                    TD(
                        IMG(_src=current.get_static_url(
                            "images/%s_small.png" %
                            str(contest["site"].lower())),
                            _class="parent-site-icon-small")),
                    TD(
                        A(I(_class="fa fa-external-link-square"),
                          _class=
                          "btn-floating btn-small accent-4 green view-contest",
                          _href=contest["url"],
                          _target="_blank")),
                    TD(utilities.get_reminder_button(contest))))

        card_content_table.append(tbody)

        card_html = BaseCard.get_html(
            self,
            **dict(card_title=self.card_title,
                   card_content=card_content_table,
                   cta_links=self.get_cta_html(),
                   card_color_class="white",
                   card_text_color_class="black-text"))
        return card_html
Exemplo n.º 4
0
    def get_html(self):
        submissions_data = self.get_data()

        card_content_table = TABLE(_class="bordered highlight")
        tbody = TBODY()

        for row in submissions_data:
            user_record = utilities.get_user_records([row[0]], "id", "id",
                                                     True)
            tr = TR(
                TD(
                    A(user_record.first_name + " " + user_record.last_name,
                      _href=URL("user",
                                "profile",
                                args=user_record.stopstalk_handle,
                                extension=False),
                      _target="_blank")))

            td = TD()
            for site in row[1]:
                if site == "total":
                    continue
                else:
                    td.append(
                        SPAN(IMG(_src=current.get_static_url(
                            "images/%s_small.png" % str(site).lower()),
                                 _class="parent-site-icon-very-small"),
                             " " + str(row[1][site]),
                             _style="padding-right: 10px;"))
            tr.append(td)
            tbody.append(tr)

        card_content_table.append(tbody)

        card_html = BaseCard.get_html(
            self,
            **dict(card_title=self.card_title,
                   card_content=card_content_table,
                   cta_links=self.get_cta_html(),
                   card_color_class="white",
                   card_text_color_class="black-text"))
        return card_html
Exemplo n.º 5
0
def render_table(submissions, duplicates=[]):
    """
        Create the HTML table from submissions
    """

    status_dict = {
        "AC": "Accepted",
        "WA": "Wrong Answer",
        "TLE": "Time Limit Exceeded",
        "MLE": "Memory Limit Exceeded",
        "RE": "Runtime Error",
        "CE": "Compile Error",
        "SK": "Skipped",
        "HCK": "Hacked",
        "OTH": "Others"
    }

    table = TABLE(_class="striped centered")
    table.append(
        THEAD(
            TR(TH("User Name"), TH("Site"), TH("Site Handle"),
               TH("Time of submission"), TH("Problem"), TH("Language"),
               TH("Status"), TH("Points"), TH("View Code"))))

    tbody = TBODY()
    for submission in submissions:
        tr = TR()
        append = tr.append
        span = SPAN()

        if submission.user_id:
            person_id = submission.user_id
        else:
            person_id = submission.custom_user_id

            # Check if the given custom_user is a duplicate
            # We need to do this because there might be a case
            # when a duplicate custom_user is created and then
            # his name or institute is changed
            for f in duplicates:
                if f[1] == person_id and f[0] != None:
                    person_id = current.db.custom_friend(f[0])
                    break
            span = SPAN(_class="orange tooltipped",
                        data={"position": "right",
                              "delay": "50",
                              "tooltip": "Custom User"},
                        _style="cursor: pointer; " + \
                                "float:right; " + \
                                "height:10px; " + \
                                "width:10px; " + \
                                "border-radius: 50%;")

        append(
            TD(
                DIV(
                    span,
                    A(person_id.first_name + " " + person_id.last_name,
                      _href=URL("user",
                                "profile",
                                args=[person_id.stopstalk_handle],
                                extension=False),
                      _target="_blank"))))
        append(TD(submission.site))
        append(
            TD(
                A(submission.site_handle,
                  _href=get_link(submission.site, submission.site_handle),
                  _target="_blank")))
        append(TD(submission.time_stamp))
        append(
            TD(
                A(submission.problem_name,
                  _href=URL("problems",
                            "index",
                            vars={
                                "pname": submission.problem_name,
                                "plink": submission.problem_link
                            },
                            extension=False),
                  _target="_blank")))
        append(TD(submission.lang))
        append(
            TD(
                IMG(_src=URL("static",
                             "images/" + submission.status + ".jpg",
                             extension=False),
                    _title=status_dict[submission.status],
                    _alt=status_dict[submission.status],
                    _style="height: 25px; width: 25px;")))
        append(TD(submission.points))

        if submission.view_link:
            append(
                TD(
                    A("View",
                      _href=submission.view_link,
                      _class="btn waves-light waves-effect",
                      _style="background-color: #FF5722",
                      _target="_blank")))
        else:
            append(TD())

        tbody.append(tr)
    table.append(tbody)
    return table
def render_table(submissions, duplicates=[], user_id=None):
    """
        Create the HTML table from submissions

        @param submissions (Dict): Dictionary of submissions to display
        @param duplicates (List): List of duplicate user ids

        @return (TABLE):  HTML TABLE containing all the submissions
    """

    T = current.T
    status_dict = {
        "AC": "Accepted",
        "WA": "Wrong Answer",
        "TLE": "Time Limit Exceeded",
        "MLE": "Memory Limit Exceeded",
        "RE": "Runtime Error",
        "CE": "Compile Error",
        "SK": "Skipped",
        "HCK": "Hacked",
        "PS": "Partially Solved",
        "OTH": "Others"
    }

    table = TABLE(_class="bordered centered submissions-table")
    table.append(
        THEAD(
            TR(TH(T("Name")),
               TH(T("Site Profile")), TH(T("Time of submission")),
               TH(T("Problem")), TH(T("Language")), TH(T("Status")),
               TH(T("Points")), TH(T("View/Download Code")))))

    tbody = TBODY()
    # Dictionary to optimize lookup for solved and unsolved problems
    # Multiple lookups in the main set is bad
    plink_to_class = {}

    for submission in submissions:
        span = SPAN()

        if submission.user_id:
            person_id = submission.user_id
        else:
            person_id = submission.custom_user_id

            # Check if the given custom_user is a duplicate
            # We need to do this because there might be a case
            # when a duplicate custom_user is created and then
            # his name or institute is changed
            for duplicate in duplicates:
                if duplicate[1] == person_id and duplicate[0]:
                    person_id = current.db.custom_friend(duplicate[0])
                    break

            span = SPAN(_class="orange tooltipped",
                        data={"position": "right",
                              "delay": "50",
                              "tooltip": T("Custom User")},
                        _style="cursor: pointer; " + \
                                "float:right; " + \
                                "height:10px; " + \
                                "width:10px; " + \
                                "border-radius: 50%;")

        tr = TR()
        append = tr.append
        append(
            TD(
                DIV(
                    span,
                    A(person_id.first_name + " " + person_id.last_name,
                      _href=URL("user",
                                "profile",
                                args=person_id.stopstalk_handle,
                                extension=False),
                      _class="submission-user-name",
                      _target="_blank"))))
        append(TD(A(IMG(_src=current.get_static_url("images/" + \
                                            submission.site.lower() + \
                                            "_small.png"),
                        _style="height: 30px; width: 30px;"),
                    _class="submission-site-profile",
                    _href=current.get_profile_url(submission.site,
                                                  submission.site_handle),
                    _target="_blank")))

        append(TD(submission.time_stamp, _class="stopstalk-timestamp"))

        link_class = ""
        plink = submission.problem_link
        if plink_to_class.has_key(plink):
            link_class = plink_to_class[plink]
        else:
            link_class = get_link_class(plink, user_id)
            plink_to_class[plink] = link_class

        link_title = (" ".join(link_class.split("-"))).capitalize()

        append(
            TD(
                problem_widget(submission.problem_name,
                               submission.problem_link, link_class,
                               link_title)))
        append(TD(submission.lang))
        append(
            TD(
                IMG(_src=current.get_static_url("images/" + submission.status +
                                                ".jpg"),
                    _title=status_dict[submission.status],
                    _alt=status_dict[submission.status],
                    _class="status-icon")))
        append(TD(submission.points))

        if submission.view_link:
            submission_data = {
                "view-link": submission.view_link,
                "site": submission.site
            }
            button_class = "btn waves-light waves-effect"
            if current.auth.is_logged_in():
                if submission.site != "HackerEarth":
                    td = TD(BUTTON(T("View"),
                                   _class="view-submission-button " + button_class,
                                   _style="background-color: #FF5722",
                                   data=submission_data),
                            " ",
                            BUTTON(T("Download"),
                                   _class="download-submission-button " + \
                                          button_class,
                                   _style="background-color: #2196F3",
                                   data=submission_data))
                else:
                    td = TD(
                        A(T("View"),
                          _href=submission.view_link,
                          _class="btn waves-light waves-effect",
                          _style="background-color: #FF5722",
                          _target="_blank"))
                append(td)
            else:
                append(
                    TD(
                        BUTTON(T("View"),
                               _class="btn tooltipped disabled",
                               _style="background-color: #FF5722",
                               data={
                                   "position": "bottom",
                                   "delay": "50",
                                   "tooltip": T("Login to View")
                               }), " ",
                        BUTTON(T("Download"),
                               _class="btn tooltipped disabled",
                               _style="background-color: #2196F3",
                               data={
                                   "position": "bottom",
                                   "delay": "50",
                                   "tooltip": T("Login to Download")
                               })))
        else:
            append(TD())

        tbody.append(tr)
    table.append(tbody)

    return table
Exemplo n.º 7
0
def render_table(submissions, duplicates=[]):
    """
        Create the HTML table from submissions
    """

    status_dict = {"AC": "Accepted",
                   "WA": "Wrong Answer",
                   "TLE": "Time Limit Exceeded",
                   "MLE": "Memory Limit Exceeded",
                   "RE": "Runtime Error",
                   "CE": "Compile Error",
                   "SK": "Skipped",
                   "HCK": "Hacked",
                   "OTH": "Others"}

    table = TABLE(_class="striped centered")
    table.append(THEAD(TR(TH("User Name"),
                          TH("Site"),
                          TH("Site Handle"),
                          TH("Time of submission"),
                          TH("Problem"),
                          TH("Language"),
                          TH("Status"),
                          TH("Points"),
                          TH("View Code"))))

    tbody = TBODY()
    for submission in submissions:
        tr = TR()
        append = tr.append
        span = SPAN()

        if submission.user_id:
            person_id = submission.user_id
        else:
            person_id = submission.custom_user_id

            # Check if the given custom_user is a duplicate
            # We need to do this because there might be a case
            # when a duplicate custom_user is created and then
            # his name or institute is changed
            for f in duplicates:
                if f[1] == person_id and f[0] != None:
                    person_id = current.db.custom_friend(f[0])
                    break
            span = SPAN(_class="orange tooltipped",
                        data={"position": "right",
                              "delay": "50",
                              "tooltip": "Custom User"},
                        _style="cursor: pointer; " + \
                                "float:right; " + \
                                "height:10px; " + \
                                "width:10px; " + \
                                "border-radius: 50%;")

        append(TD(DIV(span,
                      A(person_id.first_name + " " + person_id.last_name,
                        _href=URL("user", "profile",
                                  args=[person_id.stopstalk_handle],
                                  extension=False),
                        _target="_blank"))))
        append(TD(submission.site))
        append(TD(A(submission.site_handle,
                    _href=get_link(submission.site,
                                   submission.site_handle),
                    _target="_blank")))
        append(TD(submission.time_stamp))
        append(TD(A(submission.problem_name,
                    _href=URL("problems",
                              "index",
                              vars={"pname": submission.problem_name,
                                    "plink": submission.problem_link},
                              extension=False),
                    _target="_blank")))
        append(TD(submission.lang))
        append(TD(IMG(_src=URL("static",
                               "images/" + submission.status + ".jpg",
                               extension=False),
                      _title=status_dict[submission.status],
                      _alt=status_dict[submission.status],
                      _style="height: 25px; width: 25px;")))
        append(TD(submission.points))

        if submission.view_link:
            append(TD(A("View",
                        _href=submission.view_link,
                        _class="btn waves-light waves-effect",
                        _style="background-color: #FF5722",
                        _target="_blank")))
        else:
            append(TD())

        tbody.append(tr)
    table.append(tbody)
    return table
Exemplo n.º 8
0
def render_user_editorials_table(user_editorials,
                                 user_id=None,
                                 logged_in_user_id=None,
                                 read_editorial_class=""):
    """
        Render User editorials table

        @param user_editorials (Rows): Rows object of the editorials
        @param user_id (Number): For which user is the listing happening
        @param logged_in_user_id (Number): Which use is logged in
        @param read_editorial_class (String): HTML class for GA tracking

        @return (HTML): HTML table representing the user editorials
    """

    db = current.db
    atable = db.auth_user
    ptable = db.problem
    T = current.T

    user_ids = set([x.user_id for x in user_editorials])
    users = db(atable.id.belongs(user_ids)).select()
    user_mappings = {}
    for user in users:
        user_mappings[user.id] = user

    query = (ptable.id.belongs([x.problem_id for x in user_editorials]))
    problem_records = db(query).select(ptable.id, ptable.name, ptable.link)
    precords = {}
    for precord in problem_records:
        precords[precord.id] = {"name": precord.name, "link": precord.link}

    table = TABLE(_class="centered user-editorials-table")
    thead = THEAD(
        TR(TH(T("Problem")), TH(T("Editorial By")), TH(T("Added on")),
           TH(T("Votes")), TH()))
    tbody = TBODY()
    color_mapping = {"accepted": "green", "rejected": "red", "pending": "blue"}

    for editorial in user_editorials:
        if logged_in_user_id != 1 and user_id != editorial.user_id and editorial.verification != "accepted":
            continue

        user = user_mappings[editorial.user_id]
        record = precords[editorial.problem_id]
        number_of_votes = len(
            editorial.votes.split(",")) if editorial.votes else 0
        link_class = get_link_class(record["link"], logged_in_user_id)
        link_title = (" ".join(link_class.split("-"))).capitalize()
        tr = TR(
            TD(
                problem_widget(record["name"], record["link"], link_class,
                               link_title)))

        if logged_in_user_id is not None and \
           (editorial.user_id == logged_in_user_id or
            logged_in_user_id == 1):
            tr.append(TD(A(user.first_name + " " + user.last_name,
                         _href=URL("user",
                                   "profile",
                                   args=user.stopstalk_handle)),
                         " ",
                         DIV(editorial.verification.capitalize(),
                             _class="verification-badge " + \
                                    color_mapping[editorial.verification])))
        else:
            tr.append(
                TD(
                    A(user.first_name + " " + user.last_name,
                      _href=URL("user", "profile",
                                args=user.stopstalk_handle))))

        tr.append(TD(editorial.added_on))
        vote_class = ""
        if logged_in_user_id is not None and \
           str(logged_in_user_id) in set(editorial.votes.split(",")):
            vote_class = "red-text"
        tr.append(
            TD(
                DIV(SPAN(I(_class="fa fa-heart " + vote_class),
                         _class="love-editorial",
                         data={"id": editorial.id}),
                    " ",
                    DIV(number_of_votes,
                        _class="love-count",
                        _style="margin-left: 5px;"),
                    _style="display: inline-flex;")))

        actions_td = TD(
            A(I(_class="fa fa-eye fa-2x"),
              _href=URL("problems",
                        "read_editorial",
                        args=editorial.id,
                        extension=False),
              _class="btn btn-primary tooltipped " + read_editorial_class,
              _style="background-color: #13AA5F;",
              data={
                  "position": "bottom",
                  "delay": 40,
                  "tooltip": T("Read Editorial")
              }))
        if logged_in_user_id is not None and \
           (user.id == logged_in_user_id or logged_in_user_id == 1) and \
           editorial.verification != "accepted":
            actions_td.append(
                BUTTON(
                    I(_class="fa fa-trash fa-2x"),
                    _style="margin-left: 2%;",
                    _class="btn btn-primary red tooltipped delete-editorial",
                    data={
                        "position": "bottom",
                        "delay": 40,
                        "tooltip": T("Delete Editorial"),
                        "id": editorial.id
                    }))
        tr.append(actions_td)

        tbody.append(tr)

    table.append(thead)
    table.append(tbody)

    return table
Exemplo n.º 9
0
def render_table(submissions):
    """
        Create the HTML table from submissions
    """

    status_dict = {
        "AC": "Accepted",
        "WA": "Wrong Answer",
        "TLE": "Time Limit Exceeded",
        "MLE": "Memory Limit Exceeded",
        "RE": "Runtime Error",
        "CE": "Compile Error",
        "SK": "Skipped",
        "HCK": "Hacked",
        "OTH": "Others"
    }

    table = TABLE(_class="striped centered")
    table.append(
        THEAD(
            TR(TH("User Name"), TH("Site"), TH("Site Handle"),
               TH("Time of submission"), TH("Problem"), TH("Language"),
               TH("Status"), TH("Points"), TH("View Code"))))

    tbody = TBODY()
    for submission in submissions:
        tr = TR()
        append = tr.append

        person_id = submission.custom_user_id
        if submission.user_id:
            person_id = submission.user_id

        append(
            TD(
                A(person_id.first_name + " " + person_id.last_name,
                  _href=URL("user",
                            "profile",
                            args=[submission.stopstalk_handle]),
                  _target="_blank")))
        append(TD(submission.site))
        append(
            TD(
                A(submission.site_handle,
                  _href=get_link(submission.site, submission.site_handle),
                  _target="_blank")))
        append(TD(submission.time_stamp))
        append(
            TD(
                A(submission.problem_name,
                  _href=URL("problems",
                            "index",
                            vars={
                                "pname": submission.problem_name,
                                "plink": submission.problem_link
                            }),
                  _target="_blank")))
        append(TD(submission.lang))
        append(
            TD(
                IMG(_src=URL("static", "images/" + submission.status + ".jpg"),
                    _title=status_dict[submission.status],
                    _style="height: 25px; width: 25px;")))
        append(TD(submission.points))

        if submission.view_link:
            append(
                TD(
                    A("View",
                      _href=submission.view_link,
                      _class="btn waves-light waves-effect",
                      _style="background-color: #FF5722",
                      _target="_blank")))
        else:
            append(TD())

        tbody.append(tr)
    table.append(tbody)
    return table
Exemplo n.º 10
0
def render_table(submissions, duplicates=[]):
    """
        Create the HTML table from submissions

        @param submissions (Dict): Dictionary of submissions to display
        @param duplicates (List): List of duplicate user ids

        @return (TABLE):  HTML TABLE containing all the submissions
    """

    status_dict = {"AC": "Accepted",
                   "WA": "Wrong Answer",
                   "TLE": "Time Limit Exceeded",
                   "MLE": "Memory Limit Exceeded",
                   "RE": "Runtime Error",
                   "CE": "Compile Error",
                   "SK": "Skipped",
                   "HCK": "Hacked",
                   "PS": "Partially Solved",
                   "OTH": "Others"}

    table = TABLE(_class="bordered centered")
    table.append(THEAD(TR(TH("Name"),
                          TH("Site Profile"),
                          TH("Time of submission"),
                          TH("Problem"),
                          TH("Language"),
                          TH("Status"),
                          TH("Points"),
                          TH("View/Download Code"))))

    tbody = TBODY()
    # Dictionary to optimize lookup for solved and unsolved problems
    # Multiple lookups in the main set is bad
    plink_to_class = {}

    for submission in submissions:
        span = SPAN()

        if submission.user_id:
            person_id = submission.user_id
        else:
            person_id = submission.custom_user_id

            # Check if the given custom_user is a duplicate
            # We need to do this because there might be a case
            # when a duplicate custom_user is created and then
            # his name or institute is changed
            for duplicate in duplicates:
                if duplicate[1] == person_id and duplicate[0]:
                    person_id = current.db.custom_friend(duplicate[0])
                    break

            span = SPAN(_class="orange tooltipped",
                        data={"position": "right",
                              "delay": "50",
                              "tooltip": "Custom User"},
                        _style="cursor: pointer; " + \
                                "float:right; " + \
                                "height:10px; " + \
                                "width:10px; " + \
                                "border-radius: 50%;")

        tr = TR()
        append = tr.append
        append(TD(DIV(span,
                      A(person_id.first_name + " " + person_id.last_name,
                        _href=URL("user", "profile",
                                  args=person_id.stopstalk_handle,
                                  extension=False),
                        _target="_blank"))))
        append(TD(A(IMG(_src=URL("static",
                                 "images/" + \
                                 submission.site.lower() + \
                                 "_small.png"),
                        _style="height: 30px; width: 30px;"),
                    _href=current.get_profile_url(submission.site,
                                                  submission.site_handle),
                    _target="_blank")))

        append(TD(submission.time_stamp, _class="stopstalk-timestamp"))

        link_class = ""
        plink = submission.problem_link
        if plink_to_class.has_key(plink):
            link_class = plink_to_class[plink]
        else:
            if plink in current.solved_problems:
                link_class = "solved-problem"
            elif plink in current.unsolved_problems:
                link_class = "unsolved-problem"
            else:
                # This will prevent from further lookups
                link_class = "unattempted-problem"
            plink_to_class[plink] = link_class

        link_title = (" ".join(link_class.split("-"))).capitalize()

        append(TD(A(submission.problem_name,
                    _href=URL("problems",
                              "index",
                              vars={"pname": submission.problem_name,
                                    "plink": submission.problem_link},
                              extension=False),
                    _class=link_class,
                    _title=link_title,
                    _target="_blank")))
        append(TD(submission.lang))
        append(TD(IMG(_src=URL("static",
                               "images/" + submission.status + ".jpg",
                               extension=False),
                      _title=status_dict[submission.status],
                      _alt=status_dict[submission.status],
                      _style="height: 25px; width: 25px;")))
        append(TD(submission.points))

        if submission.view_link:
            submission_data = {"view-link": submission.view_link,
                               "site": submission.site}
            button_class = "btn waves-light waves-effect"
            if current.auth.is_logged_in():
                if submission.site != "HackerEarth":
                    td = TD(BUTTON("View",
                                   _class="view-submission-button " + button_class,
                                   _style="background-color: #FF5722",
                                   data=submission_data),
                            " ",
                            BUTTON("Download",
                                   _class="download-submission-button " + \
                                          button_class,
                                   _style="background-color: #2196F3",
                                   data=submission_data))
                else:
                    td = TD(A("View",
                              _href=submission.view_link,
                              _class="btn waves-light waves-effect",
                              _style="background-color: #FF5722",
                              _target="_blank"))
                append(td)
            else:
                append(TD(BUTTON("View",
                                 _class="btn tooltipped disabled",
                                 _style="background-color: #FF5722",
                                 data={"position": "bottom",
                                       "delay": "50",
                                       "tooltip": "Login to View"}),
                          " ",
                          BUTTON("Download",
                                 _class="btn tooltipped disabled",
                                 _style="background-color: #2196F3",
                                 data={"position": "bottom",
                                       "delay": "50",
                                       "tooltip": "Login to Download"})))
        else:
            append(TD())

        tbody.append(tr)
    table.append(tbody)

    return table
Exemplo n.º 11
0
def render_table(submissions, duplicates=[]):
    """
        Create the HTML table from submissions

        @param submissions (Dict): Dictionary of submissions to display
        @param duplicates (List): List of duplicate user ids

        @return (TABLE):  HTML TABLE containing all the submissions
    """

    status_dict = {"AC": "Accepted",
                   "WA": "Wrong Answer",
                   "TLE": "Time Limit Exceeded",
                   "MLE": "Memory Limit Exceeded",
                   "RE": "Runtime Error",
                   "CE": "Compile Error",
                   "SK": "Skipped",
                   "HCK": "Hacked",
                   "OTH": "Others"}

    table = TABLE(_class="striped centered")
    table.append(THEAD(TR(TH("User Name"),
                          TH("Site"),
                          TH("Site Handle"),
                          TH("Time of submission"),
                          TH("Problem"),
                          TH("Language"),
                          TH("Status"),
                          TH("Points"),
                          TH("View/Download Code"))))

    tbody = TBODY()
    for submission in submissions:
        span = SPAN()

        if submission.user_id:
            person_id = submission.user_id
        else:
            person_id = submission.custom_user_id

            # Check if the given custom_user is a duplicate
            # We need to do this because there might be a case
            # when a duplicate custom_user is created and then
            # his name or institute is changed
            for duplicate in duplicates:
                if duplicate[1] == person_id and duplicate[0]:
                    person_id = current.db.custom_friend(duplicate[0])
                    break

            span = SPAN(_class="orange tooltipped",
                        data={"position": "right",
                              "delay": "50",
                              "tooltip": "Custom User"},
                        _style="cursor: pointer; " + \
                                "float:right; " + \
                                "height:10px; " + \
                                "width:10px; " + \
                                "border-radius: 50%;")

        tr = TR()
        append = tr.append
        append(TD(DIV(span,
                      A(person_id.first_name + " " + person_id.last_name,
                        _href=URL("user", "profile",
                                  args=person_id.stopstalk_handle,
                                  extension=False),
                        _target="_blank"))))
        append(TD(submission.site))
        append(TD(A(submission.site_handle,
                    _href=get_link(submission.site,
                                   submission.site_handle),
                    _target="_blank")))
        append(TD(submission.time_stamp))
        append(TD(A(submission.problem_name,
                    _href=URL("problems",
                              "index",
                              vars={"pname": submission.problem_name,
                                    "plink": submission.problem_link},
                              extension=False),
                    _target="_blank")))
        append(TD(submission.lang))
        append(TD(IMG(_src=URL("static",
                               "images/" + submission.status + ".jpg",
                               extension=False),
                      _title=status_dict[submission.status],
                      _alt=status_dict[submission.status],
                      _style="height: 25px; width: 25px;")))
        append(TD(submission.points))

        if submission.view_link:
            if current.auth.is_logged_in():
                td = TD(A("View",
                          _href=submission.view_link,
                          _class="btn waves-light waves-effect",
                          _style="background-color: #FF5722",
                          _target="_blank"), " ")
                if submission.site != "HackerEarth":
                    td.append(A("Download",
                                _class="download-submission-button btn waves-light waves-effect",
                                _style="background-color: #2196F3",
                                _target="_blank",
                                data={"view-link": submission.view_link,
                                      "site": submission.site}))
                append(td)
            else:
                append(TD(A("View",
                            _class="btn tooltipped disabled",
                            _style="background-color: #FF5722",
                            _target="_blank",
                            data={"position": "bottom",
                                  "delay": "50",
                                  "tooltip": "Login to View"}),
                          " ",
                          A("Download",
                            _class="btn tooltipped disabled",
                            _style="background-color: #2196F3",
                            _target="_blank",
                            data={"position": "bottom",
                                  "delay": "50",
                                  "tooltip": "Login to Download"})))
        else:
            append(TD())

        tbody.append(tr)
    table.append(tbody)

    return table
Exemplo n.º 12
0
def render_table(submissions):
    """
        Create the HTML table from submissions
    """

    status_dict = {"AC": "Accepted",
                   "WA": "Wrong Answer",
                   "TLE": "Time Limit Exceeded",
                   "MLE": "Memory Limit Exceeded",
                   "RE": "Runtime Error",
                   "CE": "Compile Error",
                   "SK": "Skipped",
                   "HCK": "Hacked",
                   "OTH": "Others"}

    table = TABLE(_class="striped centered")
    table.append(THEAD(TR(TH("User Name"),
                          TH("Site"),
                          TH("Site Handle"),
                          TH("Time of submission"),
                          TH("Problem"),
                          TH("Language"),
                          TH("Status"),
                          TH("Points"),
                          TH("View Code"))))

    tbody = TBODY()
    for submission in submissions:
        tr = TR()
        append = tr.append

        person_id = submission.custom_user_id
        if submission.user_id:
            person_id = submission.user_id

        append(TD(A(person_id.first_name + " " + person_id.last_name,
                    _href=URL("user", "profile",
                              args=[submission.stopstalk_handle]),
                    _target="_blank")))
        append(TD(submission.site))
        append(TD(A(submission.site_handle,
                    _href=get_link(submission.site,
                                   submission.site_handle),
                    _target="_blank")))
        append(TD(submission.time_stamp))
        append(TD(A(submission.problem_name,
                    _href=URL("problems",
                              "index",
                              vars={"pname": submission.problem_name,
                                    "plink": submission.problem_link}),
                    _target="_blank")))
        append(TD(submission.lang))
        append(TD(IMG(_src=URL("static",
                               "images/" + submission.status + ".jpg"),
                      _title=status_dict[submission.status],
                      _style="height: 25px; width: 25px;")))
        append(TD(submission.points))

        if submission.view_link:
            append(TD(A("View",
                        _href=submission.view_link,
                        _class="btn waves-light waves-effect",
                        _style="background-color: #FF5722",
                        _target="_blank")))
        else:
            append(TD())

        tbody.append(tr)
    table.append(tbody)
    return table