Beispiel #1
0
    def _transition_state_to_expired(cls, review_step_key):
        step = entities.get(review_step_key)

        if not step:
            COUNTER_EXPIRE_REVIEW_STEP_MISS.inc()
            raise KeyError(
                'No review step found with key %s' % repr(review_step_key))

        if step.removed:
            COUNTER_EXPIRE_REVIEW_CANNOT_TRANSITION.inc()
            raise domain.RemovedError(
                'Cannot transition step %s' % repr(review_step_key),
                step.removed)

        if step.state in (
                domain.REVIEW_STATE_COMPLETED, domain.REVIEW_STATE_EXPIRED):
            COUNTER_EXPIRE_REVIEW_CANNOT_TRANSITION.inc()
            raise domain.TransitionError(
                'Cannot transition step %s' % repr(review_step_key),
                step.state, domain.REVIEW_STATE_EXPIRED)

        summary = entities.get(step.review_summary_key)

        if not summary:
            COUNTER_EXPIRE_REVIEW_SUMMARY_MISS.inc()
            raise KeyError(
                'No review summary found with key %s' % repr(
                    step.review_summary_key))

        summary.decrement_count(step.state)
        step.state = domain.REVIEW_STATE_EXPIRED
        summary.increment_count(step.state)
        return entities.put([step, summary])[0]
Beispiel #2
0
    def _transition_state_to_expired(cls, review_step_key):
        step = entities.get(review_step_key)

        if not step:
            COUNTER_EXPIRE_REVIEW_STEP_MISS.inc()
            raise KeyError('No review step found with key %s' %
                           repr(review_step_key))

        if step.removed:
            COUNTER_EXPIRE_REVIEW_CANNOT_TRANSITION.inc()
            raise domain.RemovedError(
                'Cannot transition step %s' % repr(review_step_key),
                step.removed)

        if step.state in (domain.REVIEW_STATE_COMPLETED,
                          domain.REVIEW_STATE_EXPIRED):
            COUNTER_EXPIRE_REVIEW_CANNOT_TRANSITION.inc()
            raise domain.TransitionError(
                'Cannot transition step %s' % repr(review_step_key),
                step.state, domain.REVIEW_STATE_EXPIRED)

        summary = entities.get(step.review_summary_key)

        if not summary:
            COUNTER_EXPIRE_REVIEW_SUMMARY_MISS.inc()
            raise KeyError('No review summary found with key %s' %
                           repr(step.review_summary_key))

        summary.decrement_count(step.state)
        step.state = domain.REVIEW_STATE_EXPIRED
        summary.increment_count(step.state)
        return entities.put([step, summary])[0]
Beispiel #3
0
def assign_course_staff(entity):
    """
    Function to assign a submission to a course staff. The entity can be
    either of type ManualEvaluationSummary or of type ManualEvaluationStep
    since both of them have the fields required here.
    """
    unit_id = entity.unit_id
    submission_key = entity.submission_key
    students = entities.get([entity.reviewee_key])
    if not students:
        return False
    student = students[0]

    namespace = namespace_manager.get_namespace()
    if namespace:
        app_context = sites.get_app_context_for_namespace(namespace)
        if app_context:
            course = courses.Course.get(app_context)
            if course:
                unit = course.find_unit_by_id(unit_id)
                if unit and submission_key and student:
                    manage.Manager.find_and_add_evaluator(
                        course, unit, submission_key, student)
                    return True
    logging.error('Could not load unit for entity ' + entity.key().name())
    return False
Beispiel #4
0
    def _mark_review_step_removed(cls, review_step_key):
        step = entities.get(review_step_key)
        if not step:
            COUNTER_DELETE_REVIEWER_STEP_MISS.inc()
            raise KeyError('No review step found with key %s' %
                           repr(review_step_key))
        if step.removed:
            COUNTER_DELETE_REVIEWER_ALREADY_REMOVED.inc()
            raise domain.RemovedError(
                'Cannot remove step %s' % repr(review_step_key), step.removed)
        summary = entities.get(step.review_summary_key)

        if not summary:
            COUNTER_DELETE_REVIEWER_SUMMARY_MISS.inc()
            raise KeyError('No review summary found with key %s' %
                           repr(step.review_summary_key))

        step.removed = True
        summary.decrement_count(step.state)
        return entities.put([step, summary])[0]
Beispiel #5
0
    def get_reviews_by_keys(cls, keys):
        """Gets reviews by their keys.

        Args:
            keys: [db.Key of review.Review]. Keys to fetch.

        Returns:
            [domain.Review or None]. Missed keys return None in place in result
            list.
        """
        return [cls._make_domain_review(model) for model in entities.get(keys)]
Beispiel #6
0
    def get_reviews_by_keys(cls, keys):
        """Gets reviews by their keys.

        Args:
            keys: [db.Key of review.Review]. Keys to fetch.

        Returns:
            [domain.Review or None]. Missed keys return None in place in result
            list.
        """
        return [cls._make_domain_review(model) for model in entities.get(keys)]
Beispiel #7
0
    def _mark_review_step_removed(cls, review_step_key):
        step = entities.get(review_step_key)
        if not step:
            COUNTER_DELETE_REVIEWER_STEP_MISS.inc()
            raise KeyError(
                'No review step found with key %s' % repr(review_step_key))
        if step.removed:
            COUNTER_DELETE_REVIEWER_ALREADY_REMOVED.inc()
            raise domain.RemovedError(
                'Cannot remove step %s' % repr(review_step_key), step.removed)
        summary = entities.get(step.review_summary_key)

        if not summary:
            COUNTER_DELETE_REVIEWER_SUMMARY_MISS.inc()
            raise KeyError(
                'No review summary found with key %s' % repr(
                    step.review_summary_key))

        step.removed = True
        summary.decrement_count(step.state)
        return entities.put([step, summary])[0]
Beispiel #8
0
    def _add_reviewer_update_step(cls, step):
        should_increment_human = False
        should_increment_reassigned = False
        should_increment_unremoved = False
        summary = entities.get(step.review_summary_key)

        if not summary:
            COUNTER_ADD_REVIEWER_BAD_SUMMARY_KEY.inc()
            raise AssertionError(
                'Found invalid review summary key %s' % repr(
                    step.review_summary_key))

        if not step.removed:

            if step.state == domain.REVIEW_STATE_EXPIRED:
                should_increment_reassigned = True
                step.state = domain.REVIEW_STATE_ASSIGNED
                summary.decrement_count(domain.REVIEW_STATE_EXPIRED)
                summary.increment_count(domain.REVIEW_STATE_ASSIGNED)
            elif (step.state == domain.REVIEW_STATE_ASSIGNED or
                  step.state == domain.REVIEW_STATE_COMPLETED):
                COUNTER_ADD_REVIEWER_UNREMOVED_STEP_FAILED.inc()
                raise domain.TransitionError(
                    'Unable to add new reviewer to step %s' % (
                        repr(step.key())),
                    step.state, domain.REVIEW_STATE_ASSIGNED)
        else:
            should_increment_unremoved = True
            step.removed = False

            if step.state != domain.REVIEW_STATE_EXPIRED:
                summary.increment_count(step.state)
            else:
                should_increment_reassigned = True
                step.state = domain.REVIEW_STATE_ASSIGNED
                summary.decrement_count(domain.REVIEW_STATE_EXPIRED)
                summary.increment_count(domain.REVIEW_STATE_ASSIGNED)

        if step.assigner_kind != domain.ASSIGNER_KIND_HUMAN:
            should_increment_human = True
            step.assigner_kind = domain.ASSIGNER_KIND_HUMAN

        step_key = entities.put([step, summary])[0]

        if should_increment_human:
            COUNTER_ADD_REVIEWER_SET_ASSIGNER_KIND_HUMAN.inc()
        if should_increment_reassigned:
            COUNTER_ADD_REVIEWER_EXPIRED_STEP_REASSIGNED.inc()
        if should_increment_unremoved:
            COUNTER_ADD_REVIEWER_REMOVED_STEP_UNREMOVED.inc()

        return step_key
Beispiel #9
0
    def get_submission_and_review_step_keys(cls, unit_id, reviewee_key):
        """Gets the submission key/review step keys for the given pair.

        Note that keys for review steps marked removed are included in the
        result set.

        Args:
            unit_id: string. Id of the unit to restrict the query to.
            reviewee_key: db.Key of models.models.Student. The student who
                authored the submission.

        Raises:
            domain.ConstraintError: if multiple review summary keys were found
                for the given unit_id, reviewee_key pair.
            KeyError: if there is no review summary for the given unit_id,
                reviewee pair.

        Returns:
            (db.Key of Submission, [db.Key of peer.ReviewStep]) if submission
            found for given unit_id, reviewee_key pair; None otherwise.
        """
        COUNTER_GET_SUBMISSION_AND_REVIEW_STEP_KEYS_START.inc()

        try:
            submission_key = db.Key.from_path(
                student_work.Submission.kind(),
                student_work.Submission.key_name(unit_id, reviewee_key))
            submission = entities.get(submission_key)
            if not submission:
                COUNTER_GET_SUBMISSION_AND_REVIEW_STEP_KEYS_SUBMISSION_MISS.inc(
                    )
                return

            step_keys_query = peer.ReviewStep.all(
                keys_only=True
            ).filter(
                peer.ReviewStep.submission_key.name, submission_key
            )

            step_keys = step_keys_query.fetch(_REVIEW_STEP_QUERY_LIMIT)
            results = (submission_key, step_keys)

        except Exception as e:
            COUNTER_GET_SUBMISSION_AND_REVIEW_STEP_KEYS_FAILED.inc()
            raise e

        COUNTER_GET_SUBMISSION_AND_REVIEW_STEP_KEYS_SUCCESS.inc()
        COUNTER_GET_SUBMISSION_AND_REVIEW_STEP_KEYS_RETURNED.inc(
            increment=len(step_keys))
        return results
Beispiel #10
0
def remove_step(step):
    """Function to remove a manual evaluation step and perform related tasks"""
    evaluator_key = db.Key.from_path(course_staff.CourseStaff.kind(),
                                     step.evaluator)
    evaluator, summary = entities.get(
        [evaluator_key, step.manual_evaluation_summary_key])
    if summary:
        summary.decrement_count(step.state)
    else:
        manage.COUNTER_DELETE_REVIEWER_SUMMARY_MISS.inc()
    step.removed = True
    if evaluator:
        evaluator.num_assigned -= 1
    entities.put([entity for entity in [step, summary, evaluator] if entity])
Beispiel #11
0
    def _attempt_review_assignment(cls, review_summary_key, reviewer_key,
                                   last_change_date):
        COUNTER_GET_NEW_REVIEW_ASSIGNMENT_ATTEMPTED.inc()
        summary = entities.get(review_summary_key)
        if not summary:
            raise KeyError('No review summary found with key %s' %
                           repr(review_summary_key))
        if summary.change_date != last_change_date:
            # The summary has changed since we queried it. We cannot know for
            # sure what the edit was, but let's skip to the next one because it
            # was probably a review assignment.
            COUNTER_GET_NEW_REVIEW_SUMMARY_CHANGED.inc()
            return

        step = peer.ReviewStep.get_by_key_name(
            peer.ReviewStep.key_name(summary.submission_key, reviewer_key))

        if not step:
            step = peer.ReviewStep(assigner_kind=domain.ASSIGNER_KIND_AUTO,
                                   review_summary_key=summary.key(),
                                   reviewee_key=summary.reviewee_key,
                                   reviewer_key=reviewer_key,
                                   state=domain.REVIEW_STATE_ASSIGNED,
                                   submission_key=summary.submission_key,
                                   unit_id=summary.unit_id)
        else:
            if step.state == domain.REVIEW_STATE_COMPLETED:
                # Reviewer has previously done this review and the review
                # has been deleted. Skip to the next one.
                COUNTER_GET_NEW_REVIEW_CANNOT_UNREMOVE_COMPLETED.inc()
                return

            if step.removed:
                # We can reassign the existing review step.
                COUNTER_GET_NEW_REVIEW_REASSIGN_EXISTING.inc()
                step.removed = False
                step.assigner_kind = domain.ASSIGNER_KIND_AUTO
                step.state = domain.REVIEW_STATE_ASSIGNED
            else:
                # Reviewee has already reviewed or is already assigned to review
                # this submission, so we cannot reassign the step.
                COUNTER_GET_NEW_REVIEW_ALREADY_ASSIGNED.inc()
                return

        summary.increment_count(domain.REVIEW_STATE_ASSIGNED)
        return entities.put([step, summary])[0]
Beispiel #12
0
    def _attempt_review_assignment(
        cls, review_summary_key, reviewer_key, last_change_date):
        COUNTER_GET_NEW_REVIEW_ASSIGNMENT_ATTEMPTED.inc()
        summary = entities.get(review_summary_key)
        if not summary:
            raise KeyError('No review summary found with key %s' % repr(
                review_summary_key))
        if summary.change_date != last_change_date:
            # The summary has changed since we queried it. We cannot know for
            # sure what the edit was, but let's skip to the next one because it
            # was probably a review assignment.
            COUNTER_GET_NEW_REVIEW_SUMMARY_CHANGED.inc()
            return

        step = peer.ReviewStep.get_by_key_name(
            peer.ReviewStep.key_name(summary.submission_key, reviewer_key))

        if not step:
            step = peer.ReviewStep(
                assigner_kind=domain.ASSIGNER_KIND_AUTO,
                review_summary_key=summary.key(),
                reviewee_key=summary.reviewee_key, reviewer_key=reviewer_key,
                state=domain.REVIEW_STATE_ASSIGNED,
                submission_key=summary.submission_key, unit_id=summary.unit_id)
        else:
            if step.state == domain.REVIEW_STATE_COMPLETED:
                # Reviewer has previously done this review and the review
                # has been deleted. Skip to the next one.
                COUNTER_GET_NEW_REVIEW_CANNOT_UNREMOVE_COMPLETED.inc()
                return

            if step.removed:
                # We can reassign the existing review step.
                COUNTER_GET_NEW_REVIEW_REASSIGN_EXISTING.inc()
                step.removed = False
                step.assigner_kind = domain.ASSIGNER_KIND_AUTO
                step.state = domain.REVIEW_STATE_ASSIGNED
            else:
                # Reviewee has already reviewed or is already assigned to review
                # this submission, so we cannot reassign the step.
                COUNTER_GET_NEW_REVIEW_ALREADY_ASSIGNED.inc()
                return

        summary.increment_count(domain.REVIEW_STATE_ASSIGNED)
        return entities.put([step, summary])[0]
Beispiel #13
0
    def store_feedback(cls, handler, mark_completed):
        user = handler.current_user
        evaluator = handler.evaluator

        if not evaluator.can_grade:
            handler.error(404)
            handler.redirect('/course_staff')
            return

        key = handler.request.get('key')
        if not key:
            handler.error(404)
            handler.redirect('/course_staff')
            return

        step = entities.get(key)
        if not step:
            handler.error(404)
            handler.redirect('/course_staff')
            return

        if step.evaluator != user.user_id() and not evaluator.can_override:
            handler.error(404)
            handler.redirect('/course_staff')
            return

        score = 0
        course = handler.get_course()

        if handler.request.get('score'):
            score = float(handler.request.get('score'))

        manage.Manager.write_manual_review(step,
                                           handler.request.get('comments'),
                                           score,
                                           course,
                                           mark_completed=mark_completed)
Beispiel #14
0
    def _update_review_contents_and_change_state(
        cls, review_step_key, review_payload, mark_completed):
        should_increment_created_new_review = False
        should_increment_updated_existing_review = False
        should_increment_assigned_to_completed = False
        should_increment_expired_to_completed = False

        step = entities.get(review_step_key)
        if not step:
            COUNTER_WRITE_REVIEW_STEP_MISS.inc()
            raise KeyError(
                'No review step found with key %s' % repr(review_step_key))
        elif step.removed:
            raise domain.RemovedError(
                'Unable to process step %s' % repr(step.key()), step.removed)
        elif mark_completed and step.state == domain.REVIEW_STATE_COMPLETED:
            raise domain.TransitionError(
                'Unable to transition step %s' % repr(step.key()),
                step.state, domain.REVIEW_STATE_COMPLETED)

        if step.review_key:
            review_to_update = entities.get(step.review_key)
            if review_to_update:
                should_increment_updated_existing_review = True
        else:
            review_to_update = student_work.Review(
                contents=review_payload, reviewee_key=step.reviewee_key,
                reviewer_key=step.reviewer_key, unit_id=step.unit_id)
            step.review_key = db.Key.from_path(
                student_work.Review.kind(),
                student_work.Review.key_name(
                    step.unit_id, step.reviewee_key, step.reviewer_key))
            should_increment_created_new_review = True

        if not review_to_update:
            COUNTER_WRITE_REVIEW_REVIEW_MISS.inc()
            raise domain.ConstraintError(
                'No review found with key %s' % repr(step.review_key))

        summary = entities.get(step.review_summary_key)
        if not summary:
            COUNTER_WRITE_REVIEW_SUMMARY_MISS.inc()
            raise domain.ConstraintError(
                'No review summary found with key %s' % repr(
                    step.review_summary_key))

        review_to_update.contents = review_payload
        updated_step_key = None
        if not mark_completed:
            # pylint: disable=unbalanced-tuple-unpacking,unpacking-non-sequence
            _, updated_step_key = entities.put([review_to_update, step])
        else:
            if step.state == domain.REVIEW_STATE_ASSIGNED:
                should_increment_assigned_to_completed = True
            elif step.state == domain.REVIEW_STATE_EXPIRED:
                should_increment_expired_to_completed = True

            summary.decrement_count(step.state)
            step.state = domain.REVIEW_STATE_COMPLETED
            summary.increment_count(step.state)

            # pylint: disable=unbalanced-tuple-unpacking,unpacking-non-sequence
            _, updated_step_key, _ = entities.put(
                [review_to_update, step, summary])

        if should_increment_created_new_review:
            COUNTER_WRITE_REVIEW_CREATED_NEW_REVIEW.inc()
        elif should_increment_updated_existing_review:
            COUNTER_WRITE_REVIEW_UPDATED_EXISTING_REVIEW.inc()

        if should_increment_assigned_to_completed:
            COUNTER_WRITE_REVIEW_COMPLETED_ASSIGNED_STEP.inc()
        elif should_increment_expired_to_completed:
            COUNTER_WRITE_REVIEW_COMPLETED_EXPIRED_STEP.inc()

        return updated_step_key
Beispiel #15
0
        print "Visited links.....", visited
        print "Missing links.....", totalLinks-visited

if __name__ == '__main__':
    parser = OptionParser()
    parser.add_option("-r", "--request", dest="request_id")

    (options, args) = parser.parse_args()
    request_id = options.request_id

    from models import entities



    with db_session:
        request = entities.get(r for r in entities.WSRequest if r.request_id == request_id)

        print "id_proyecto:", request.id_proyecto
        print "nombre_directorio:", request.nombre_directorio

        # claves = entities.get(a for a in entities.Searchkeys_searchkey if a.request_id == request_id)
        searchkeys = Searchkeys_searchkey.select(lambda p: p.request_id == request_id)
        consulta = ""
        for searchKey in searchkeys:
            consulta = consulta + str(searchKey.clave) + " "

        consulta =  " ".join(filter(lambda x:x[0]!='-', consulta.split()))
        nombre_directorio = request.nombre_directorio
        # url_list tiene una lista de (orden, URL)
        url_list = request.urls.order_by(Url.orden)
def getClassByName(itemName):
    return entities.get(itemName)
Beispiel #17
0
    def _update_review_contents_and_change_state(cls, review_step_key,
                                                 review_payload,
                                                 mark_completed):
        should_increment_created_new_review = False
        should_increment_updated_existing_review = False
        should_increment_assigned_to_completed = False
        should_increment_expired_to_completed = False

        step = entities.get(review_step_key)
        if not step:
            COUNTER_WRITE_REVIEW_STEP_MISS.inc()
            raise KeyError('No review step found with key %s' %
                           repr(review_step_key))
        elif step.removed:
            raise domain.RemovedError(
                'Unable to process step %s' % repr(step.key()), step.removed)
        elif mark_completed and step.state == domain.REVIEW_STATE_COMPLETED:
            raise domain.TransitionError(
                'Unable to transition step %s' % repr(step.key()), step.state,
                domain.REVIEW_STATE_COMPLETED)

        if step.review_key:
            review_to_update = entities.get(step.review_key)
            if review_to_update:
                should_increment_updated_existing_review = True
        else:
            review_to_update = student_work.Review(
                contents=review_payload,
                reviewee_key=step.reviewee_key,
                reviewer_key=step.reviewer_key,
                unit_id=step.unit_id)
            step.review_key = db.Key.from_path(
                student_work.Review.kind(),
                student_work.Review.key_name(step.unit_id, step.reviewee_key,
                                             step.reviewer_key))
            should_increment_created_new_review = True

        if not review_to_update:
            COUNTER_WRITE_REVIEW_REVIEW_MISS.inc()
            raise domain.ConstraintError('No review found with key %s' %
                                         repr(step.review_key))

        summary = entities.get(step.review_summary_key)
        if not summary:
            COUNTER_WRITE_REVIEW_SUMMARY_MISS.inc()
            raise domain.ConstraintError(
                'No review summary found with key %s' %
                repr(step.review_summary_key))

        review_to_update.contents = review_payload
        updated_step_key = None
        if not mark_completed:
            # pylint: disable=unbalanced-tuple-unpacking,unpacking-non-sequence
            _, updated_step_key = entities.put([review_to_update, step])
        else:
            if step.state == domain.REVIEW_STATE_ASSIGNED:
                should_increment_assigned_to_completed = True
            elif step.state == domain.REVIEW_STATE_EXPIRED:
                should_increment_expired_to_completed = True

            summary.decrement_count(step.state)
            step.state = domain.REVIEW_STATE_COMPLETED
            summary.increment_count(step.state)

            # pylint: disable=unbalanced-tuple-unpacking,unpacking-non-sequence
            _, updated_step_key, _ = entities.put(
                [review_to_update, step, summary])

        if should_increment_created_new_review:
            COUNTER_WRITE_REVIEW_CREATED_NEW_REVIEW.inc()
        elif should_increment_updated_existing_review:
            COUNTER_WRITE_REVIEW_UPDATED_EXISTING_REVIEW.inc()

        if should_increment_assigned_to_completed:
            COUNTER_WRITE_REVIEW_COMPLETED_ASSIGNED_STEP.inc()
        elif should_increment_expired_to_completed:
            COUNTER_WRITE_REVIEW_COMPLETED_EXPIRED_STEP.inc()

        return updated_step_key
Beispiel #18
0
    def get_evaluate_subjective(cls, handler):
        user = handler.current_user
        evaluator = handler.evaluator

        key = handler.request.get('key')
        if not key:
            handler.error(404)
            handler.redirect('/course_staff')
            return

        step = entities.get(key)
        if not step:
            handler.error(404)
            handler.redirect('/course_staff')
            return

        if step.evaluator != user.user_id() and not evaluator.can_override:
            handler.error(404)
            handler.redirect('/course_staff')
            return

        unit_id = step.unit_id
        course = handler.get_course()
        unit = course.find_unit_by_id(unit_id)
        if not unit:
            handler.error(404)
            handler.redirect('/course')
            return

        submission = student_work.Submission.get_contents_by_key(
            step.submission_key)
        if not submission:
            handler.error(404)
            handler.redirect('/course_staff')
            return
        content = cls.get_content(course, unit)
        submission_content = transforms.loads(submission)

        if cls.ESSAY == content[cls.OPT_QUESTION_TYPE]:
            handler.template_value['essay'] = submission_content['essay']
        else:
            if 'copied_file' in submission_content.keys():
                copied_file = submission_content['copied_file']
                # For backward compatibility, checking for both the following
                # cases:
                # 1. copied_file is a list
                # 2. copied_file is a dict (will get depreciated soon)
                if isinstance(copied_file, list):
                    handler.template_value['file_meta_list'] = copied_file
                else:
                    handler.template_value['file_meta_list'] = [copied_file]

        handler.template_value[
            'save_comments_xsrf_token'] = handler.create_xsrf_token(
                'save_comments')
        handler.template_value[
            'submit_xsrf_token'] = handler.create_xsrf_token('submit_score')
        handler.template_value['reviewee'] = step.reviewee_key.id_or_name()
        handler.template_value['key'] = key
        handler.template_value['score'] = step.score if step.score else ''
        handler.template_value[
            'comments'] = step.comments if step.comments else ''

        handler.template_value['unit'] = unit
        handler.template_value['unit_id'] = unit.unit_id

        template_file = 'templates/course_staff/evaluate.html'
        template = jinja_utils.get_template(template_file,
                                            [os.path.dirname(__file__)])
        handler.render(template)