Esempio n. 1
0
def get_activity():

    if request.extension != "json":
        return dict(table="")
    stable = db.submission
    post_vars = request.post_vars
    date = post_vars["date"]
    if date is None:
        return dict(table="")
    handle = post_vars["handle"]
    start_time = date + " 00:00:00"
    end_time = date + " 23:59:59"

    query = (stable.time_stamp >= start_time) & \
            (stable.time_stamp <= end_time) & \
            (stable.stopstalk_handle == handle)
    submissions = db(query).select()

    if len(submissions) > 0:
        table = utilities.render_table(submissions)
        table = DIV(H3("Activity on " + date), table)
    else:
        table = H5("No activity on " + date)

    return dict(table=table)
Esempio n. 2
0
def get_activity():

    if request.extension != "json" or \
       request.vars.user_id is None or \
       request.vars.custom is None:
        raise HTTP(400, "Bad request")
        return

    user_id = int(request.vars.user_id)
    custom = (request.vars.custom == "True")

    stable = db.submission
    post_vars = request.post_vars
    date = post_vars["date"]
    if date is None:
        return dict(table="")
    start_time = date + " 00:00:00"
    end_time = date + " 23:59:59"

    query = (stable.time_stamp >= start_time) & \
            (stable.time_stamp <= end_time)

    if custom:
        query &= (stable.custom_user_id == user_id)
    else:
        query &= (stable.user_id == user_id)
    submissions = db(query).select(orderby=~stable.time_stamp)

    if len(submissions) > 0:
        table = utilities.render_table(submissions, [], session.user_id)
        table = DIV(H3(T("Activity on") + " " + date), table)
    else:
        table = H5(T("No activity on") + " " + date)

    return dict(table=table)
Esempio n. 3
0
def submissions():
    """
        Retrieve submissions of the logged-in user
    """

    if len(request.args) == 0:
        active = 1
    else:
        try:
            active = int(request.args[0])
        except ValueError:
            # The pagination page number is not integer
            raise HTTP(404)
            return

    cftable = db.custom_friend
    ftable = db.friends
    stable = db.submission
    atable = db.auth_user

    # Get all the friends/custom friends of the logged-in user
    friends, cusfriends = utilities.get_friends(session.user_id)

    # The Original IDs of duplicate custom_friends
    custom_friends = []
    for cus_id in cusfriends:
        if cus_id[1] is None:
            custom_friends.append(cus_id[0])
        else:
            custom_friends.append(cus_id[1])

    query = (stable.user_id.belongs(friends)) | \
            (stable.custom_user_id.belongs(custom_friends))
    total_count = db(query).count()

    PER_PAGE = current.PER_PAGE
    count = total_count / PER_PAGE
    if total_count % PER_PAGE:
        count += 1

    if request.extension == "json":
        return dict(count=count,
                    total_rows=1)

    user = session.auth.user
    db.sessions_today.insert(message="%s %s %d %s" % (user.first_name,
                                                      user.last_name,
                                                      user.id,
                                                      datetime.datetime.now()))

    offset = PER_PAGE * (active - 1)
    # Retrieve only some number of submissions from the offset
    rows = db(query).select(orderby=~db.submission.time_stamp,
                            limitby=(offset, offset + PER_PAGE))

    table = utilities.render_table(rows, cusfriends)
    return dict(table=table,
                friends=friends,
                cusfriends=cusfriends,
                total_rows=len(rows))
Esempio n. 4
0
def submissions():
    """
        Retrieve submissions of a specific user
        @ToDo: Bootstrap Pagination
    """

    custom = False

    if len(request.args) < 1:
        user_id = session.user_id
    else:
        row = db(db.auth_user.stopstalk_handle==request.args[0]).select().first()
        if row:
            user_id = row.id
        else:
            row = db(db.custom_friend.stopstalk_handle==request.args[0]).select().first()
            if row:
                user_id = row.id
                custom = True
            else:
                redirect(URL("default", "index"))

    stable = db.submission
    utilities.retrieve_submissions(user_id, custom)

    if custom:
        query = stable.custom_user_id == user_id
    else:
        query = stable.user_id == user_id

    submissions = db(query).select(orderby=~stable.time_stamp)
    table = utilities.render_table(submissions)
    return dict(table=table)
Esempio n. 5
0
def get_submissions_list():
    if request.vars.has_key("problem_id") is False:
        # Disables direct entering of a URL
        session.flash = T("Please click on a Problem Link")
        redirect(URL("default", "index"))
        return

    try:
        problem_id = int(request.vars["problem_id"])
    except ValueError:
        session.flash = T("Invalid problem!")
        redirect(URL("default", "index"))
        return

    submission_type = "friends"
    if request.vars.has_key("submission_type"):
        if request.vars["submission_type"] == "global":
            submission_type = "global"
        elif request.vars["submission_type"] == "my":
            submission_type = "my"

    if auth.is_logged_in() is False and submission_type != "global":
        response.flash = T("Login to view your/friends' submissions")
        submission_type = "global"

    stable = db.submission
    query = (stable.problem_id == problem_id)
    cusfriends = []

    if submission_type in ("my", "friends"):
        if auth.is_logged_in():
            if submission_type == "friends":
                friends, cusfriends = utilities.get_friends(session.user_id)
                # The Original IDs of duplicate custom_friends
                custom_friends = []
                for cus_id in cusfriends:
                    if cus_id[1] is None:
                        custom_friends.append(cus_id[0])
                    else:
                        custom_friends.append(cus_id[1])

                query &= (stable.user_id.belongs(friends)) | \
                         (stable.custom_user_id.belongs(custom_friends))
            else:
                query &= (stable.user_id == session.user_id)
        else:
            response.flash = T("Login to view your/friends' submissions")

    submissions = db(query).select(orderby=~stable.time_stamp,
                                   limitby=(0, 200))

    if len(submissions):
        table = utilities.render_table(submissions, cusfriends,
                                       session.user_id)
    else:
        table = DIV(T("No submissions found"))
    return table
def submissions():
    """
        Retrieve submissions of the logged-in user
    """

    if len(request.args) == 0:
        active = "1"
    else:
        active = request.args[0]

    cftable = db.custom_friend
    ftable = db.friends
    stable = db.submission
    atable = db.auth_user

    # Get all the friends/custom friends of the logged-in user
    friends, cusfriends = utilities.get_friends(session["user_id"])

    query = (stable.user_id.belongs(friends))
    query |= (stable.custom_user_id.belongs(cusfriends))
    total_count = db(query).count()

    PER_PAGE = current.PER_PAGE
    count = total_count / PER_PAGE
    if total_count % PER_PAGE:
        count += 1

    friend_query = (atable.id.belongs(friends))
    friends_list = db(friend_query).select(atable.id, atable.first_name,
                                           atable.last_name)
    all_friends = []
    for friend in friends_list:
        friend_name = friend["first_name"] + " " + friend["last_name"]
        all_friends.append([friend["id"], friend_name])

    cusfriend_query = (cftable.id.belongs(cusfriends))
    cusfriends_list = db(cusfriend_query).select(cftable.id,
                                                 cftable.first_name,
                                                 cftable.last_name)
    all_custom_friends = []
    for friend in cusfriends_list:
        friend_name = friend["first_name"] + " " + friend["last_name"]
        all_custom_friends.append([friend["id"], friend_name])

    if request.extension == "json":
        return dict(count=count,
                    friends=all_friends,
                    cusfriends=all_custom_friends)

    offset = PER_PAGE * (int(active) - 1)
    # Retrieve only some number of submissions from the offset
    rows = db(query).select(orderby=~db.submission.time_stamp,
                            limitby=(offset, offset + PER_PAGE))

    table = utilities.render_table(rows)
    return dict(table=table, friends=friends, cusfriends=cusfriends)
Esempio n. 7
0
def submissions():
    """
        Retrieve submissions of the logged-in user
    """

    if len(request.args) == 0:
        active = "1"
    else:
        active = request.args[0]

    cftable = db.custom_friend
    ftable = db.friends
    stable = db.submission
    atable = db.auth_user

    # Get all the friends/custom friends of the logged-in user
    friends, cusfriends = utilities.get_friends(session.user_id)

    # The Original IDs of duplicate custom_friends
    custom_friends = []
    for cus_id in cusfriends:
        if cus_id[1] is None:
            custom_friends.append(cus_id[0])
        else:
            custom_friends.append(cus_id[1])

    query = (stable.user_id.belongs(friends)) | \
            (stable.custom_user_id.belongs(custom_friends))
    total_count = db(query).count()

    PER_PAGE = current.PER_PAGE
    count = total_count / PER_PAGE
    if total_count % PER_PAGE:
        count += 1

    if request.extension == "json":
        return dict(count=count,
                    total_rows=1)

    user = session.auth.user
    db.sessions_today.insert(message="%s %s %s %s" % (user.first_name,
                                                      user.last_name,
                                                      user.institute,
                                                      datetime.datetime.now()))

    offset = PER_PAGE * (int(active) - 1)
    # Retrieve only some number of submissions from the offset
    rows = db(query).select(orderby=~db.submission.time_stamp,
                            limitby=(offset, offset + PER_PAGE))

    table = utilities.render_table(rows, cusfriends)
    return dict(table=table,
                friends=friends,
                cusfriends=cusfriends,
                total_rows=len(rows))
Esempio n. 8
0
def submissions():
    """
        Retrieve submissions of the logged-in user
    """

    if len(request.args) == 0:
        active = "1"
    else:
        active = request.args[0]

    cftable = db.custom_friend
    ftable = db.friends
    stable = db.submission
    atable = db.auth_user

    # Get all the friends/custom friends of the logged-in user
    friends, cusfriends = utilities.get_friends(session["user_id"])

    # The Original IDs of duplicate custom_friends
    custom_friends = []
    for cus_id in cusfriends:
        if cus_id[1] == None:
            custom_friends.append(cus_id[0])
        else:
            custom_friends.append(cus_id[1])

    query = (stable.user_id.belongs(friends)) | \
            (stable.custom_user_id.belongs(custom_friends))
    total_count = db(query).count()

    PER_PAGE = current.PER_PAGE
    count = total_count / PER_PAGE
    if total_count % PER_PAGE:
        count += 1

    if request.extension == "json":
        return dict(count=count, total_rows=1)

    offset = PER_PAGE * (int(active) - 1)
    # Retrieve only some number of submissions from the offset
    rows = db(query).select(orderby=~db.submission.time_stamp,
                            limitby=(offset, offset + PER_PAGE))

    table = utilities.render_table(rows, cusfriends)
    return dict(table=table,
                friends=friends,
                cusfriends=cusfriends,
                total_rows=len(rows))
Esempio n. 9
0
def submissions():
    """
        Retrieve submissions of the logged-in user
    """

    if len(request.args) == 0:
        active = "1"
    else:
        active = request.args[0]

    # Retrieve all the custom users created by the logged-in user
    query = db.custom_friend.user_id == session.user_id
    custom_friends = db(query).select(db.custom_friend.id)

    cusfriends = []
    for friend in custom_friends:
        cusfriends.append(friend.id)

    # Get the friends of logged in user
    query = db.friends.user_id == session.user_id
    friends = db(query).select(db.friends.friends_list).first()
    friends = tuple(eval(friends.friends_list))

    query = db.submission.user_id.belongs(friends)
    query |= db.submission.custom_user_id.belongs(cusfriends)
    count = db(query).count()
    count = count / 100 + 1

    if request.extension == "json":
        return dict(count=count)

    # Retrieve user submissions only on page 1
    if active == "1":
        for i in friends:
            utilities.retrieve_submissions(i)

        for i in cusfriends:
            utilities.retrieve_submissions(i, custom=True)

    offset = 100 * (int(active) - 1)
    # Retrieve only 100 submissions from the offset
    rows = db(query).select(orderby=~db.submission.time_stamp, limitby=(offset, offset + 100))

    table = utilities.render_table(rows)
    return dict(table=table)
Esempio n. 10
0
def submissions():
    """
        Retrieve submissions of the logged-in user
    """

    if len(request.args) == 0:
        active = "1"
    else:
        active = request.args[0]

    custom_friends = db(db.custom_friend.user_id == session.user_id).select(db.custom_friend.id)

    cusfriends = []
    for f in custom_friends:
        cusfriends.append(f.id)

    # Get the friends of logged in user
    query = (db.friends.user_id == session.user_id)
    friends = db(query).select(db.friends.friends_list).first()
    friends = tuple(eval(friends.friends_list))

    query = (db.submission.user_id.belongs(friends))
    query |= (db.submission.custom_user_id.belongs(cusfriends))
    count = db(query).count()
    count = count / 100 + 1

    if request.extension == "json":
        return dict(count=count)

    if active == "1":
        for i in friends:
            utilities.retrieve_submissions(i)

        for i in cusfriends:
            utilities.retrieve_submissions(i, custom=True)

    rows = db(query).select(orderby=~db.submission.time_stamp,
                            limitby=(100 * (int(active) - 1), (int(active) - 1) * 100 + 100))

    table = utilities.render_table(rows)
    return dict(table=table)
Esempio n. 11
0
def get_activity():

    if request.extension != "json":
        return dict(table="")

    if request.vars.user_id and request.vars.custom:
        user_id = int(request.vars.user_id)
        custom = (request.vars.custom == "True")
    else:
        raise HTTP(400, "Bad request")
        return
        redirect(URL("default", "index"))

    stable = db.submission
    post_vars = request.post_vars
    date = post_vars["date"]
    if date is None:
        return dict(table="")
    start_time = date + " 00:00:00"
    end_time = date + " 23:59:59"

    query = (stable.time_stamp >= start_time) & \
            (stable.time_stamp <= end_time)

    if custom:
        query &= (stable.custom_user_id == user_id)
    else:
        query &= (stable.user_id == user_id)
    submissions = db(query).select()

    if len(submissions) > 0:
        table = utilities.render_table(submissions)
        table = DIV(H3("Activity on " + date), table)
    else:
        table = H5("No activity on " + date)

    return dict(table=table)
Esempio n. 12
0
def get_activity():

    if request.extension != "json":
        return dict(table="")

    if request.vars.user_id and request.vars.custom:
        user_id = int(request.vars.user_id)
        custom = (request.vars.custom == "True")
    else:
        raise HTTP(400, "Bad request")
        return
        redirect(URL("default", "index"))

    stable = db.submission
    post_vars = request.post_vars
    date = post_vars["date"]
    if date is None:
        return dict(table="")
    start_time = date + " 00:00:00"
    end_time = date + " 23:59:59"

    query = (stable.time_stamp >= start_time) & \
            (stable.time_stamp <= end_time)

    if custom:
        query &= (stable.custom_user_id == user_id)
    else:
        query &= (stable.user_id == user_id)
    submissions = db(query).select()

    if len(submissions) > 0:
        table = utilities.render_table(submissions)
        table = DIV(H3("Activity on " + date), table)
    else:
        table = H5("No activity on " + date)

    return dict(table=table)
Esempio n. 13
0
def filters():
    """
        Apply multiple kind of filters on submissions
    """

    stable = db.submission
    get_vars = request.get_vars
    if len(request.args) == 0:
        page = 1
    else:
        page = int(request.args[0])
        page -= 1

    all_languages = db(stable).select(stable.lang, distinct=True)
    languages = [x["lang"] for x in all_languages]

    table = None
    global_submissions = False
    if get_vars.has_key("global"):
        if get_vars["global"] == "True":
            global_submissions = True

    # If form is not submitted
    if get_vars == {}:
        return dict(languages=languages,
                    div=DIV(),
                    global_submissions=global_submissions)

    # If nothing is filled in the form
    # these fields should be passed in
    # the URL with empty value
    compulsary_keys = ["pname", "name", "end_date", "start_date"]
    if set(compulsary_keys).issubset(get_vars.keys()) is False:
        session.flash = "Invalid URL parameters"
        redirect(URL("default", "filters"))

    # Form has been submitted
    cftable = db.custom_friend
    atable = db.auth_user
    ftable = db.friends
    duplicates = []

    switch = DIV(LABEL(
        H6("Friends' Submissions",
           INPUT(_type="checkbox", _id="submission-switch"),
           SPAN(_class="lever pink accent-3"), "Global Submissions")),
                 _class="switch")
    table = TABLE()
    div = TAG[""](H4("Recent Submissions"), switch, table)

    if global_submissions is False and not auth.is_logged_in():
        session.flash = "Login to view Friends' submissions"
        new_vars = request.vars
        new_vars["global"] = True
        redirect(URL("default", "filters", vars=new_vars, args=request.args))

    query = True
    username = get_vars["name"]
    if username != "":
        tmplist = username.split()
        for token in tmplist:
            query &= ((cftable.first_name.contains(token)) | \
                      (cftable.last_name.contains(token)) | \
                      (cftable.stopstalk_handle.contains(token)))

    if global_submissions is False:
        # Retrieve all the custom users created by the logged-in user
        query = (cftable.user_id == session.user_id) & query
    cust_friends = db(query).select(cftable.id, cftable.duplicate_cu)

    # The Original IDs of duplicate custom_friends
    custom_friends = []
    for cus_id in cust_friends:
        if cus_id.duplicate_cu:
            duplicates.append((cus_id.id, cus_id.duplicate_cu))
            custom_friends.append(cus_id.duplicate_cu)
        else:
            custom_friends.append(cus_id.id)

    query = True
    # Get the friends of logged in user
    if username != "":
        tmplist = username.split()
        username_query = False
        for token in tmplist:
            username_query |= ((atable.first_name.contains(token)) | \
                               (atable.last_name.contains(token)) | \
                               (atable.stopstalk_handle.contains(token)))
            for site in current.SITES:
                username_query |= (atable[site.lower() + \
                                   "_handle"].contains(token))

        query &= username_query

    # @ToDo: Anyway to use join instead of two such db calls
    possible_users = db(query).select(atable.id)
    possible_users = [x["id"] for x in possible_users]
    friends = possible_users

    if global_submissions is False:
        query = (ftable.user_id == session.user_id) & \
                (ftable.friend_id.belongs(possible_users))
        friend_ids = db(query).select(ftable.friend_id)
        friends = [x["friend_id"] for x in friend_ids]

        if session.user_id in possible_users:
            # Show submissions of user also
            friends.append(session.user_id)

    # User in one of the friends
    query = (stable.user_id.belongs(friends))

    # User in one of the custom friends
    query |= (stable.custom_user_id.belongs(custom_friends))

    start_date = get_vars["start_date"]
    end_date = get_vars["end_date"]

    # Else part ensures that both the dates passed
    # are included in the range
    if start_date == "":
        # If start date is empty start from the INITIAL_DATE
        start_date = current.INITIAL_DATE
    else:
        # Else append starting time for that day
        start_date += " 00:00:00"

    if end_date == "":
        # If end date is empty retrieve all submissions till now(current timestamp)
        # Current date/time
        end_date = str(datetime.datetime.today())
        # Remove the last milliseconds from the timestamp
        end_date = end_date[:-7]
    else:
        # Else append the ending time for that day
        end_date += " 23:59:59"

    start_time = time.strptime(start_date, "%Y-%m-%d %H:%M:%S")
    end_time = time.strptime(end_date, "%Y-%m-%d %H:%M:%S")

    if end_time > start_time:
        # Submissions in the the range start_date to end_date
        query &= (stable.time_stamp >= start_date) & \
                 (stable.time_stamp <= end_date)
    else:
        session.flash = "Start Date greater than End Date"
        redirect(URL("default", "filters"))

    pname = get_vars["pname"]
    # Submissions with problem name containing pname
    if pname != "":
        pname = pname.split()
        for token in pname:
            query &= (stable.problem_name.contains(token))

    # Check if multiple parameters are passed
    def _get_values_list(param_name):

        values_list = None
        if get_vars.has_key(param_name):
            values_list = get_vars[param_name]
            if isinstance(values_list, str):
                values_list = [values_list]
        elif get_vars.has_key(param_name + "[]"):
            values_list = get_vars[param_name + "[]"]
            if isinstance(values_list, str):
                values_list = [values_list]

        return values_list

    # Submissions from this site
    sites = _get_values_list("site")
    if sites:
        query &= (stable.site.belongs(sites))

    # Submissions with this language
    langs = _get_values_list("language")
    if langs:
        query &= (stable.lang.belongs(langs))

    # Submissions with this status
    statuses = _get_values_list("status")
    if statuses:
        query &= (stable.status.belongs(statuses))

    PER_PAGE = current.PER_PAGE
    # Apply the complex query and sort by time_stamp DESC
    filtered = db(query).select(limitby=(page * PER_PAGE,
                                         (page + 1) * PER_PAGE),
                                orderby=~stable.time_stamp)

    total_problems = db(query).count()
    total_pages = total_problems / 100
    if total_problems % 100 == 0:
        total_pages += 1

    table = utilities.render_table(filtered, duplicates)
    switch = DIV(LABEL(
        H6("Friends' Submissions",
           INPUT(_type="checkbox", _id="submission-switch"),
           SPAN(_class="lever pink accent-3"), "Global Submissions")),
                 _class="switch")
    div = TAG[""](switch, table)

    return dict(languages=languages,
                div=div,
                total_pages=total_pages,
                global_submissions=global_submissions)
Esempio n. 14
0
def filters():
    """
        Apply multiple kind of filters on submissions
    """

    stable = db.submission
    get_vars = request.get_vars
    if len(request.args) == 0:
        page = 1
    else:
        page = int(request.args[0])
        page -= 1

    all_languages = db(stable).select(stable.lang,
                                      distinct=True)
    languages = [x["lang"] for x in all_languages]

    table = None
    global_submissions = False
    if get_vars.has_key("global"):
        if get_vars["global"] == "True":
            global_submissions = True

    # If form is not submitted
    if get_vars == {}:
        return dict(languages=languages,
                    div=DIV(),
                    global_submissions=global_submissions)

    # If nothing is filled in the form
    # these fields should be passed in
    # the URL with empty value
    compulsary_keys = ["pname", "name", "end_date", "start_date"]
    if set(compulsary_keys).issubset(get_vars.keys()) is False:
        session.flash = "Invalid URL parameters"
        redirect(URL("default", "filters"))

    # Form has been submitted
    cftable = db.custom_friend
    atable = db.auth_user
    ftable = db.friends
    duplicates = []

    switch = DIV(LABEL(H6("Friends' Submissions",
                          INPUT(_type="checkbox", _id="submission-switch"),
                          SPAN(_class="lever pink accent-3"),
                          "Global Submissions")),
                 _class="switch")
    table = TABLE()
    div = TAG[""](H4("Recent Submissions"), switch, table)

    if global_submissions is False and not auth.is_logged_in():
        session.flash = "Login to view Friends' submissions"
        new_vars = request.vars
        new_vars["global"] = True
        redirect(URL("default", "filters",
                     vars=new_vars,
                     args=request.args))

    query = True
    username = get_vars["name"]
    if username != "":
        tmplist = username.split()
        for token in tmplist:
            query &= ((cftable.first_name.contains(token)) | \
                      (cftable.last_name.contains(token)))

    if global_submissions is False:
        # Retrieve all the custom users created by the logged-in user
        query = (cftable.user_id == session.user_id) & query
    cust_friends = db(query).select(cftable.id, cftable.duplicate_cu)

    # The Original IDs of duplicate custom_friends
    custom_friends = []
    for cus_id in cust_friends:
        if cus_id.duplicate_cu:
            duplicates.append((cus_id.id, cus_id.duplicate_cu))
            custom_friends.append(cus_id.duplicate_cu)
        else:
            custom_friends.append(cus_id.id)

    query = True
    # Get the friends of logged in user
    if username != "":
        tmplist = username.split()
        for token in tmplist:
            query &= ((atable.first_name.contains(token)) | \
                      (atable.last_name.contains(token)))

    # @ToDo: Anyway to use join instead of two such db calls
    possible_users = db(query).select(atable.id)
    possible_users = [x["id"] for x in possible_users]
    friends = possible_users

    if global_submissions is False:
        query = (ftable.user_id == session.user_id) & \
                (ftable.friend_id.belongs(possible_users))
        friend_ids = db(query).select(ftable.friend_id)
        friends = [x["friend_id"] for x in friend_ids]

        if session.user_id in possible_users:
            # Show submissions of user also
            friends.append(session.user_id)

    # User in one of the friends
    query = (stable.user_id.belongs(friends))

    # User in one of the custom friends
    query |= (stable.custom_user_id.belongs(custom_friends))

    start_date = get_vars["start_date"]
    end_date = get_vars["end_date"]

    # Else part ensures that both the dates passed
    # are included in the range
    if start_date == "":
        # If start date is empty start from the INITIAL_DATE
        start_date = current.INITIAL_DATE
    else:
        # Else append starting time for that day
        start_date += " 00:00:00"

    if end_date == "":
        # If end date is empty retrieve all submissions till now(current timestamp)
        # Current date/time
        end_date = str(datetime.datetime.today())
        # Remove the last milliseconds from the timestamp
        end_date = end_date[:-7]
    else:
        # Else append the ending time for that day
        end_date += " 23:59:59"

    start_time = time.strptime(start_date, "%Y-%m-%d %H:%M:%S")
    end_time = time.strptime(end_date, "%Y-%m-%d %H:%M:%S")

    if end_time > start_time:
        # Submissions in the the range start_date to end_date
        query &= (stable.time_stamp >= start_date) & \
                 (stable.time_stamp <= end_date)
    else:
        session.flash = "Start Date greater than End Date"
        redirect(URL("default", "filters"))

    pname = get_vars["pname"]
    # Submissions with problem name containing pname
    if pname != "":
        pname = pname.split()
        for token in pname:
            query &= (stable.problem_name.contains(token))

    # Check if multiple parameters are passed
    def get_values_list(param_name):

        values_list = None
        if get_vars.has_key(param_name):
            values_list = get_vars[param_name]
            if isinstance(values_list, str):
                values_list = [values_list]
        elif get_vars.has_key(param_name + "[]"):
            values_list = get_vars[param_name + "[]"]
            if isinstance(values_list, str):
                values_list = [values_list]

        return values_list

    # Submissions from this site
    sites = get_values_list("site")
    if sites:
        query &= (stable.site.belongs(sites))

    # Submissions with this language
    langs = get_values_list("language")
    if langs:
        query &= (stable.lang.belongs(langs))

    # Submissions with this status
    statuses = get_values_list("status")
    if statuses:
        query &= (stable.status.belongs(statuses))

    PER_PAGE = current.PER_PAGE
    # Apply the complex query and sort by time_stamp DESC
    filtered = db(query).select(limitby=(page * PER_PAGE,
                                         (page + 1) * PER_PAGE),
                                orderby=~stable.time_stamp)

    total_problems = db(query).count()
    total_pages = total_problems / 100
    if total_problems % 100 == 0:
        total_pages += 1

    table = utilities.render_table(filtered, duplicates)
    switch = DIV(LABEL(H6("Friends' Submissions",
                          INPUT(_type="checkbox", _id="submission-switch"),
                          SPAN(_class="lever pink accent-3"),
                          "Global Submissions")),
                 _class="switch")
    div = TAG[""](switch, table)

    return dict(languages=languages,
                div=div,
                total_pages=total_pages,
                global_submissions=global_submissions)
Esempio n. 15
0
def submissions():
    """
        Retrieve submissions of a specific user
    """

    custom = False
    atable = db.auth_user
    cftable = db.custom_friend
    handle = None
    duplicates = []

    if len(request.args) < 1:
        if auth.is_logged_in():
            user_id = session.user_id
            handle = session.handle
        else:
            redirect(URL("default", "index"))
    else:
        handle = request.args[0]
        query = (atable.stopstalk_handle == handle)
        row = db(query).select(atable.id, atable.first_name).first()
        if row is None:
            query = (cftable.stopstalk_handle == handle)
            row = db(query).select().first()
            if row:
                custom = True
                if row.duplicate_cu:
                    duplicates = [(row.id, row.duplicate_cu)]
                    handle = row.duplicate_cu.stopstalk_handle
            else:
                redirect(URL("default", "index"))

    if request.vars["page"]:
        page = request.vars["page"]
    else:
        page = "1"

    stable = db.submission
    query = (stable.stopstalk_handle == handle)

    PER_PAGE = current.PER_PAGE

    if request.extension == "json":
        total_submissions = db(query).count()
        page_count = total_submissions / PER_PAGE

        if total_submissions % PER_PAGE:
            page_count += 1

        return dict(page_count=page_count)

    offset = PER_PAGE * (int(page) - 1)
    all_submissions = db(query).select(orderby=~stable.time_stamp,
                                       limitby=(offset, offset + PER_PAGE))
    table = utilities.render_table(all_submissions, duplicates)

    if handle == session.handle:
        user = "******"
    else:
        user = row["first_name"]

    return dict(handle=handle,
                user=user,
                table=table,
                total_rows=len(all_submissions))
Esempio n. 16
0
def submissions():
    """
        Retrieve submissions of the logged-in user
    """

    if len(request.args) == 0:
        active = 1
    else:
        try:
            active = int(request.args[0])
        except ValueError:
            # The pagination page number is not integer
            raise HTTP(404)
            return

    cftable = db.custom_friend
    stable = db.submission
    atable = db.auth_user
    ptable = db.problem

    # Get all the friends/custom friends of the logged-in user
    friends, cusfriends = utilities.get_friends(session.user_id)

    # The Original IDs of duplicate custom_friends
    custom_friends = []
    for cus_id in cusfriends:
        if cus_id[1] is None:
            custom_friends.append(cus_id[0])
        else:
            custom_friends.append(cus_id[1])

    query = (stable.user_id.belongs(friends)) | \
            (stable.custom_user_id.belongs(custom_friends))
    total_count = db(query).count()

    PER_PAGE = current.PER_PAGE
    count = total_count / PER_PAGE
    if total_count % PER_PAGE:
        count += 1

    if request.extension == "json":
        return dict(count=count, total_rows=1)

    user = session.auth.user
    db.sessions_today.insert(
        message="%s %s %d %s" %
        (user.first_name, user.last_name, user.id, datetime.datetime.now()))

    offset = PER_PAGE * (active - 1)
    # Retrieve only some number of submissions from the offset
    rows = db(query).select(orderby=~db.submission.time_stamp,
                            limitby=(offset, offset + PER_PAGE))

    table = utilities.render_table(rows, cusfriends)

    country_value = session.auth.user.get("country")
    country = country_value if country_value else "not-available"

    country_form = None
    if country == "not-available":
        country_form = SQLFORM(db.auth_user,
                               session.auth.user,
                               fields=["country"],
                               showid=False)
        if country_form.process(onvalidation=current.sanitize_fields).accepted:
            session.auth.user = db.auth_user(session.user_id)
            session.flash = T("Country updated!")
            redirect(URL("default", "submissions", args=1))
        elif country_form.errors:
            response.flash = T("Form has errors")

    return dict(table=table,
                friends=friends,
                cusfriends=cusfriends,
                total_rows=len(rows),
                country=country,
                country_form=country_form)
Esempio n. 17
0
def index():
    """
        The main problem page
    """
    from json import dumps

    if request.vars.has_key("problem_id") is False:
        # Disables direct entering of a URL
        session.flash = T("Please click on a Problem Link")
        redirect(URL("default", "index"))
        return

    try:
        problem_id = int(request.vars["problem_id"])
    except ValueError:
        session.flash = T("Invalid problem!")
        redirect(URL("default", "index"))
        return

    submission_type = "friends"
    if request.vars.has_key("submission_type"):
        if request.vars["submission_type"] == "global":
            submission_type = "global"
        elif request.vars["submission_type"] == "my":
            submission_type = "my"

    if auth.is_logged_in() is False and submission_type != "global":
        response.flash = T("Login to view your/friends' submissions")
        submission_type = "global"

    stable = db.submission
    ptable = db.problem
    pstable = db.problem_setters

    problem_record = ptable(problem_id)
    if problem_record is None:
        session.flash = T("Please click on a Problem Link")
        redirect(URL("default", "index"))

    setters = db(pstable.problem_id == problem_id).select(pstable.handle)
    setters = [x.handle for x in setters]
    query = (stable.problem_id == problem_id)
    cusfriends = []

    if submission_type in ("my", "friends"):
        if auth.is_logged_in():
            if submission_type == "friends":
                friends, cusfriends = utilities.get_friends(session.user_id)
                # The Original IDs of duplicate custom_friends
                custom_friends = []
                for cus_id in cusfriends:
                    if cus_id[1] is None:
                        custom_friends.append(cus_id[0])
                    else:
                        custom_friends.append(cus_id[1])

                query &= (stable.user_id.belongs(friends)) | \
                         (stable.custom_user_id.belongs(custom_friends))
            else:
                query &= (stable.user_id == session.user_id)
        else:
            response.flash = T("Login to view your/friends' submissions")

    submissions = db(query).select(orderby=~stable.time_stamp,
                                   limitby=(0, 300))
    try:
        all_tags = problem_record.tags
        if all_tags:
            all_tags = eval(all_tags)
        else:
            all_tags = ["-"]
    except AttributeError:
        all_tags = ["-"]

    lower_site = utilities.urltosite(problem_record.link)
    site = utilities.get_actual_site(lower_site)
    problem_details = DIV(_class="row")
    details_table = TABLE(_style="font-size: 140%; float: left; width: 50%;")
    problem_class = ""

    link_class, link_title = utilities.get_link_class(problem_id, session.user_id)

    tbody = TBODY()
    tbody.append(TR(TD(),
                    TD(STRONG(T("Problem Name") + ":")),
                    TD(utilities.problem_widget(problem_record.name,
                                                problem_record.link,
                                                link_class,
                                                link_title,
                                                problem_id,
                                                anchor=False,
                                                disable_todo=True),
                       _id="problem_name")))
    tbody.append(TR(TD(),
                    TD(STRONG(T("Site") + ":")),
                    TD(site)))

    links = DIV(DIV(A(I(_class="fa fa-link"), " " + T("Problem"),
                      _href=problem_record.link,
                      _class="problem-page-site-link",
                      _style="color: black;",
                      _target="blank"),
                    _class="chip lime accent-3"),
                " ",
                DIV(A(I(_class="fa fa-book"), " " + T("Editorials"),
                      _href=URL("problems", "editorials", args=problem_record.id),
                      _class="problem-page-editorials",
                      _style="color: white;",
                      _target="_blank"),
                    _class="chip deep-purple darken-1",
                    _id="problem-page-editorial-button"))

    if auth.is_logged_in():
        links.append(DIV(A(I(_class="fa fa-edit"), " " + T("Suggest Difficulty"),
                             _style="color: white;"),
                         _class="chip",
                         _style="background-color: #9b4da9; cursor: pointer;",
                         _id="problem-page-difficulty-button"))
    tbody.append(TR(TD(),
                    TD(STRONG(T("Links") + ":")),
                    links))

    suggest_tags_class = "disabled btn chip tooltipped suggest-tags-plus-logged-out"
    suggest_tags_data = {"position": "right",
                         "delay": "50",
                         "tooltip": T("Login to suggest tags")}
    suggest_tags_id = "disabled-suggest-tags"
    if auth.is_logged_in():
        suggest_tags_class = "green chip waves-light waves-effect tooltipped suggest-tags-plus modal-trigger"
        suggest_tags_data["target"] = "suggest-tags-modal"
        suggest_tags_data["tooltip"] = T("Suggest tags")
        suggest_tags_id = "suggest-trigger"

    tbody.append(TR(TD(),
                    TD(STRONG(T("Tags") + ":")),
                    TD(DIV(SPAN(A(I(_class="fa fa-tag"), " Show Tags",
                                 _id="show-tags",
                                 _class="chip orange darken-1",
                                 data={"tags": dumps(all_tags)}),
                                _id="tags-span"),
                           " ",
                           BUTTON(I(_class="fa fa-plus"),
                                  _style="color: white; margin-top: 7px;",
                                  _class=suggest_tags_class,
                                  _id=suggest_tags_id,
                                  data=suggest_tags_data)))))

    if len(setters) > 0:
        tbody.append(TR(TD(),
                        TD(STRONG(T("Problem setters") + ":")),
                        TD(DIV(utilities.problem_setters_widget(setters,
                                                                site)))))

    details_table.append(tbody)
    problem_details.append(details_table)
    problem_details.append(DIV(_style="width: 50%; height: 200px; margin-top: 3%",
                               _id="chart_div",
                               _class="right"))

    if len(submissions):
        table = utilities.render_table(submissions, cusfriends, session.user_id)
    else:
        table = DIV(T("No submissions found"))

    return dict(site=site,
                problem_details=problem_details,
                problem_name=problem_record.name,
                problem_link=problem_record.link,
                problem_id=problem_id,
                submission_type=submission_type,
                submission_length=len(submissions),
                table=table)
Esempio n. 18
0
def index():
    """
        The main problem page
    """

    if request.vars.has_key("pname") == False or \
       request.vars.has_key("plink") == False:

        # Disables direct entering of a URL
        session.flash = "Please click on a Problem Link"
        redirect(URL("default", "index"))

    stable = db.submission
    ptable = db.problem_tags
    problem_name = request.vars["pname"]
    problem_link = request.vars["plink"]

    query = (stable.problem_link == problem_link)
    # If a user is logged-in then show his/her friends' submissions
    if session.auth:
        friends, cusfriends = utilities.get_friends(session.user_id)
        query &= (stable.user_id.belongs(friends)) | \
                 (stable.custom_user_id.belongs(cusfriends)) | \
                 (stable.user_id == session.user_id)

    submissions = db(query).select(orderby=~stable.time_stamp)

    try:
        query = (ptable.problem_link == problem_link)
        all_tags = db(query).select(ptable.tags).first()
        if all_tags:
            all_tags = eval(all_tags["tags"])
        else:
            all_tags = []
        if all_tags != [] and all_tags != ['-']:
            tags = DIV(_class="center")
            for tag in all_tags:
                tags.append(DIV(A(tag,
                                  _href=URL("problems",
                                            "tag",
                                            vars={"q": tag}),
                                  _style="color: white;",
                                  _target="_blank"),
                                _class="chip"))
                tags.append(" ")
        else:
            tags = DIV("No tags available")
    except AttributeError:
        tags = DIV("No tags available")

    problem_details = TABLE(_style="font-size: 140%;")
    tbody = TBODY()
    tbody.append(TR(TD(),
                    TD(STRONG("Problem Name:")),
                    TD(problem_name,
                       _id="problem_name"),
                    TD(_id="chart_div",
                       _style="width: 50%; height: 30%;",
                       _rowspan="4")))
    tbody.append(TR(TD(),
                    TD(STRONG("Site:")),
                    TD(urltosite(problem_link).capitalize())))
    tbody.append(TR(TD(),
                    TD(STRONG("Problem Link:")),
                    TD(A(I(_class="fa fa-link"), " Link",
                         _href=problem_link,
                         _target="_blank"))))
    tbody.append(TR(TD(),
                    TD(STRONG("Tags:")),
                    TD(tags)))
    problem_details.append(tbody)
    table = utilities.render_table(submissions)

    return dict(problem_details=problem_details,
                problem_name=problem_name,
                problem_link=problem_link,
                table=table)
Esempio n. 19
0
def index():
    """
        The main problem page
    """
    from json import dumps

    if request.vars.has_key("pname") is False or \
       request.vars.has_key("plink") is False:

        # Disables direct entering of a URL
        session.flash = "Please click on a Problem Link"
        redirect(URL("default", "index"))

    submission_type = "friends"
    if request.vars.has_key("submission_type"):
        if request.vars["submission_type"] == "global":
            submission_type = "global"
        elif request.vars["submission_type"] == "my":
            submission_type = "my"

    if auth.is_logged_in() is False and submission_type != "global":
        response.flash = "Login to view your/friends' submissions"
        submission_type = "global"

    stable = db.submission
    ptable = db.problem

    problem_name = request.vars["pname"]
    problem_link = request.vars["plink"]

    query = (stable.problem_link == problem_link)
    cusfriends = []

    if submission_type in ("my", "friends"):
        if auth.is_logged_in():
            if submission_type == "friends":
                friends, cusfriends = utilities.get_friends(session.user_id)
                # The Original IDs of duplicate custom_friends
                custom_friends = []
                for cus_id in cusfriends:
                    if cus_id[1] is None:
                        custom_friends.append(cus_id[0])
                    else:
                        custom_friends.append(cus_id[1])

                query &= (stable.user_id.belongs(friends)) | \
                         (stable.custom_user_id.belongs(custom_friends))
            else:
                query &= (stable.user_id == session.user_id)
        else:
            response.flash = "Login to view your/friends' submissions"

    submissions = db(query).select(orderby=~stable.time_stamp)

    try:
        query = (ptable.link == problem_link)
        all_tags = db(query).select(ptable.tags).first()
        if all_tags:
            all_tags = eval(all_tags["tags"])
        else:
            all_tags = ["-"]
    except AttributeError:
        all_tags = ["-"]

    site = utilities.urltosite(problem_link).capitalize()
    problem_details = DIV(_class="row")
    details_table = TABLE(_style="font-size: 140%;", _class="col s7")
    tbody = TBODY()
    tbody.append(TR(TD(),
                    TD(STRONG("Problem Name:")),
                    TD(problem_name,
                       _id="problem_name")))
    tbody.append(TR(TD(),
                    TD(STRONG("Site:")),
                    TD(site)))

    links = DIV(DIV(A(I(_class="fa fa-link"), " Problem",
                      _href=problem_link,
                      _style="color: black;",
                      _target="blank"),
                    _class="chip lime accent-3"))

    row = db(ptable.link == problem_link).select().first()
    if row and row.editorial_link:
        links.append(" ")
        links.append(DIV(A(I(_class="fa fa-book"), " Editorial",
                           _href=row.editorial_link,
                           _style="color: white;",
                           _target="_blank"),
                         _class="chip deep-purple darken-1"))
    tbody.append(TR(TD(),
                    TD(STRONG("Links:")),
                    links))

    suggest_tags_class = "disabled btn chip tooltipped"
    suggest_tags_data = {"position": "right",
                         "delay": "50",
                         "tooltip": "Login to suggest tags"}
    suggest_tags_id = "disabled-suggest-tags"
    if auth.is_logged_in():
        suggest_tags_class = "green chip waves-light waves-effect tooltipped"
        suggest_tags_data["target"] = "suggest-tags-modal"
        suggest_tags_data["tooltip"] = "Suggest tags"
        suggest_tags_id = "suggest-trigger"

    tbody.append(TR(TD(),
                    TD(STRONG("Tags:")),
                    TD(DIV(SPAN(A(I(_class="fa fa-tag"), " Show Tags",
                                 _id="show-tags",
                                 _class="chip orange darken-1",
                                 data={"tags": dumps(all_tags)}),
                                _id="tags-span"),
                           " ",
                           A(I(_class="fa fa-plus"),
                             _style="color: white",
                             _class=suggest_tags_class,
                             _id=suggest_tags_id,
                             data=suggest_tags_data)))))

    details_table.append(tbody)
    problem_details.append(details_table)
    problem_details.append(DIV(_class="col s5", _id="chart_div"))

    table = utilities.render_table(submissions, cusfriends)

    return dict(site=site,
                problem_details=problem_details,
                problem_name=problem_name,
                problem_link=problem_link,
                submission_type=submission_type,
                table=table)
Esempio n. 20
0
def index():
    """
        The main problem page
    """
    from json import dumps

    if request.vars.has_key("pname") is False or \
       request.vars.has_key("plink") is False:

        # Disables direct entering of a URL
        session.flash = T("Please click on a Problem Link")
        redirect(URL("default", "index"))

    submission_type = "friends"
    if request.vars.has_key("submission_type"):
        if request.vars["submission_type"] == "global":
            submission_type = "global"
        elif request.vars["submission_type"] == "my":
            submission_type = "my"

    if auth.is_logged_in() is False and submission_type != "global":
        response.flash = T("Login to view your/friends' submissions")
        submission_type = "global"

    stable = db.submission
    ptable = db.problem

    problem_name = request.vars["pname"]
    problem_link = request.vars["plink"]

    query = (stable.problem_link == problem_link)
    cusfriends = []

    if submission_type in ("my", "friends"):
        if auth.is_logged_in():
            if submission_type == "friends":
                friends, cusfriends = utilities.get_friends(session.user_id)
                # The Original IDs of duplicate custom_friends
                custom_friends = []
                for cus_id in cusfriends:
                    if cus_id[1] is None:
                        custom_friends.append(cus_id[0])
                    else:
                        custom_friends.append(cus_id[1])

                query &= (stable.user_id.belongs(friends)) | \
                         (stable.custom_user_id.belongs(custom_friends))
            else:
                query &= (stable.user_id == session.user_id)
        else:
            response.flash = T("Login to view your/friends' submissions")

    submissions = db(query).select(orderby=~stable.time_stamp)
    problem_record = db(ptable.link == problem_link).select().first()
    try:
        all_tags = problem_record.tags
        if all_tags:
            all_tags = eval(all_tags)
        else:
            all_tags = ["-"]
    except AttributeError:
        all_tags = ["-"]

    site = utilities.urltosite(problem_link).capitalize()
    problem_details = DIV(_class="row")
    details_table = TABLE(_style="font-size: 140%; float: left; width: 50%;")
    problem_class = ""

    link_class = utilities.get_link_class(problem_link, session.user_id)
    link_title = (" ".join(link_class.split("-"))).capitalize()

    tbody = TBODY()
    tbody.append(
        TR(
            TD(), TD(STRONG(T("Problem Name") + ":")),
            TD(utilities.problem_widget(problem_name,
                                        problem_link,
                                        link_class,
                                        link_title,
                                        anchor=False),
               _id="problem_name")))
    tbody.append(TR(TD(), TD(STRONG(T("Site") + ":")), TD(site)))

    links = DIV(
        DIV(A(I(_class="fa fa-link"),
              " " + T("Problem"),
              _href=problem_link,
              _class="problem-page-site-link",
              _style="color: black;",
              _target="blank"),
            _class="chip lime accent-3"))

    row = db(ptable.link == problem_link).select().first()
    if row:
        links.append(" ")
        links.append(
            DIV(A(I(_class="fa fa-book"),
                  " " + T("Editorials"),
                  _href=URL("problems", "editorials", args=row.id),
                  _class="problem-page-editorials",
                  _style="color: white;",
                  _target="_blank"),
                _class="chip deep-purple darken-1"))

    tbody.append(TR(TD(), TD(STRONG(T("Links") + ":")), links))

    suggest_tags_class = "disabled btn chip tooltipped suggest-tags-plus-logged-out"
    suggest_tags_data = {
        "position": "right",
        "delay": "50",
        "tooltip": T("Login to suggest tags")
    }
    suggest_tags_id = "disabled-suggest-tags"
    if auth.is_logged_in():
        suggest_tags_class = "green chip waves-light waves-effect tooltipped suggest-tags-plus modal-trigger"
        suggest_tags_data["target"] = "suggest-tags-modal"
        suggest_tags_data["tooltip"] = T("Suggest tags")
        suggest_tags_id = "suggest-trigger"

    tbody.append(
        TR(
            TD(), TD(STRONG(T("Tags") + ":")),
            TD(
                DIV(
                    SPAN(A(I(_class="fa fa-tag"),
                           " Show Tags",
                           _id="show-tags",
                           _class="chip orange darken-1",
                           data={"tags": dumps(all_tags)}),
                         _id="tags-span"), " ",
                    BUTTON(I(_class="fa fa-plus"),
                           _style="color: white; margin-top: 7px;",
                           _class=suggest_tags_class,
                           _id=suggest_tags_id,
                           data=suggest_tags_data)))))

    details_table.append(tbody)
    problem_details.append(details_table)
    problem_details.append(
        DIV(_style="width: 50%; margin-top: 3%",
            _id="chart_div",
            _class="right"))

    table = utilities.render_table(submissions, cusfriends, session.user_id)

    return dict(site=site,
                problem_details=problem_details,
                problem_name=problem_name,
                problem_link=problem_link,
                submission_type=submission_type,
                table=table)
Esempio n. 21
0
def index():
    """
        The main problem page
    """

    if request.vars.has_key("pname") == False or \
       request.vars.has_key("plink") == False:

        # Disables direct entering of a URL
        session.flash = "Please click on a Problem Link"
        redirect(URL("default", "index"))

    global_submissions = False
    if request.vars.has_key("global"):
        if request.vars["global"] == "True":
            global_submissions = True

    stable = db.submission
    ptable = db.problem_tags
    problem_name = request.vars["pname"]
    problem_link = request.vars["plink"]

    query = (stable.problem_link == problem_link)

    cusfriends = []

    if global_submissions is False:
        if session.user_id:
            friends, cusfriends = utilities.get_friends(session.user_id)
            # The Original IDs of duplicate custom_friends
            custom_friends = []
            for cus_id in cusfriends:
                if cus_id[1] == None:
                    custom_friends.append(cus_id[0])
                else:
                    custom_friends.append(cus_id[1])

            query &= (stable.user_id.belongs(friends)) | \
                     (stable.custom_user_id.belongs(custom_friends)) | \
                     (stable.user_id == session.user_id)
        else:
            session.flash = "Login to view Friends' Submissions"
            new_vars = request.vars
            new_vars["global"] = True
            redirect(URL("problems", "index", vars=new_vars))

    submissions = db(query).select(orderby=~stable.time_stamp)
    try:
        query = (ptable.problem_link == problem_link)
        all_tags = db(query).select(ptable.tags).first()
        if all_tags:
            all_tags = eval(all_tags["tags"])
        else:
            all_tags = []
        if all_tags != [] and all_tags != ['-']:
            tags = DIV(_class="center")
            for tag in all_tags:
                tags.append(
                    DIV(A(tag,
                          _href=URL("problems",
                                    "tag",
                                    vars={
                                        "q": tag,
                                        "page": 1
                                    }),
                          _style="color: white;",
                          _target="_blank"),
                        _class="chip"))
                tags.append(" ")
        else:
            tags = DIV("No tags available")
    except AttributeError:
        tags = DIV("No tags available")

    problem_details = TABLE(_style="font-size: 140%;")
    tbody = TBODY()
    tbody.append(
        TR(
            TD(), TD(STRONG("Problem Name:")),
            TD(problem_name, _id="problem_name"),
            TD(_id="chart_div",
               _style="width: 50%; height: 30%;",
               _rowspan="4")))
    tbody.append(
        TR(TD(), TD(STRONG("Site:")),
           TD(utilities.urltosite(problem_link).capitalize())))
    tbody.append(
        TR(
            TD(), TD(STRONG("Problem Link:")),
            TD(
                A(I(_class="fa fa-link"),
                  " Link",
                  _href=problem_link,
                  _target="_blank"))))
    tbody.append(TR(TD(), TD(STRONG("Tags:")), TD(tags)))
    problem_details.append(tbody)

    table = utilities.render_table(submissions, cusfriends)
    switch = DIV(LABEL(
        H6("Friends' Submissions",
           INPUT(_type="checkbox", _id="submission-switch"),
           SPAN(_class="lever pink accent-3"), "Global Submissions")),
                 _class="switch")
    div = TAG[""](H4("Recent Submissions"), switch, table)

    return dict(problem_details=problem_details,
                problem_name=problem_name,
                problem_link=problem_link,
                global_submissions=global_submissions,
                div=div)
Esempio n. 22
0
def index():
    """
        The main problem page
    """

    if request.vars.has_key("pname") == False or \
       request.vars.has_key("plink") == False:

        # Disables direct entering of a URL
        session.flash = "Please click on a Problem Link"
        redirect(URL("default", "index"))

    global_submissions = False
    if request.vars.has_key("global"):
        if request.vars["global"] == "True":
            global_submissions = True

    stable = db.submission
    ptable = db.problem_tags
    problem_name = request.vars["pname"]
    problem_link = request.vars["plink"]

    query = (stable.problem_link == problem_link)

    cusfriends = []

    if global_submissions is False:
        if session.user_id:
            friends, cusfriends = utilities.get_friends(session.user_id)
            # The Original IDs of duplicate custom_friends
            custom_friends = []
            for cus_id in cusfriends:
                if cus_id[1] == None:
                    custom_friends.append(cus_id[0])
                else:
                    custom_friends.append(cus_id[1])

            query &= (stable.user_id.belongs(friends)) | \
                     (stable.custom_user_id.belongs(custom_friends)) | \
                     (stable.user_id == session.user_id)
        else:
            session.flash = "Login to view Friends' Submissions"
            new_vars = request.vars
            new_vars["global"] = True
            redirect(URL("problems", "index",
                         vars=new_vars))

    submissions = db(query).select(orderby=~stable.time_stamp)
    try:
        query = (ptable.problem_link == problem_link)
        all_tags = db(query).select(ptable.tags).first()
        if all_tags:
            all_tags = eval(all_tags["tags"])
        else:
            all_tags = []
        if all_tags != [] and all_tags != ['-']:
            tags = DIV(_class="center")
            for tag in all_tags:
                tags.append(DIV(A(tag,
                                  _href=URL("problems",
                                            "tag",
                                            vars={"q": tag, "page": 1}),
                                  _style="color: white;",
                                  _target="_blank"),
                                _class="chip"))
                tags.append(" ")
        else:
            tags = DIV("No tags available")
    except AttributeError:
        tags = DIV("No tags available")

    problem_details = TABLE(_style="font-size: 140%;")
    tbody = TBODY()
    tbody.append(TR(TD(),
                    TD(STRONG("Problem Name:")),
                    TD(problem_name,
                       _id="problem_name"),
                    TD(_id="chart_div",
                       _style="width: 50%; height: 30%;",
                       _rowspan="4")))
    tbody.append(TR(TD(),
                    TD(STRONG("Site:")),
                    TD(utilities.urltosite(problem_link).capitalize())))
    tbody.append(TR(TD(),
                    TD(STRONG("Problem Link:")),
                    TD(A(I(_class="fa fa-link"), " Link",
                         _href=problem_link,
                         _target="_blank"))))
    tbody.append(TR(TD(),
                    TD(STRONG("Tags:")),
                    TD(tags)))
    problem_details.append(tbody)

    table = utilities.render_table(submissions, cusfriends)
    switch = DIV(LABEL(H6("Friends' Submissions",
                          INPUT(_type="checkbox", _id="submission-switch"),
                          SPAN(_class="lever pink accent-3"),
                          "Global Submissions")),
                 _class="switch")
    div = TAG[""](H4("Recent Submissions"), switch, table)

    return dict(problem_details=problem_details,
                problem_name=problem_name,
                problem_link=problem_link,
                global_submissions=global_submissions,
                div=div)
def index():
    """
        The main problem page
    """

    if request.vars.has_key("pname") == False or \
       request.vars.has_key("plink") == False:

        # Disables direct entering of a URL
        session.flash = "Please click on a Problem Link"
        redirect(URL("default", "index"))

    stable = db.submission
    ptable = db.problem_tags
    problem_name = request.vars["pname"]
    problem_link = request.vars["plink"]

    query = (stable.problem_link == problem_link)
    # If a user is logged-in then show his/her friends' submissions
    if session.auth:
        friends, cusfriends = utilities.get_friends(session.user_id)
        query &= (stable.user_id.belongs(friends)) | \
                 (stable.custom_user_id.belongs(cusfriends)) | \
                 (stable.user_id == session.user_id)

    submissions = db(query).select(orderby=~stable.time_stamp)

    try:
        query = (ptable.problem_link == problem_link)
        all_tags = db(query).select(ptable.tags).first()
        if all_tags:
            all_tags = eval(all_tags["tags"])
        else:
            all_tags = []
        if all_tags != [] and all_tags != ['-']:
            tags = DIV(_class="center")
            for tag in all_tags:
                tags.append(
                    DIV(A(tag,
                          _href=URL("problems", "tag", vars={"q": tag}),
                          _style="color: white;",
                          _target="_blank"),
                        _class="chip"))
                tags.append(" ")
        else:
            tags = DIV("No tags available")
    except AttributeError:
        tags = DIV("No tags available")

    problem_details = TABLE(_style="font-size: 140%;")
    tbody = TBODY()
    tbody.append(
        TR(
            TD(), TD(STRONG("Problem Name:")),
            TD(problem_name, _id="problem_name"),
            TD(_id="chart_div",
               _style="width: 50%; height: 30%;",
               _rowspan="4")))
    tbody.append(
        TR(TD(), TD(STRONG("Site:")),
           TD(urltosite(problem_link).capitalize())))
    tbody.append(
        TR(
            TD(), TD(STRONG("Problem Link:")),
            TD(
                A(I(_class="fa fa-link"),
                  " Link",
                  _href=problem_link,
                  _target="_blank"))))
    tbody.append(TR(TD(), TD(STRONG("Tags:")), TD(tags)))
    problem_details.append(tbody)
    table = utilities.render_table(submissions)

    return dict(problem_details=problem_details,
                problem_name=problem_name,
                problem_link=problem_link,
                table=table)
Esempio n. 24
0
def get_activity():

    if request.extension != "json" or \
       request.vars.user_id is None or \
       request.vars.custom is None:
        raise HTTP(400, "Bad request")
        return

    user_id = int(request.vars.user_id)
    custom = (request.vars.custom == "True")

    stable = db.submission
    uetable = db.user_editorials

    post_vars = request.post_vars
    date = post_vars["date"]
    if date is None:
        return dict(table="")
    start_time = date + " 00:00:00"
    end_time = date + " 23:59:59"

    query = (stable.time_stamp >= start_time) & \
            (stable.time_stamp <= end_time)

    ue_query = (uetable.added_on >= start_time) & \
               (uetable.added_on <= end_time)

    if custom is False and auth.is_logged_in() and session.user_id == user_id:
        ue_query &= True
    else:
        ue_query &= (uetable.verification == "accepted")

    if custom:
        query &= (stable.custom_user_id == user_id)
        ue_query &= False
    else:
        query &= (stable.user_id == user_id)
        ue_query &= (uetable.user_id == user_id)

    submissions = db(query).select(orderby=~stable.time_stamp)
    user_editorials = db(ue_query).select(orderby=~uetable.id)
    editorials_table = utilities.render_user_editorials_table(
        user_editorials, user_id,
        session.user_id if auth.is_logged_in() else None,
        "read-editorial-user-profile-page")

    if len(submissions) > 0 or len(user_editorials):
        div_element = DIV(H3(T("Activity on") + " " + date))
        if len(submissions) > 0:
            table = utilities.render_table(submissions, [], session.user_id)
            div_element.append(table)

            if len(user_editorials) > 0:
                div_element.append(BR())

        if len(user_editorials) > 0:
            div_element.append(editorials_table)
    else:
        div_element = H5(T("No activity on") + " " + date)

    return dict(table=div_element)
Esempio n. 25
0
def submissions():
    """
        Retrieve submissions of a specific user
    """

    custom = False
    atable = db.auth_user
    cftable = db.custom_friend
    handle = None
    duplicates = []
    row = None

    if len(request.args) < 1:
        if auth.is_logged_in():
            user_id = session.user_id
            handle = session.handle
        else:
            redirect(URL("default", "index"))
    else:
        handle = request.args[0]
        query = (atable.stopstalk_handle == handle)
        row = db(query).select(atable.id, atable.first_name).first()
        if row is None:
            query = (cftable.stopstalk_handle == handle)
            row = db(query).select().first()
            if row:
                custom = True
                user_id = row.id
                if row.duplicate_cu:
                    duplicates = [(row.id, row.duplicate_cu)]
                    user_id = row.duplicate_cu.id
            else:
                raise HTTP(404)
                return
        else:
            user_id = row.id

    if request.vars.page:
        page = request.vars.page
    else:
        page = "1"

    stable = db.submission

    query = (stable.user_id == user_id)
    if custom:
        query = (stable.custom_user_id == user_id)

    PER_PAGE = current.PER_PAGE

    if request.extension == "json":
        total_submissions = db(query).count()
        page_count = total_submissions / PER_PAGE

        if total_submissions % PER_PAGE:
            page_count += 1

        return dict(page_count=page_count)

    offset = PER_PAGE * (int(page) - 1)
    all_submissions = db(query).select(orderby=~stable.time_stamp,
                                       limitby=(offset, offset + PER_PAGE))
    table = utilities.render_table(all_submissions, duplicates,
                                   session.user_id)

    if handle == session.handle:
        user = "******"
    else:
        user = row["first_name"]

    return dict(handle=handle,
                user=user,
                table=table,
                total_rows=len(all_submissions))
Esempio n. 26
0
def submissions():
    """
        Retrieve submissions of a specific user
    """

    custom = False

    if len(request.args) < 1:
        if session.user_id:
            user_id = session.user_id
        else:
            redirect(URL("default", "index"))
    else:
        query = (db.auth_user.stopstalk_handle == request.args[0])
        row = db(query).select().first()
        if row:
            user_id = row.id
        else:
            query = (db.custom_friend.stopstalk_handle == request.args[0])
            row = db(query).select().first()
            if row:
                user_id = row.id
                custom = True
            else:
                redirect(URL("default", "index"))

    if request.vars["page"]:
        page = request.vars["page"]
    else:
        page = "1"

    stable = db.submission

    if custom:
        query = (stable.custom_user_id == user_id)
    else:
        query = (stable.user_id == user_id)

    PER_PAGE = current.PER_PAGE
    if request.extension == "json":
        total_submissions = db(query).count()
        page_count = total_submissions / PER_PAGE
        if total_submissions % PER_PAGE:
            page_count += 1
        return dict(page_count=page_count)

    offset = PER_PAGE * (int(page) - 1)
    all_submissions = db(query).select(orderby=~stable.time_stamp,
                                       limitby=(offset, offset + PER_PAGE))
    table = utilities.render_table(all_submissions)

    if user_id == session.user_id:
        user = "******"
    else:
        user = row["first_name"]

    c = "0"
    if custom:
        c = "1"

    return dict(c=c, user=user, user_id=user_id, table=table)
def filters():
    """
        Apply multiple kind of filters on submissions
    """

    stable = db.submission
    get_vars = request.get_vars
    if len(request.args) == 0:
        page = 1
    else:
        page = int(request.args[0])
        page -= 1

    all_languages = db(stable.id > 0).select(stable.lang, distinct=True)
    languages = []
    for i in all_languages:
        languages.append(i["lang"])

    table = None
    # If form is not submitted
    if get_vars == {}:
        return dict(languages=languages, table=table)

    # Form has been submitted
    cftable = db.custom_friend
    atable = db.auth_user
    ftable = db.friends

    if session.auth:
        # Retrieve all the custom users created by the logged-in user
        query = (cftable.first_name.contains(get_vars["name"]))
        query |= (cftable.last_name.contains(get_vars["name"]))
        query &= (cftable.user_id == session.user_id)
        custom_friends = db(query).select(cftable.id)
        cusfriends = [x["id"] for x in custom_friends]

    # Get the friends of logged in user
    query = (atable.first_name.contains(get_vars["name"]))
    query |= (atable.last_name.contains(get_vars["name"]))
    query &= (ftable.user_id == atable.id)
    friend_ids = db(atable).select(atable.id, join=ftable.on(query))
    friends = [x["id"] for x in friend_ids]

    # User in one of the friends
    query = (stable.user_id.belongs(friends))

    if session.auth:
        # User in one of the custom friends
        query |= (stable.custom_user_id.belongs(cusfriends))

    start_date = get_vars["start_date"]
    end_date = get_vars["end_date"]

    # Else part ensures that both the dates passed
    # are included in the range
    if start_date == "":
        # If start date is empty start from the INITIAL_DATE
        start_date = current.INITIAL_DATE
    else:
        # Else append starting time for that day
        start_date += " 00:00:00"

    if end_date == "":
        # If end date is empty retrieve all submissions till now(current timestamp)
        # Current date/time
        end_date = str(datetime.today())
        # Remove the last milliseconds from the timestamp
        end_date = end_date[:-7]
    else:
        # Else append the ending time for that day
        end_date += " 23:59:59"

    start_time = time.strptime(start_date, "%Y-%m-%d %H:%M:%S")
    end_time = time.strptime(end_date, "%Y-%m-%d %H:%M:%S")

    if end_time > start_time:
        # Submissions in the the range start_date to end_date
        query &= (stable.time_stamp >= start_date)
        query &= (stable.time_stamp <= end_date)
    else:
        session.flash = "Start Date greater than End Date"
        redirect(URL("default", "filters"))

    # Submissions with problem name containing pname
    if get_vars["pname"] != "":
        query &= (stable.problem_name.contains(get_vars["pname"]))

    # Submissions from this site
    if get_vars.has_key("site"):
        sites = get_vars["site"]
        if isinstance(sites, str):
            sites = [sites]
        query &= (stable.site.belongs(sites))

    # Submissions with this language
    if get_vars.has_key("language"):
        langs = get_vars["language"]
        if isinstance(langs, str):
            langs = [langs]
        query &= (stable.lang.belongs(langs))

    # Submissions with this submission status
    if get_vars.has_key("status"):
        statuses = get_vars["status"]
        if isinstance(statuses, str):
            statuses = [statuses]
        query &= (stable.status.belongs(statuses))

    PER_PAGE = current.PER_PAGE
    # Apply the complex query and sort by time_stamp DESC
    filtered = db(query).select(limitby=(page * PER_PAGE,
                                         (page + 1) * PER_PAGE),
                                orderby=~stable.time_stamp)
    total_pages = db(query).count()
    total_pages = total_pages / 100
    table = utilities.render_table(filtered)

    return dict(languages=languages, table=table, total_pages=total_pages)
Esempio n. 28
0
def submissions():
    """
        Retrieve submissions of a specific user
    """

    custom = False
    atable = db.auth_user
    cftable = db.custom_friend
    handle = None
    duplicates = []
    row = None

    if len(request.args) < 1:
        if auth.is_logged_in():
            user_id = session.user_id
            handle = session.handle
        else:
            redirect(URL("default", "index"))
    else:
        handle = request.args[0]
        row = utilities.get_user_records([handle], "stopstalk_handle",
                                         "stopstalk_handle", True)
        if row is None:
            query = (cftable.stopstalk_handle == handle)
            row = db(query).select().first()
            if row:
                custom = True
                user_id = row.id
                if row.duplicate_cu:
                    duplicates = [(row.id, row.duplicate_cu)]
                    user_id = row.duplicate_cu.id
            else:
                raise HTTP(404)
                return
        else:
            user_id = row.id

    if request.vars.page:
        page = request.vars.page
    else:
        page = "1"

    if int(page) > current.USER_PAGINATION_LIMIT and not auth.is_logged_in():
        session.flash = T("Please enter a valid page")
        redirect(URL("default", "index"))
        return

    stable = db.submission

    query = (stable.user_id == user_id)
    if custom:
        query = (stable.custom_user_id == user_id)

    PER_PAGE = current.PER_PAGE

    if request.extension == "json":
        total_submissions = db(query).count()
        if not auth.is_logged_in() and \
           total_submissions > current.USER_PAGINATION_LIMIT * PER_PAGE:
            total_submissions = current.USER_PAGINATION_LIMIT * PER_PAGE
        else:
            # User is logged in or total_submissions are less than our public
            # view limit of submissions
            pass
        page_count = total_submissions / PER_PAGE

        if total_submissions % PER_PAGE:
            page_count += 1

        return dict(page_count=page_count)

    offset = PER_PAGE * (int(page) - 1)
    all_submissions = db(query).select(orderby=~stable.time_stamp,
                                       limitby=(offset, offset + PER_PAGE))
    table = utilities.render_table(all_submissions, duplicates,
                                   session.user_id)

    if handle == session.handle:
        user = "******"
    else:
        user = row["first_name"]

    return dict(handle=handle,
                user=user,
                table=table,
                total_rows=len(all_submissions))
Esempio n. 29
0
def filters():
    """
        Apply multiple kind of filters on submissions
    """

    stable = db.submission
    get_vars = request.get_vars
    if len(request.args) == 0:
        page = 1
    else:
        page = int(request.args[0])
        page -= 1

    all_languages = db(stable.id > 0).select(stable.lang,
                                             distinct=True)
    languages = []
    for  i in all_languages:
        languages.append(i["lang"])

    table = None
    # If form is not submitted
    if get_vars == {}:
        return dict(languages=languages,
                    table=table)

    # Form has been submitted
    cftable = db.custom_friend
    atable = db.auth_user
    ftable = db.friends

    if session.auth:
        # Retrieve all the custom users created by the logged-in user
        query = (cftable.first_name.contains(get_vars["name"]))
        query |= (cftable.last_name.contains(get_vars["name"]))
        query &= (cftable.user_id == session.user_id)
        custom_friends = db(query).select(cftable.id)
        cusfriends = [x["id"] for x in custom_friends]

    # Get the friends of logged in user
    query = (atable.first_name.contains(get_vars["name"]))
    query |= (atable.last_name.contains(get_vars["name"]))
    query &= (ftable.user_id == atable.id)
    friend_ids = db(atable).select(atable.id, join=ftable.on(query))
    friends = [x["id"] for x in friend_ids]

    # User in one of the friends
    query = (stable.user_id.belongs(friends))

    if session.auth:
        # User in one of the custom friends
        query |= (stable.custom_user_id.belongs(cusfriends))

    start_date = get_vars["start_date"]
    end_date = get_vars["end_date"]

    # Else part ensures that both the dates passed
    # are included in the range
    if start_date == "":
        # If start date is empty start from the INITIAL_DATE
        start_date = current.INITIAL_DATE
    else:
        # Else append starting time for that day
        start_date += " 00:00:00"

    if end_date == "":
        # If end date is empty retrieve all submissions till now(current timestamp)
        # Current date/time
        end_date = str(datetime.today())
        # Remove the last milliseconds from the timestamp
        end_date = end_date[:-7]
    else:
        # Else append the ending time for that day
        end_date += " 23:59:59"

    start_time = time.strptime(start_date, "%Y-%m-%d %H:%M:%S")
    end_time = time.strptime(end_date, "%Y-%m-%d %H:%M:%S")

    if end_time > start_time:
        # Submissions in the the range start_date to end_date
        query &= (stable.time_stamp >= start_date)
        query &= (stable.time_stamp <= end_date)
    else:
        session.flash = "Start Date greater than End Date"
        redirect(URL("default", "filters"))

    # Submissions with problem name containing pname
    if get_vars["pname"] != "":
        query &= (stable.problem_name.contains(get_vars["pname"]))

    # Submissions from this site
    if get_vars.has_key("site"):
        sites = get_vars["site"]
        if isinstance(sites, str):
            sites = [sites]
        query &= (stable.site.belongs(sites))

    # Submissions with this language
    if get_vars.has_key("language"):
        langs = get_vars["language"]
        if isinstance(langs, str):
            langs = [langs]
        query &= (stable.lang.belongs(langs))

    # Submissions with this submission status
    if get_vars.has_key("status"):
        statuses = get_vars["status"]
        if isinstance(statuses, str):
            statuses = [statuses]
        query &= (stable.status.belongs(statuses))

    PER_PAGE = current.PER_PAGE
    # Apply the complex query and sort by time_stamp DESC
    filtered = db(query).select(limitby=(page * PER_PAGE,
                                         (page + 1) * PER_PAGE),
                                         orderby=~stable.time_stamp)
    total_pages = db(query).count()
    total_pages = total_pages / 100
    table = utilities.render_table(filtered)

    return dict(languages=languages,
                table=table,
                total_pages=total_pages)
Esempio n. 30
0
def submissions():
    """
        Retrieve submissions of the logged-in user
    """

    if len(request.args) == 0:
        active = "1"
    else:
        active = request.args[0]

    cftable = db.custom_friend
    ftable = db.friends
    stable = db.submission
    atable = db.auth_user

    # Get all the friends/custom friends of the logged-in user
    friends, cusfriends = utilities.get_friends(session["user_id"])

    query = (stable.user_id.belongs(friends))
    query |= (stable.custom_user_id.belongs(cusfriends))
    total_count = db(query).count()

    PER_PAGE = current.PER_PAGE
    count = total_count / PER_PAGE
    if total_count % PER_PAGE:
        count += 1

    friend_query = (atable.id.belongs(friends))
    friends_list = db(friend_query).select(atable.id,
                                           atable.first_name,
                                           atable.last_name)
    all_friends = []
    for friend in friends_list:
        friend_name = friend["first_name"] + " " + friend["last_name"]
        all_friends.append([friend["id"],
                            friend_name])

    cusfriend_query = (cftable.id.belongs(cusfriends))
    cusfriends_list = db(cusfriend_query).select(cftable.id,
                                                 cftable.first_name,
                                                 cftable.last_name)
    all_custom_friends = []
    for friend in cusfriends_list:
        friend_name = friend["first_name"] + " " + friend["last_name"]
        all_custom_friends.append([friend["id"],
                                   friend_name])

    if request.extension == "json":
        return dict(count=count,
                    friends=all_friends,
                    cusfriends=all_custom_friends)

    offset = PER_PAGE * (int(active) - 1)
    # Retrieve only some number of submissions from the offset
    rows = db(query).select(orderby=~db.submission.time_stamp,
                            limitby=(offset, offset + PER_PAGE))

    table = utilities.render_table(rows)
    return dict(table=table,
                friends=friends,
                cusfriends=cusfriends)
Esempio n. 31
0
def submissions():
    """
        Retrieve submissions of a specific user
    """

    custom = False

    if len(request.args) < 1:
        if session.user_id:
            user_id = session.user_id
        else:
            redirect(URL("default", "index"))
    else:
        query = (db.auth_user.stopstalk_handle == request.args[0])
        row = db(query).select().first()
        if row:
            user_id = row.id
        else:
            query = (db.custom_friend.stopstalk_handle == request.args[0])
            row = db(query).select().first()
            if row:
                user_id = row.id
                custom = True
            else:
                redirect(URL("default", "index"))

    if request.vars["page"]:
        page = request.vars["page"]
    else:
        page = "1"

    stable = db.submission

    if custom:
        query = (stable.custom_user_id == user_id)
    else:
        query = (stable.user_id == user_id)

    PER_PAGE = current.PER_PAGE
    if request.extension == "json":
        total_submissions = db(query).count()
        page_count = total_submissions / PER_PAGE
        if total_submissions % PER_PAGE:
            page_count += 1
        return dict(page_count=page_count)

    offset = PER_PAGE * (int(page) - 1)
    all_submissions = db(query).select(orderby=~stable.time_stamp,
                                       limitby=(offset, offset + PER_PAGE))
    table = utilities.render_table(all_submissions)

    if user_id == session.user_id:
        user = "******"
    else:
        user = row["first_name"]

    c = "0"
    if custom:
        c = "1"

    return dict(c=c,
                user=user,
                user_id=user_id,
                table=table)