Exemplo n.º 1
0
def update_details():
    """
        Update user details
    """

    form_fields = ["first_name",
                   "last_name",
                   "email",
                   "institute",
                   "stopstalk_handle"]

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

    atable = db.auth_user
    stable = db.submission
    record = atable(session.user_id)

    # Do not allow to modify stopstalk_handle and email
    atable.stopstalk_handle.writable = False
    atable.email.writable = False

    form = SQLFORM(db.auth_user,
                   record,
                   fields=form_fields,
                   showid=False)

    form.vars.email = record.email
    form.vars.stopstalk_handle = record.stopstalk_handle

    if form.process(onvalidation=current.sanitize_fields).accepted:
        session.flash = "User details updated"

        updated_sites = utilities.handles_updated(record, form)
        if updated_sites != []:
            site_lrs = {}
            submission_query = (stable.user_id == session.user_id)
            for site in updated_sites:
                site_lrs[site.lower() + "_lr"] = current.INITIAL_DATE

            # Reset the user only if any of the profile site handle is updated
            query = (atable.id == session.user_id)
            db(query).update(rating=0,
                             prev_rating=0,
                             per_day=0.0,
                             per_day_change="0.0",
                             authentic=False,
                             **site_lrs)

            submission_query &= (stable.site.belongs(updated_sites))
            # Only delete the submission of those particular sites
            # whose site handles are updated
            db(submission_query).delete()

        redirect(URL("default", "submissions", args=[1]))
    elif form.errors:
        response.flash = "Form has errors"

    return dict(form=form)
Exemplo n.º 2
0
def update_details():
    """
        Update user details
    """

    form_fields = [
        "first_name", "last_name", "email", "institute", "stopstalk_handle"
    ]

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

    atable = db.auth_user
    stable = db.submission
    record = atable(session.user_id)

    # Do not allow to modify stopstalk_handle and email
    atable.stopstalk_handle.writable = False
    atable.stopstalk_handle.comment = T("StopStalk handle cannot be updated")

    atable.email.writable = False
    atable.email.comment = T("Email cannot be updated")

    form = SQLFORM(db.auth_user, record, fields=form_fields, showid=False)

    form.vars.email = record.email
    form.vars.stopstalk_handle = record.stopstalk_handle

    if form.process(onvalidation=current.sanitize_fields).accepted:
        session.flash = T("User details updated")

        updated_sites = utilities.handles_updated(record, form)
        if updated_sites != []:
            site_lrs = {}
            submission_query = (stable.user_id == session.user_id)
            for site in updated_sites:
                site_lrs[site.lower() + "_lr"] = current.INITIAL_DATE

            # Reset the user only if any of the profile site handle is updated
            query = (atable.id == session.user_id)
            db(query).update(rating=0,
                             prev_rating=0,
                             per_day=0.0,
                             per_day_change="0.0",
                             authentic=False,
                             **site_lrs)

            submission_query &= (stable.site.belongs(updated_sites))
            # Only delete the submission of those particular sites
            # whose site handles are updated
            db(submission_query).delete()

        redirect(URL("default", "submissions", args=[1]))
    elif form.errors:
        response.flash = T("Form has errors")

    return dict(form=form)
Exemplo n.º 3
0
def update_friend():
    """
        Update custom friend details
    """

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

    cftable = db.custom_friend
    stable = db.submission

    query = (cftable.user_id == session.user_id) & \
            (cftable.id == request.args[0])
    record = db(query).select().first()
    if record is None:
        session.flash = T("Please click one of the buttons")
        redirect(URL("user", "custom_friend"))

    # Do not allow to modify stopstalk_handle
    cftable.stopstalk_handle.writable = False

    form_fields = [
        "first_name", "last_name", "institute", "country", "stopstalk_handle"
    ]

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

    for field in form_fields:
        if record[field] is None:
            continue
        record[field] = unicode(record[field], "utf-8").encode("utf-8")

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

    form.vars.stopstalk_handle = record.stopstalk_handle.replace("cus_", "")

    if form.validate(onvalidation=current.sanitize_fields):
        form.vars.stopstalk_handle = record.stopstalk_handle
        pickle_file_path = "./applications/stopstalk/graph_data/" + \
                           str(record.id) + "_custom.pickle"
        import os
        utilities.clear_profile_page_cache(record.stopstalk_handle)

        if form.deleted:
            ## DELETE
            # If delete checkbox is checked => just process it redirect back
            session.flash = T("Custom User deleted")
            duplicate_cus = db(cftable.duplicate_cu == record.id).select()
            if os.path.exists(pickle_file_path):
                os.remove(pickle_file_path)
            if len(duplicate_cus):
                # The current custom user is a parent of other duplicate custom users

                first_dcu = duplicate_cus.first()

                # Populate stopstalk_handle of first child to submission tabls
                squery = (stable.stopstalk_handle == record.stopstalk_handle)
                db(squery).update(stopstalk_handle=first_dcu.stopstalk_handle)

                # Pick the first cu child and copy the stopstalk_handle to the parent
                record.update_record(
                    user_id=first_dcu.user_id,
                    stopstalk_handle=first_dcu.stopstalk_handle,
                    institute=first_dcu.institute)
                # Now delete the first child as the parent is now modified
                # and the previous siblings remain as child to this parent
                first_dcu.delete_record()
            else:
                record.delete_record()
            redirect(URL("user", "custom_friend"))
        else:
            updated_sites = utilities.handles_updated(record, form)
            ## UPDATE
            if updated_sites != []:
                if os.path.exists(pickle_file_path):
                    os.remove(pickle_file_path)
                submission_query = (stable.custom_user_id == int(
                    request.args[0]))
                reset_sites = current.SITES if record.duplicate_cu else updated_sites

                nrtable = db.next_retrieval
                nrtable_record = db(db.next_retrieval.custom_user_id == int(
                    request.args[0])).select().first()
                if nrtable_record is None:
                    nid = nrtable.insert(custom_user_id=int(request.args[0]))
                    nrtable_record = nrtable(nid)
                for site in reset_sites:
                    form.vars[site.lower() + "_lr"] = current.INITIAL_DATE
                    nrtable_record.update({site.lower() + "_delay": 0})

                nrtable_record.update_record()

                submission_query &= (stable.site.belongs(reset_sites))

                form.vars["duplicate_cu"] = None
                form.vars["stopstalk_rating"] = 0
                form.vars["stopstalk_prev_rating"] = 0
                form.vars["per_day"] = 0.0
                form.vars["per_day_change"] = "0.0"
                form.vars["graph_data_retrieved"] = False

                # Only delete the submission of those particular sites
                # whose site handles are updated
                db(submission_query).delete()

            record.update_record(**dict(form.vars))

            session.flash = T("User details updated")
            redirect(URL("user", "custom_friend"))

    elif form.errors:
        form.vars.stopstalk_handle = record.stopstalk_handle
        response.flash = T("Form has errors")

    return dict(form=form)
Exemplo n.º 4
0
def update_details():
    """
        Update user details
    """

    form_fields = [
        "first_name", "last_name", "email", "institute", "country",
        "stopstalk_handle"
    ]

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

    atable = db.auth_user
    stable = db.submission
    record = utilities.get_user_records([session.user_id], "id", "id", True)

    for field in form_fields:
        if record[field] is None:
            continue
        record[field] = record[field].encode("utf-8")

    # Do not allow to modify stopstalk_handle and email
    atable.stopstalk_handle.writable = False
    atable.stopstalk_handle.comment = T("StopStalk handle cannot be updated")

    atable.email.readable = True
    atable.email.writable = False
    atable.email.comment = T("Email cannot be updated")

    form = SQLFORM(db.auth_user, record, fields=form_fields, showid=False)

    if form.process(onvalidation=current.sanitize_fields).accepted:
        current.REDIS_CLIENT.delete(
            utilities.get_user_record_cache_key(session.user_id))
        session.flash = T("User details updated")

        updated_sites = utilities.handles_updated(record, form)
        if updated_sites != []:
            utilities.clear_profile_page_cache(record.stopstalk_handle)
            site_lrs = {}
            nrtable = db.next_retrieval
            submission_query = (stable.user_id == session.user_id)
            nrtable_record = db(
                nrtable.user_id == session.user_id).select().first()
            if nrtable_record is None:
                nid = nrtable.insert(user_id=session.user_id)
                nrtable_record = nrtable(nid)
            for site in updated_sites:
                site_lrs[site.lower() + "_lr"] = current.INITIAL_DATE
                nrtable_record.update({site.lower() + "_delay": 0})

            nrtable_record.update_record()

            pickle_file_path = "./applications/stopstalk/graph_data/" + \
                               str(session.user_id) + ".pickle"
            import os
            if os.path.exists(pickle_file_path):
                os.remove(pickle_file_path)

            # Reset the user only if any of the profile site handle is updated
            query = (atable.id == session.user_id)
            db(query).update(stopstalk_rating=0,
                             stopstalk_prev_rating=0,
                             per_day=0.0,
                             per_day_change="0.0",
                             authentic=False,
                             graph_data_retrieved=False,
                             **site_lrs)

            submission_query &= (stable.site.belongs(updated_sites))
            # Only delete the submission of those particular sites
            # whose site handles are updated
            db(submission_query).delete()

        session.auth.user = db.auth_user(session.user_id)
        current.REDIS_CLIENT.delete(
            CARD_CACHE_REDIS_KEYS["more_accounts_prefix"] +
            str(session.user_id))
        redirect(URL("default", "index"))
    elif form.errors:
        response.flash = T("Form has errors")

    return dict(form=form)
Exemplo 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", "custom_friend"))

    cftable = db.custom_friend
    stable = db.submission

    query = (cftable.user_id == session.user_id) & \
            (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", "custom_friend"))

    record = cftable(request.args[0])

    # Do not allow to modify stopstalk_handle
    cftable.stopstalk_handle.writable = False

    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,
                   showid=False)
    if form.validate():
        if form.deleted:
            ## DELETE
            # If delete checkbox is checked => just process it redirect back
            session.flash = "Custom User deleted"
            db(cftable.id == record.id).delete()
            redirect(URL("user", "custom_friend"))
        else:
            updated_sites = utilities.handles_updated(record, form)
            ## UPDATE
            if updated_sites != []:

                submission_query = (stable.custom_user_id == request.args[0])
                for site in updated_sites:
                    form.vars[site.lower() + "_lr"] = current.INITIAL_DATE
                    submission_query &= (stable.site == site)

                form.vars["duplicate_cu"] = None
                form.vars["rating"] = 0
                form.vars["prev_rating"] = 0
                form.vars["per_day"] = 0.0
                form.vars["per_day_change"] = "0.0"

                # Only delete the submission of those particular sites
                # whose site handles are updated
                db(submission_query).delete()

            record.update_record(**dict(form.vars))

            session.flash = "User details updated"
            redirect(URL("user", "custom_friend"))

    elif form.errors:
        response.flash = "Form has errors"

    return dict(form=form)
Exemplo n.º 6
0
def update_details():
    """
        Update user details
    """

    form_fields = [
        "first_name", "last_name", "email", "institute", "country",
        "stopstalk_handle"
    ]

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

    atable = db.auth_user
    stable = db.submission
    record = atable(session.user_id)

    # Do not allow to modify stopstalk_handle and email
    atable.stopstalk_handle.writable = False
    atable.stopstalk_handle.comment = T("StopStalk handle cannot be updated")

    atable.email.readable = True
    atable.email.writable = False
    atable.email.comment = T("Email cannot be updated")

    form = SQLFORM(db.auth_user, record, fields=form_fields, showid=False)

    form.vars.email = record.email
    form.vars.stopstalk_handle = record.stopstalk_handle

    if form.process(onvalidation=current.sanitize_fields).accepted:
        session.flash = T("User details updated")

        updated_sites = utilities.handles_updated(record, form)
        if updated_sites != []:
            site_lrs = {}
            submission_query = (stable.user_id == session.user_id)
            nrtable_record = db(
                db.next_retrieval.user_id == session.user_id).select().first()
            for site in updated_sites:
                site_lrs[site.lower() + "_lr"] = current.INITIAL_DATE
                nrtable_record.update({site.lower() + "_delay": 0})

            nrtable_record.update_record()

            pickle_file_path = "./applications/stopstalk/graph_data/" + \
                               str(session.user_id) + ".pickle"
            import os
            if os.path.exists(pickle_file_path):
                os.remove(pickle_file_path)

            # Reset the user only if any of the profile site handle is updated
            query = (atable.id == session.user_id)
            db(query).update(stopstalk_rating=0,
                             stopstalk_prev_rating=0,
                             per_day=0.0,
                             per_day_change="0.0",
                             authentic=False,
                             graph_data_retrieved=False,
                             **site_lrs)

            submission_query &= (stable.site.belongs(updated_sites))
            # Only delete the submission of those particular sites
            # whose site handles are updated
            db(submission_query).delete()

        session.auth.user = db.auth_user(session.user_id)
        redirect(URL("default", "submissions", args=[1]))
    elif form.errors:
        response.flash = T("Form has errors")

    return dict(form=form)
Exemplo n.º 7
0
def update_friend():
    """
        Update custom friend details
    """

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

    cftable = db.custom_friend
    stable = db.submission

    query = (cftable.user_id == session.user_id) & \
            (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", "custom_friend"))

    record = cftable(request.args[0])

    # Do not allow to modify stopstalk_handle
    cftable.stopstalk_handle.writable = False

    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,
                   showid=False)

    form.vars.stopstalk_handle = record.stopstalk_handle

    if form.validate(onvalidation=current.sanitize_fields):
        if form.deleted:
            ## DELETE
            # If delete checkbox is checked => just process it redirect back
            session.flash = "Custom User deleted"
            duplicate_cus = db(cftable.duplicate_cu == record.id).select()
            if len(duplicate_cus):
                # The current custom user is a parent of other duplicate custom users

                first_dcu = duplicate_cus.first()

                # Populate stopstalk_handle of first child to submission tabls
                squery = (stable.stopstalk_handle == record.stopstalk_handle)
                db(squery).update(stopstalk_handle=first_dcu.stopstalk_handle)

                # Pick the first cu child and copy the stopstalk_handle to the parent
                record.update_record(user_id=first_dcu.user_id,
                                     stopstalk_handle=first_dcu.stopstalk_handle,
                                     institute=first_dcu.institute)
                # Now delete the first child as the parent is now modified
                # and the previous siblings remain as child to this parent
                first_dcu.delete_record()
            else:
                record.delete_record()
            redirect(URL("user", "custom_friend"))
        else:
            updated_sites = utilities.handles_updated(record, form)
            ## UPDATE
            if updated_sites != []:

                submission_query = (stable.custom_user_id == int(request.args[0]))
                reset_sites = current.SITES if record.duplicate_cu else updated_sites
                for site in reset_sites:
                    form.vars[site.lower() + "_lr"] = current.INITIAL_DATE

                submission_query &= (stable.site.belongs(reset_sites))

                form.vars["duplicate_cu"] = None
                form.vars["rating"] = 0
                form.vars["prev_rating"] = 0
                form.vars["per_day"] = 0.0
                form.vars["per_day_change"] = "0.0"

                # Only delete the submission of those particular sites
                # whose site handles are updated
                db(submission_query).delete()

            record.update_record(**dict(form.vars))

            session.flash = "User details updated"
            redirect(URL("user", "custom_friend"))

    elif form.errors:
        response.flash = "Form has errors"

    return dict(form=form)
Exemplo n.º 8
0
def update_friend():
    """
        Update custom friend details
    """

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

    cftable = db.custom_friend
    stable = db.submission

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

    record = cftable(request.args[0])

    # Do not allow to modify stopstalk_handle
    cftable.stopstalk_handle.writable = False

    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,
                   showid=False)

    form.vars.stopstalk_handle = record.stopstalk_handle

    if form.validate(onvalidation=current.sanitize_fields):
        if form.deleted:
            ## DELETE
            # If delete checkbox is checked => just process it redirect back
            session.flash = T("Custom User deleted")
            duplicate_cus = db(cftable.duplicate_cu == record.id).select()
            if len(duplicate_cus):
                # The current custom user is a parent of other duplicate custom users

                first_dcu = duplicate_cus.first()

                # Populate stopstalk_handle of first child to submission tabls
                squery = (stable.stopstalk_handle == record.stopstalk_handle)
                db(squery).update(stopstalk_handle=first_dcu.stopstalk_handle)

                # Pick the first cu child and copy the stopstalk_handle to the parent
                record.update_record(user_id=first_dcu.user_id,
                                     stopstalk_handle=first_dcu.stopstalk_handle,
                                     institute=first_dcu.institute)
                # Now delete the first child as the parent is now modified
                # and the previous siblings remain as child to this parent
                first_dcu.delete_record()
            else:
                record.delete_record()
            redirect(URL("user", "custom_friend"))
        else:
            updated_sites = utilities.handles_updated(record, form)
            ## UPDATE
            if updated_sites != []:

                submission_query = (stable.custom_user_id == int(request.args[0]))
                reset_sites = current.SITES if record.duplicate_cu else updated_sites
                for site in reset_sites:
                    form.vars[site.lower() + "_lr"] = current.INITIAL_DATE

                submission_query &= (stable.site.belongs(reset_sites))

                form.vars["duplicate_cu"] = None
                form.vars["rating"] = 0
                form.vars["prev_rating"] = 0
                form.vars["per_day"] = 0.0
                form.vars["per_day_change"] = "0.0"

                # Only delete the submission of those particular sites
                # whose site handles are updated
                db(submission_query).delete()

            record.update_record(**dict(form.vars))

            session.flash = T("User details updated")
            redirect(URL("user", "custom_friend"))

    elif form.errors:
        response.flash = T("Form has errors")

    return dict(form=form)