コード例 #1
0
ファイル: mpt_cgi.py プロジェクト: CSSE1001/MyPyTutor
def get_user_and_add():
    """Returns the result of uqauth.get_user(), and also permanently records
       the user's information (name, email) for administration purposes."""
    info = uqauth.get_user_info()
    userid, name, email = map(str, [info['user'], info.get('name', 'NO_NAME'),
                                    info.get('email', 'NO_EMAIL')])
    support.add_user(support.User(userid, name, email, support.NOT_ENROLLED))
    return str(info['user'])
コード例 #2
0
ファイル: mpt_cgi.py プロジェクト: scott-frazier/MyPyTutor
def get_user_and_add():
    """Returns the result of uqauth.get_user(), and also permanently records
       the user's information (name, email) for administration purposes."""
    info = uqauth.get_user_info()
    userid, name, email = map(str, [
        info['user'],
        info.get('name', 'NO_NAME'),
        info.get('email', 'NO_EMAIL')
    ])
    support.add_user(support.User(userid, name, email, support.NOT_ENROLLED))
    return str(info['user'])
コード例 #3
0
ファイル: mpt_cgi.py プロジェクト: CSSE1001/MyPyTutor
def userinfo():
    user = uqauth.get_user_info()
    result = {key: str(user[key]) for key in ('user', 'name')}
    return json.dumps(result)
コード例 #4
0
ファイル: help_list.py プロジェクト: z530z675/MyPyTutor
def main():
    try:
        user = uqauth.get_user()
    except uqauth.Redirected:
        return

    # two sets of possibilities
    # (1) the help list (need to be a tutor)
    #       (a) viewing the list
    #       (b) submitting the form (eg, deleting an entry)
    # (2) asking for help (as a student)
    #       (a) for the first time (no message query param)
    #       (b) submitting the form
    form = cgi.FieldStorage(keep_blank_values=True)

    view_list = user in TUTORS and 'noadmin' not in form
    if view_list and user not in TUTORS:
        print UNAUTHORISED.format(user)
        return

    print "Content-Type: text/html\n"

    data = {}

    if view_list:
        template = Template(filename="./templates/help_list.html")

        # make our changes if the form was submitted
        if os.environ.get('REQUEST_METHOD') == 'POST' and 'mark_as' in form:
            user = form.getvalue('username')
            status = form.getvalue('mark_as')

            support.set_help_request_status(user, status)

        help_list = sorted(support.get_help_list(),
                           key=lambda hi: hi.timestamp)

        data['date_offset'] = TZ_DELTA  # hacky workaround
        data['help_list'] = help_list
        data['open_index'] = -1
    else:
        template = Template(filename='./templates/help_request.html')

        data['user'] = user

        message = form.getvalue('message')
        traceback = form.getvalue('traceback')

        if os.environ.get('REQUEST_METHOD') == 'POST' \
                and 'message' is not None:
            info = uqauth.get_user_info()
            name = info.get('name', '')

            support.log_help_request(user, name, message, traceback)

            data['alert_message'] = ('alert-success',
                                     'Your help request has been logged')

        pending_request = support.get_pending_help_request(user)
        data['has_pending'] = pending_request is not None
        data['is_ignored'] = False
        data['queue_position'] = None

        if pending_request is not None:
            message = pending_request.message
            traceback = pending_request.traceback

            data['is_ignored'] = \
                pending_request.status == support.HELP_STATUS_IGNORED
            data['queue_position'] = support.get_position_in_help_queue(user)

        data['message'] = message
        data['traceback'] = traceback

    try:
        print(template.render(**data))
    except:
        print(exceptions.html_error_template().render())
コード例 #5
0
ファイル: mpt_cgi.py プロジェクト: dartmoth/MyPyTutor
def userinfo():
    user = uqauth.get_user_info()
    result = {key: str(user[key]) for key in ('user', 'name')}
    return json.dumps(result)
コード例 #6
0
ファイル: help_list.py プロジェクト: CSSE1001/MyPyTutor
def main():
    try:
        user = uqauth.get_user()
    except uqauth.Redirected:
        return

    # two sets of possibilities
    # (1) the help list (need to be a tutor)
    #       (a) viewing the list
    #       (b) submitting the form (eg, deleting an entry)
    # (2) asking for help (as a student)
    #       (a) for the first time (no message query param)
    #       (b) submitting the form
    form = cgi.FieldStorage(keep_blank_values=True)

    view_list = user in TUTORS and 'noadmin' not in form
    if view_list and user not in TUTORS:
        print UNAUTHORISED.format(user)
        return

    print "Content-Type: text/html\n"

    data = {}

    if view_list:
        template = Template(filename="./templates/help_list.html")

        # make our changes if the form was submitted
        if os.environ.get('REQUEST_METHOD') == 'POST' and 'mark_as' in form:
            user = form.getvalue('username')
            status = form.getvalue('mark_as')

            support.set_help_request_status(user, status)

        help_list = sorted(
            support.get_help_list(), key=lambda hi: hi.timestamp
        )

        data['date_offset'] = TZ_DELTA  # hacky workaround
        data['help_list'] = help_list
        data['open_index'] = -1
    else:
        template = Template(filename='./templates/help_request.html')

        data['user'] = user

        message = form.getvalue('message')
        traceback = form.getvalue('traceback')

        if os.environ.get('REQUEST_METHOD') == 'POST' \
                and 'message' is not None:
            info = uqauth.get_user_info()
            name = info.get('name', '')

            support.log_help_request(user, name, message, traceback)

            data['alert_message'] = (
                'alert-success', 'Your help request has been logged'
            )

        pending_request = support.get_pending_help_request(user)
        data['has_pending'] = pending_request is not None
        data['is_ignored'] = False
        data['queue_position'] = None

        if pending_request is not None:
            message = pending_request.message
            traceback = pending_request.traceback

            data['is_ignored'] = \
                pending_request.status == support.HELP_STATUS_IGNORED
            data['queue_position'] = support.get_position_in_help_queue(user)

        data['message'] = message
        data['traceback'] = traceback

    try:
        print(template.render(**data))
    except:
        print(exceptions.html_error_template().render())