当前位置: 首页>>代码示例>>Python>>正文


Python models.user_by_anonymous_id函数代码示例

本文整理汇总了Python中student.models.user_by_anonymous_id函数的典型用法代码示例。如果您正苦于以下问题:Python user_by_anonymous_id函数的具体用法?Python user_by_anonymous_id怎么用?Python user_by_anonymous_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了user_by_anonymous_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_secret_key_changes

 def test_secret_key_changes(self):
     """Test that a new anonymous id is returned when the secret key changes."""
     CourseEnrollment.enroll(self.user, self.course.id)
     anonymous_id = anonymous_id_for_user(self.user, self.course.id)
     with override_settings(SECRET_KEY='some_new_and_totally_secret_key'):
         # Recreate user object to clear cached anonymous id.
         self.user = User.objects.get(pk=self.user.id)
         new_anonymous_id = anonymous_id_for_user(self.user, self.course.id)
         self.assertNotEqual(anonymous_id, new_anonymous_id)
         self.assertEqual(self.user, user_by_anonymous_id(anonymous_id))
         self.assertEqual(self.user, user_by_anonymous_id(new_anonymous_id))
开发者ID:Stanford-Online,项目名称:edx-platform,代码行数:11,代码来源:tests.py

示例2: test_roundtrip_with_unicode_course_id

 def test_roundtrip_with_unicode_course_id(self):
     course2 = CourseFactory.create(display_name=u"Omega Course Ω")
     CourseEnrollment.enroll(self.user, course2.id)
     anonymous_id = anonymous_id_for_user(self.user, course2.id)
     real_user = user_by_anonymous_id(anonymous_id)
     self.assertEqual(self.user, real_user)
     self.assertEqual(anonymous_id, anonymous_id_for_user(self.user, course2.id, save=False))
开发者ID:Stanford-Online,项目名称:edx-platform,代码行数:7,代码来源:tests.py

示例3: submissions_score_reset_handler

def submissions_score_reset_handler(sender, **kwargs):  # pylint: disable=unused-argument
    """
    Consume the score_reset signal defined in the Submissions API, and convert
    it to a SCORE_CHANGED signal indicating that the score has been set to 0/0.
    Converts the unicode keys for user, course and item into the standard
    representation for the SCORE_CHANGED signal.

    This method expects that the kwargs dictionary will contain the following
    entries (See the definition of score_reset):
      - 'anonymous_user_id': unicode,
      - 'course_id': unicode,
      - 'item_id': unicode
    """
    course_id = kwargs['course_id']
    usage_id = kwargs['item_id']
    user = user_by_anonymous_id(kwargs['anonymous_user_id'])

    # If any of the kwargs were missing, at least one of the following values
    # will be None.
    SCORE_CHANGED.send(
        sender=None,
        points_possible=0,
        points_earned=0,
        user=user,
        course_id=course_id,
        usage_id=usage_id
    )
开发者ID:open-craft,项目名称:edx-platform,代码行数:27,代码来源:handlers.py

示例4: submissions_score_reset_handler

def submissions_score_reset_handler(sender, **kwargs):  # pylint: disable=unused-argument
    """
    Consume the score_reset signal defined in the Submissions API, and convert
    it to a PROBLEM_WEIGHTED_SCORE_CHANGED signal indicating that the score
    has been set to 0/0. Converts the unicode keys for user, course and item
    into the standard representation for the PROBLEM_WEIGHTED_SCORE_CHANGED signal.

    This method expects that the kwargs dictionary will contain the following
    entries (See the definition of score_reset):
      - 'anonymous_user_id': unicode,
      - 'course_id': unicode,
      - 'item_id': unicode
    """
    course_id = kwargs['course_id']
    usage_id = kwargs['item_id']
    user = user_by_anonymous_id(kwargs['anonymous_user_id'])
    if user is None:
        return

    PROBLEM_WEIGHTED_SCORE_CHANGED.send(
        sender=None,
        weighted_earned=0,
        weighted_possible=0,
        user_id=user.id,
        anonymous_user_id=kwargs['anonymous_user_id'],
        course_id=course_id,
        usage_id=usage_id,
        modified=kwargs['created_at'],
        score_deleted=True,
        score_db_table=ScoreDatabaseTableEnum.submissions,
    )
开发者ID:edx,项目名称:edx-platform,代码行数:31,代码来源:handlers.py

示例5: submissions_score_set_handler

def submissions_score_set_handler(sender, **kwargs):  # pylint: disable=unused-argument
    """
    Consume the score_set signal defined in the Submissions API, and convert it
    to a PROBLEM_SCORE_CHANGED signal defined in this module. Converts the unicode keys
    for user, course and item into the standard representation for the
    PROBLEM_SCORE_CHANGED signal.

    This method expects that the kwargs dictionary will contain the following
    entries (See the definition of score_set):
      - 'points_possible': integer,
      - 'points_earned': integer,
      - 'anonymous_user_id': unicode,
      - 'course_id': unicode,
      - 'item_id': unicode
    """
    points_possible = kwargs['points_possible']
    points_earned = kwargs['points_earned']
    course_id = kwargs['course_id']
    usage_id = kwargs['item_id']
    user = user_by_anonymous_id(kwargs['anonymous_user_id'])
    if user is None:
        return

    PROBLEM_SCORE_CHANGED.send(
        sender=None,
        points_earned=points_earned,
        points_possible=points_possible,
        user_id=user.id,
        course_id=course_id,
        usage_id=usage_id)
开发者ID:gunjanmodi,项目名称:edx-platform,代码行数:30,代码来源:handlers.py

示例6: _get_username

def _get_username(submission, user_id):
    """
    Return username of student who provided `submission`.
    """
    # If the student ID key doesn't exist, we're dealing with a single student and know the ID already.
    student_id = submission.get("student_id", user_id)
    return user_by_anonymous_id(student_id).username
开发者ID:Semi-global,项目名称:problem-builder,代码行数:7,代码来源:tasks.py

示例7: get_student_data

        def get_student_data():
            # pylint: disable=no-member
            """
            Returns a dict of student assignment information along with
            annotated file name, student id and module id, this
            information will be used on grading screen
            """
            # Submissions doesn't have API for this, just use model directly. 直接操作model ,这一块是和成绩挂钩的关键
            students = SubmissionsStudent.objects.filter(
                course_id=self.course_id,
                item_id=self.block_id)
            for student in students:
                submission = self.get_submission(student.student_id)
                if not submission:
                    continue
                user = user_by_anonymous_id(student.student_id)
                module, created = StudentModule.objects.get_or_create(
                    course_id=self.course_id,
                    module_state_key=self.location,
                    student=user,
                    defaults={
                        'state': '{}',
                        'module_type': self.category,
                    })
                if created:
                    log.info(
                        "Init for course:%s module:%s student:%s  ",
                        module.course_id,
                        module.module_state_key,
                        module.student.username
                    )

                state = json.loads(module.state)
                score = self.get_score(student.student_id)
                approved = score is not None
                if score is None:
                    score = state.get('staff_score')
                    needs_approval = score is not None
                else:
                    needs_approval = False
                instructor = self.is_instructor()
                yield {
                    'module_id': module.id,
                    'student_id': student.student_id,
                    'submission_id': submission['uuid'],
                    'username': module.student.username,
                    #'student_answer': self.student_answer, #?? maybe error
                    'student_answer': submission['answer']["student_answer"],
                    'fullname': module.student.profile.name,
                    'filename': submission['answer']["filename"],
                    'timestamp': submission['created_at'].strftime(
                        DateTime.DATETIME_FORMAT
                    ),
                    'score': score,
                    'approved': approved,
                    'needs_approval': instructor and needs_approval,
                    'may_grade': instructor or not approved,
                    'annotated': state.get("annotated_filename"),
                    'comment': state.get("comment", ''),
                }
开发者ID:wwj718,项目名称:edx-sga,代码行数:60,代码来源:sga.py

示例8: submissions_score_reset_handler

def submissions_score_reset_handler(sender, **kwargs):  # pylint: disable=unused-argument
    """
    Consume the score_reset signal defined in the Submissions API, and convert
    it to a SCORE_CHANGED signal indicating that the score has been set to 0/0.
    Converts the unicode keys for user, course and item into the standard
    representation for the SCORE_CHANGED signal.

    This method expects that the kwargs dictionary will contain the following
    entries (See the definition of score_reset):
      - 'anonymous_user_id': unicode,
      - 'course_id': unicode,
      - 'item_id': unicode
    """
    course_id = kwargs.get('course_id', None)
    usage_id = kwargs.get('item_id', None)
    user = None
    if 'anonymous_user_id' in kwargs:
        user = user_by_anonymous_id(kwargs.get('anonymous_user_id'))

    # If any of the kwargs were missing, at least one of the following values
    # will be None.
    if all((user, course_id, usage_id)):
        SCORE_CHANGED.send(
            sender=None,
            points_possible=0,
            points_earned=0,
            user=user,
            course_id=course_id,
            usage_id=usage_id
        )
    else:
        log.exception(
            u"Failed to process score_reset signal from Submissions API. "
            "user: %s, course_id: %s, usage_id: %s", user, course_id, usage_id
        )
开发者ID:louyihua,项目名称:edx-platform,代码行数:35,代码来源:signals.py

示例9: _get_student_submissions

def _get_student_submissions(block_id, course_id, locator):
    """
    Returns valid submission file paths with the username of the student that submitted them.

    Args:
        course_id (unicode): edx course id
        block_id (unicode): edx block id
        locator (BlockUsageLocator): BlockUsageLocator for the sga module

    Returns:
        list(tuple): A list of 2-element tuples - (student username, submission file path)
    """
    submissions = submissions_api.get_all_submissions(
        course_id,
        block_id,
        ITEM_TYPE
    )
    return [
        (
            user_by_anonymous_id(submission['student_id']).username,
            get_file_storage_path(
                locator,
                submission['answer']['sha1'],
                submission['answer']['filename']
            )
        )
        for submission in submissions if submission['answer']
    ]
开发者ID:doctoryes,项目名称:edx-sga,代码行数:28,代码来源:tasks.py

示例10: get_student_data

 def get_student_data():
     # Submissions doesn't have API for this, just use model directly
     students = SubmissionsStudent.objects.filter(
         course_id=self.course_id,
         item_id=self.block_id)
     for student in students:
         submission = self.get_submission(student.student_id)
         if not submission:
             continue
         user = user_by_anonymous_id(student.student_id)
         module, _ = StudentModule.objects.get_or_create(
             course_id=self.course_id,
             module_state_key=self.location,
             student=user,
             defaults={
                 'state': '{}',
                 'module_type': self.category,
             })
         state = json.loads(module.state)
         score = self.get_score(student.student_id)
         approved = score is not None
         if score is None:
             score = state.get('staff_score')
             needs_approval = score is not None
         else:
             needs_approval = False
         instructor = self.is_instructor()
         yield {
             'module_id': module.id,
             'student_id': student.student_id,
             'submission_id': submission['uuid'],
             'username': module.student.username,
             'fullname': module.student.profile.name,
             'filename': submission['answer']["filename"],
             'timestamp': submission['created_at'].strftime(
                 DateTime.DATETIME_FORMAT
             ),
             'score': score,
             'approved': approved,
             'needs_approval': instructor and needs_approval,
             'may_grade': instructor or not approved,
             'annotated': state.get("annotated_filename"),
             'comment': state.get("comment", ''),
         }
开发者ID:eduNEXT,项目名称:edunext-sga,代码行数:44,代码来源:sga.py

示例11: get_student_data

 def get_student_data():
     # pylint: disable=no-member
     """
     Returns a dict of student assignment information along with
     annotated file name, student id and module id, this
     information will be used on grading screen
     """
     # Submissions doesn't have API for this, just use model directly.
     students = SubmissionsStudent.objects.filter(
         course_id=self.course_id,
         item_id=self.block_id)
     for student in students:
         submission = self.get_submission(student.student_id)
         if not submission:
             continue
         user = user_by_anonymous_id(student.student_id)
         student_module = self.get_or_create_student_module(user)
         state = json.loads(student_module.state)
         score = self.get_score(student.student_id)
         approved = score is not None
         if score is None:
             score = state.get('staff_score')
             needs_approval = score is not None
         else:
             needs_approval = False
         instructor = self.is_instructor()
         yield {
             'module_id': student_module.id,
             'student_id': student.student_id,
             'submission_id': submission['uuid'],
             'username': student_module.student.username,
             'fullname': student_module.student.profile.name,
             'filename': submission['answer']["filename"],
             'timestamp': submission['created_at'].strftime(
                 DateTime.DATETIME_FORMAT
             ),
             'score': score,
             'approved': approved,
             'needs_approval': instructor and needs_approval,
             'may_grade': instructor or not approved,
             'annotated': force_text(state.get("annotated_filename", '')),
             'comment': force_text(state.get("comment", '')),
             'finalized': is_finalized_submission(submission_data=submission)
         }
开发者ID:mitodl,项目名称:edx-sga,代码行数:44,代码来源:sga.py

示例12: get_encoded_data

    def get_encoded_data(self):
        """
        Collect all data needed and encode it
        Returns: string

        """
        if self.is_course_staff():
            return ""
        user = user_by_anonymous_id(self.runtime.anonymous_student_id)
        data = {
            'course_id': str(self.course_id),
            'username': user.username,
            'email': user.email,
            'fullname': "%s %s" % (user.first_name, user.last_name)

        }
        row = json.dumps(data)
        encoded = AESCipher(settings.FEATURES['REDDIT_SECRET_KEY']).encrypt(row)
        return "?data=" + urllib.quote(encoded)
开发者ID:oksana-slu,项目名称:reddin,代码行数:19,代码来源:reddin.py

示例13: handle

    def handle(self, *args, **options):
        if 'modified_start' not in options:
            raise CommandError('modified_start must be provided.')

        if 'modified_end' not in options:
            raise CommandError('modified_end must be provided.')

        modified_start = utc.localize(datetime.strptime(options['modified_start'], DATE_FORMAT))
        modified_end = utc.localize(datetime.strptime(options['modified_end'], DATE_FORMAT))
        event_transaction_id = create_new_event_transaction_id()
        set_event_transaction_type(PROBLEM_SUBMITTED_EVENT_TYPE)
        kwargs = {'modified__range': (modified_start, modified_end), 'module_type': 'problem'}
        for record in StudentModule.objects.filter(**kwargs):
            task_args = {
                "user_id": record.student_id,
                "course_id": unicode(record.course_id),
                "usage_id": unicode(record.module_state_key),
                "only_if_higher": False,
                "expected_modified_time": to_timestamp(record.modified),
                "score_deleted": False,
                "event_transaction_id": unicode(event_transaction_id),
                "event_transaction_type": PROBLEM_SUBMITTED_EVENT_TYPE,
                "score_db_table": ScoreDatabaseTableEnum.courseware_student_module,
            }
            recalculate_subsection_grade_v3.apply_async(kwargs=task_args)

        kwargs = {'created_at__range': (modified_start, modified_end)}
        for record in Submission.objects.filter(**kwargs):
            task_args = {
                "user_id": user_by_anonymous_id(record.student_item.student_id).id,
                "anonymous_user_id": record.student_item.student_id,
                "course_id": unicode(record.student_item.course_id),
                "usage_id": unicode(record.student_item.item_id),
                "only_if_higher": False,
                "expected_modified_time": to_timestamp(record.created_at),
                "score_deleted": False,
                "event_transaction_id": unicode(event_transaction_id),
                "event_transaction_type": PROBLEM_SUBMITTED_EVENT_TYPE,
                "score_db_table": ScoreDatabaseTableEnum.submissions,
            }
            recalculate_subsection_grade_v3.apply_async(kwargs=task_args)
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:41,代码来源:recalculate_subsection_grades.py

示例14: post_comment

 def post_comment(self, data, suffix=''):
     #IT MIGHT BE BETTER TO MAINTAIN THE PRIMARY KEYS than rely on SQL auto increment since it is hard to get back the primary key.
     ajax_comment = data.get('comment')
     """
     The ajax supplied comment may have ' (apostrophe/single quote) embedded in it. These must be escaped before
     being put into the SQL query (which itself relies on single quotes when inserting strings).
     """
     safe_comment = ""
     self.xblock_login = self.student_id()
     current_user = user_by_anonymous_id(self.xblock_login)
     for char in ajax_comment:
         if (char != "'"):
             safe_comment += char
         else:
             safe_comment +="\\'" #Escaping the embedded single quote using a single \. We use \\ to escape it in python as well
             #ALSO CHECK DOUBLE QUOTES AND WILDCARD CHARACTER CASES!!!
     insert_query = ("INSERT INTO discussion_table (thread_id, user_id, user_name, comment, parent_id) VALUES (2, '" + self.xblock_login + "', '" + current_user.username + "', '" + safe_comment + "', -1)")
     ret_val = self.exec_query(insert_query,"Inserting user comment")
     if(ret_val == 0):
         return {'update_status': "Success"}
     else:
         return {'update_status': "Failure"}
开发者ID:DANCEcollaborative,项目名称:forum-xblock,代码行数:22,代码来源:discussion_dance.py

示例15: submissions_score_set_handler

def submissions_score_set_handler(sender, **kwargs):  # pylint: disable=unused-argument
    """
    Consume the score_set signal defined in the Submissions API, and convert it
    to a PROBLEM_WEIGHTED_SCORE_CHANGED signal defined in this module. Converts the
    unicode keys for user, course and item into the standard representation for the
    PROBLEM_WEIGHTED_SCORE_CHANGED signal.

    This method expects that the kwargs dictionary will contain the following
    entries (See the definition of score_set):
      - 'points_possible': integer,
      - 'points_earned': integer,
      - 'anonymous_user_id': unicode,
      - 'course_id': unicode,
      - 'item_id': unicode
    """
    points_possible = kwargs['points_possible']
    points_earned = kwargs['points_earned']
    course_id = kwargs['course_id']
    usage_id = kwargs['item_id']
    user = user_by_anonymous_id(kwargs['anonymous_user_id'])
    if user is None:
        return
    if points_possible == 0:
        # This scenario is known to not succeed, see TNL-6559 for details.
        return

    PROBLEM_WEIGHTED_SCORE_CHANGED.send(
        sender=None,
        weighted_earned=points_earned,
        weighted_possible=points_possible,
        user_id=user.id,
        anonymous_user_id=kwargs['anonymous_user_id'],
        course_id=course_id,
        usage_id=usage_id,
        modified=kwargs['created_at'],
        score_db_table=ScoreDatabaseTableEnum.submissions,
    )
开发者ID:edx,项目名称:edx-platform,代码行数:37,代码来源:handlers.py


注:本文中的student.models.user_by_anonymous_id函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。