Пример #1
0
def save_code(lti=lti):
    assignment_id = request.values.get('assignment_id', None)
    assignment_version = int(request.values.get('version', -1))
    course_id = request.values.get('course_id',
                                   g.course.id if 'course' in g else None)
    if None in (assignment_id, course_id) or course_id == "":
        return failure("No Assignment ID or Course ID given!")
    code = request.values.get('code', '')
    timestamp = request.values.get('timestamp', '')
    filename = request.values.get('filename', '__main__')
    is_version_correct = True
    if filename == "__main__":
        submission, is_version_correct = Submission.save_code(
            g.user.id,
            assignment_id,
            int(course_id),
            code,
            assignment_version,
            timestamp=timestamp)
    elif g.user.is_instructor(int(course_id)):
        if filename == "give_feedback":
            Assignment.edit(assignment_id=assignment_id, give_feedback=code)
        elif filename == "on_change":
            Assignment.edit(assignment_id=assignment_id, on_step=code)
        elif filename == "starting_code":
            Assignment.edit(assignment_id=assignment_id, starting_code=code)
        log = Log.new('instructor',
                      filename,
                      assignment_id,
                      g.user.id,
                      body=code,
                      timestamp=timestamp)
    return jsonify(success=True,
                   is_version_correct=is_version_correct,
                   ip=request.remote_addr)
Пример #2
0
def watch():
    assignment_list = request.values.get('assignments', '')
    assignments = [int(aid) for aid in assignment_list.split(',') if len(aid) > 0]
    course_id = request.values.get('course_id',  g.course.id if 'course' in g else None)
    if course_id == None or course_id == "":
        return jsonify(success=False, message="No Course ID given!")
    if g.user is None or not g.user.is_instructor(int(course_id)):
        return jsonify(success=False, message="You are not an instructor in this assignments' course.")
    update = request.values.get('update', 'false') == "true"
    if update:
        data = []
        for aid in assignments:
            submissions = Submission.by_assignment(aid, int(course_id))
            completions = sum([int(sua[0].correct) for sua in submissions])
            workings = len(Submission.get_latest(aid, int(course_id)))
            histories = [process_history([h['time'] for h in sua[0].get_history()])
                         for sua in submissions]
            touches = [int(sua[0].version) for sua in submissions]
            feedbacks = [l[0] for l in Log.calculate_feedbacks(aid, course_id)]
            data.append({'id': aid,
                         'Completions': completions,
                         'Workings': workings,
                         'Time': histories,
                         'Touches': touches,
                         'Feedbacks': feedbacks})
        return jsonify(success=True, data=data)
    else:
        assignments = [Assignment.by_id(aid) for aid in assignments]
        return render_template('blockpy/watch.html', course_id=course_id, assignments=assignments,
                               assignment_list=assignment_list)
Пример #3
0
def log_event():
    if 'user_id' in request.values:
        user_id = request.values.get('user_id')
    elif 'user' in g and g.user and g.user.id:
        user_id = g.user.id
    else:
        user_id = str(request.remote_addr)
    assignment_id = request.values.get('assignment_id', "-1")
    if assignment_id == "":
        assignment_id = -1
    else:
        assignment_id = int(assignment_id)
    event = request.values.get('event', "")
    action = request.values.get('action', "")
    body = request.values.get('body', "")
    timestamp = request.values.get('timestamp', "")
    Log.new(event, action, assignment_id, user_id, body, timestamp)
    return jsonify(success=True)
Пример #4
0
def save_events(lti=lti):
    assignment_id = request.form.get('assignment_id', None)
    event = request.form.get('event', "blank")
    action = request.form.get('action', "missing")
    body = request.form.get('body', "")
    user_id = g.user.id if g.user != None else -1
    if assignment_id is None:
        return jsonify(success=False, message="No Assignment ID given!")
    log = Log.new(event, action, assignment_id, -1, body=body)
    return jsonify(success=True)
Пример #5
0
    def add_log(self):
        log = Log(ip="127.0.0.1",
                  method=random.choice(['GET', 'POST', 'HEAD', 'PUT']),
                  url="/index.html",
                  status=random.randint(400, 600),
                  size=random.randint(0, 10**8))

        self.db.session.add(log)
        self.db.session.commit()
        return log
Пример #6
0
def save_events(lti=lti):
    assignment_id = request.values.get('assignment_id', None)
    event = request.values.get('event', "blank")
    action = request.values.get('action', "missing")
    body = request.values.get('body', "")
    timestamp = request.values.get('timestamp', "")
    user_id = g.user.id if g.user != None else -1
    if assignment_id is None:
        return jsonify(success=False, message="No Assignment ID given!")
    log = Log.new(event, action, assignment_id, user_id, body=body, timestamp=timestamp)
    return jsonify(success=True)
Пример #7
0
def save_events(lti=lti):
    assignment_id = request.form.get('question_id', None)
    event = request.form.get('event', "blank")
    action = request.form.get('action', "missing")
    if assignment_id is None:
        return jsonify(success=False, message="No Assignment ID given!")
    user = User.from_lti("canvas", session["pylti_user_id"], 
                         session.get("user_email", ""),
                         session.get("lis_person_name_given", ""),
                         session.get("lis_person_name_family", ""))
    log = Log.new(event, action, assignment_id, user.id)
    return jsonify(success=True)
Пример #8
0
def save_events(lti=lti):
    assignment_id = request.form.get('question_id', None)
    event = request.form.get('event', "blank")
    action = request.form.get('action', "missing")
    if assignment_id is None:
        return jsonify(success=False, message="No Assignment ID given!")
    user = User.from_lti("canvas", session["pylti_user_id"],
                         session.get("user_email", ""),
                         session.get("lis_person_name_given", ""),
                         session.get("lis_person_name_family", ""))
    log = Log.new(event, action, assignment_id, user.id)
    return jsonify(success=True)
Пример #9
0
def load_assignment(lti=lti):
    assignment_id = request.values.get('assignment_id', None)
    group_id = request.values.get('group_id', None)
    course_id = request.values.get('course_id',
                                   g.course.id if 'course' in g else None)
    if None in (assignment_id, course_id) or course_id == "":
        return failure("No Assignment ID or Course ID given!")
    timestamp = request.values.get('timestamp', '')
    user_id = g.user.id if g.user != None else -1
    assignment = Assignment.by_id(assignment_id)
    if user_id != -1:
        submission = assignment.get_submission(user_id, course_id=course_id)
        submission_status = submission.status
        submission_course_id = submission.course_id
        submission_code = submission.code
        log = Log.new('editor',
                      'load',
                      assignment_id,
                      user_id,
                      body=str(assignment.version),
                      timestamp=timestamp)
    else:
        submission_status = 0
        submission_course_id = course_id
        submission_code = assignment.starting_code or ""
    interface = ('Text' if assignment.mode.lower() == 'text' else
                 'Split' if assignment.mode.lower() == 'split' else
                 'Upload' if assignment.mode.lower() == 'upload' else 'Blocks')
    upload = assignment.mode.lower() == 'upload'
    if assignment.settings:
        settings = json.loads(assignment.settings)
    else:
        settings = {}
    files = settings['files'] if 'files' in settings else []
    files = [f for f in files if f.strip()]
    added_modules = settings['modules'][
        'added'] if 'modules' in settings else []
    removed_modules = settings['modules'][
        'removed'] if 'modules' in settings else []
    return jsonify(
        success=True,
        ip=request.remote_addr,
        settings={
            'editor': interface,
            'read_only': upload,
            'status': submission_status
        },
        assignment={
            'assignment_id':
            assignment.id,
            'course_id':
            course_id if course_id != None else submission_course_id,
            'student_id':
            user_id,
            'group_id':
            group_id,
            'introduction':
            assignment.body,
            'name':
            assignment.name,
            'upload':
            upload,
            'version':
            assignment.version,
            'initial_view':
            interface,
            'give_feedback':
            assignment.give_feedback,
            'parsons':
            assignment.mode == 'parsons',
            'starting_code':
            assignment.starting_code,
            'on_change':
            assignment.on_step,
            'importable':
            settings.get('importable', False),
            'secret':
            settings.get('secret', False),
            'disable_algorithm_errors':
            settings.get('disable_algorithm_errors', False),
            'disable_timeout':
            settings.get('disable_timeout', False),
            'files':
            files,
            'modules': {
                'added': added_modules,
                'removed': removed_modules,
            },
        },
        programs={
            '__main__': submission_code,
            'starting_code': assignment.starting_code,
            'give_feedback': assignment.give_feedback,
            'on_change': assignment.on_step
        })
Пример #10
0
 def _log_for_course(self, course, output):
     from models.models import Log
     logs = Log.get_logs_for_course(course)
     self.dump_rows(logs, output, 'log')