Esempio n. 1
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. 2
0
def custom_friend():
    """
        Controller to add a Custom Friend
    """

    list_fields = ["first_name", "last_name", "institute", "stopstalk_handle"]

    for site in current.SITES:
        list_fields += [site.lower() + "_handle"]

    form = SQLFORM(db.custom_friend,
                   fields=list_fields,
                   hidden=dict(user_id=session.user_id,
                               last_retrieved=datetime.now()))

    # Set the hidden field
    form.vars.user_id = session.user_id
    form.process()

    if form.accepted:
        utilities.retrieve_submissions(form.vars.id, custom=True)
        session.flash = "Submissions for custom user added"
        redirect(URL("default", "submissions", args=[1]))

    return dict(form=form)
Esempio n. 3
0
def custom_friend():
    """
        Controller to add a Custom Friend
    """

    list_fields = ["first_name",
                   "last_name",
                   "institute",
                   "stopstalk_handle"]

    for site in current.SITES:
        list_fields += [site.lower() + "_handle"]

    form = SQLFORM(db.custom_friend,
                   fields=list_fields,
                   hidden=dict(user_id=session.user_id,
                               last_retrieved=datetime.now()))

    # Set the hidden field
    form.vars.user_id = session.user_id
    form.process()

    if form.accepted:
        utilities.retrieve_submissions(form.vars.id,
                                       custom=True)
        session.flash = "Submissions for custom user added"
        redirect(URL("default", "submissions", args=[1]))

    return dict(form=form)
Esempio n. 4
0
def update_friend():
    """
        Update custom friend details
    """

    if len(request.args) != 1:
        session.flash = "Please click one of the buttons"
        redirect(URL("user", "edit_custom_friend_details"))

    cftable = db.custom_friend

    query = (cftable.user_id == session["user_id"])
    query &= (cftable.id == request.args[0])
    row = db(query).select(cftable.id)
    if len(row) == 0:
        session.flash = "Please click one of the buttons"
        redirect(URL("user", "edit_custom_friend_details"))

    record = cftable(request.args[0])
    form_fields = ["first_name",
                   "last_name",
                   "institute",
                   "stopstalk_handle"]

    for site in current.SITES:
        form_fields.append(site.lower() + "_handle")

    form = SQLFORM(cftable,
                   record,
                   fields=form_fields,
                   deletable=True)

    if form.process().accepted:
        if form.vars.delete_this_record != "on":
            ## UPDATE
            # If delete checkbox is not checked
            response.flash = "User details updated"

            # Since there may be some updates in the handle
            # for correctness we need to remove all the submissions
            # and retrieve all the submissions again
            query = (cftable.id == request.args[0])
            db(query).update(last_retrieved=current.INITIAL_DATE)
            db(db.submission.custom_user_id == request.args[0]).delete()
            utilities.retrieve_submissions(form.vars.id, True)

            redirect(URL("user", "edit_custom_friend_details"))
        else:
            ## DELETE
            # If delete checkbox is checked => just process it redirect back
            response.flash = "Custom User deleted"
            redirect(URL("user", "edit_custom_friend_details"))
    elif form.errors:
        response.flash = "Form has errors"

    return dict(form=form)
Esempio n. 5
0
def update_friend():
    """
        Update custom friend details
    """

    if len(request.args) != 1:
        session.flash = "Please click one of the buttons"
        redirect(URL("user", "edit_custom_friend_details"))

    cftable = db.custom_friend

    query = (cftable.user_id == session["user_id"])
    query &= (cftable.id == request.args[0])
    row = db(query).select(cftable.id)
    if len(row) == 0:
        session.flash = "Please click one of the buttons"
        redirect(URL("user", "edit_custom_friend_details"))

    record = cftable(request.args[0])
    form_fields = ["first_name", "last_name", "institute", "stopstalk_handle"]

    for site in current.SITES:
        form_fields.append(site.lower() + "_handle")

    form = SQLFORM(cftable, record, fields=form_fields, deletable=True)

    if form.process().accepted:
        if form.vars.delete_this_record != "on":
            ## UPDATE
            # If delete checkbox is not checked
            response.flash = "User details updated"

            # Since there may be some updates in the handle
            # for correctness we need to remove all the submissions
            # and retrieve all the submissions again
            query = (cftable.id == request.args[0])
            db(query).update(last_retrieved=current.INITIAL_DATE)
            db(db.submission.custom_user_id == request.args[0]).delete()
            utilities.retrieve_submissions(form.vars.id, True)

            redirect(URL("user", "edit_custom_friend_details"))
        else:
            ## DELETE
            # If delete checkbox is checked => just process it redirect back
            response.flash = "Custom User deleted"
            redirect(URL("user", "edit_custom_friend_details"))
    elif form.errors:
        response.flash = "Form has errors"

    return dict(form=form)
Esempio n. 6
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. 7
0
def index():
    """
        The main controller which redirects depending
        on the login status of the user and does some
        extra pre-processing
    """

    # If the user is logged in
    if session["auth"]:
        session["handle"] = session["auth"]["user"]["stopstalk_handle"]
        session["user_id"] = session["auth"]["user"]["id"]
        redirect(URL("default", "submissions", args=[1]))

    # Detect a registration has taken place
    # This will be the case when submission on
    # a register user form is done.
    row = db(db.auth_event.id > 0).select().last()
    if row:
        desc = row.description
    else:
        desc = ""

    # If the last auth_event record contains registered
    # or verification then retrieve submissions
    if desc.__contains__("Registered") or \
       desc.__contains__("Verification"):
        reg_user = desc.split(" ")[1]
        utilities.retrieve_submissions(int(reg_user))

        row = db(db.auth_user.id == reg_user).select().first()
        tup = get_max_streak(row.stopstalk_handle)
        total_submissions = tup[1]

        today = datetime.today().date()
        start = datetime.strptime(current.INITIAL_DATE,
                                  "%Y-%m-%d %H:%M:%S").date()

        per_day = total_submissions * 1.0 / (today - start).days
        query = (db.auth_user.stopstalk_handle == row.stopstalk_handle)
        db(query).update(per_day=per_day)

    response.flash = T("Please Login")
    return dict()
def index():
    """
        The main controller which redirects depending
        on the login status of the user and does some
        extra pre-processing
    """

    # If the user is logged in
    if session["auth"]:
        session["handle"] = session["auth"]["user"]["stopstalk_handle"]
        session["user_id"] = session["auth"]["user"]["id"]
        redirect(URL("default", "submissions", args=[1]))

    # Detect a registration has taken place
    # This will be the case when submission on
    # a register user form is done.
    row = db(db.auth_event.id > 0).select().last()
    if row:
        desc = row.description
    else:
        desc = ""

    # If the last auth_event record contains registered
    # or verification then retrieve submissions
    if desc.__contains__("Registered") or \
       desc.__contains__("Verification"):
        reg_user = desc.split(" ")[1]
        utilities.retrieve_submissions(int(reg_user))

        row = db(db.auth_user.id == reg_user).select().first()
        tup = get_max_streak(row.stopstalk_handle)
        total_submissions = tup[1]

        today = datetime.today().date()
        start = datetime.strptime(current.INITIAL_DATE,
                                  "%Y-%m-%d %H:%M:%S").date()

        per_day = total_submissions * 1.0 / (today - start).days
        query = (db.auth_user.stopstalk_handle == row.stopstalk_handle)
        db(query).update(per_day=per_day)

    response.flash = T("Please Login")
    return dict()
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]

    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. 10
0
def index():
    """
        The main controller which redirects depending
        on the login status of the user and does some
        extra pre-processing
    """

    # If the user is logged in
    if session["auth"]:
        session["handle"] = session["auth"]["user"]["stopstalk_handle"]
        session["user_id"] = session["auth"]["user"]["id"]
        session.flash = "Logged in successfully"
        redirect(URL("default", "submissions", args=[1]))

    # Detect a registration has taken place
    # This will be the case when submission on
    # a register user form is done.
    row = db(db.auth_event.id > 0).select().last()
    if row:
        desc = row.description
    else:
        desc = ""

    # If the last auth_event record contains registered
    # or verification then retrieve submissions
    if desc.__contains__("Registered") or \
       desc.__contains__("Verification"):
        reg_user = desc.split(" ")[1]
        r = db(db.friends.user_id == reg_user).select()
        utilities.retrieve_submissions(int(reg_user))

        # User has a `set` of friends' ids
        # If user does not exists then initialize it with empty set
        if len(r) == 0:
            db.friends.insert(user_id=int(reg_user),
                              friends_list=str(set([])))

    response.flash = T("Please Login")
    return dict()
Esempio n. 11
0
def start_retrieving():
    """
        AJAX helper function for starting retrieval
        of a particular user
    """

    if len(request.args) < 2:
        return "Failure"
    else:
        friend_id = int(request.args[0])
        custom = int(request.args[1])
        if custom == 1:
            custom = True
        else:
            custom = False

        result = utilities.retrieve_submissions(friend_id, custom)
        if result == "FAILURE":
            return "Failure"
        else:
            return result
def start_retrieving():
    """
        AJAX helper function for starting retrieval
        of a particular user
    """

    if len(request.args) < 2:
        return "Failure"
    else:
        friend_id = int(request.args[0])
        custom = int(request.args[1])
        if custom == 1:
            custom = True
        else:
            custom = False

        result = utilities.retrieve_submissions(friend_id, custom)
        if result == "FAILURE":
            return "Failure"
        else:
            return result