本文整理汇总了Python中userprofile.models.UserProfile.get_by_student_id方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.get_by_student_id方法的具体用法?Python UserProfile.get_by_student_id怎么用?Python UserProfile.get_by_student_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类userprofile.models.UserProfile
的用法示例。
在下文中一共展示了UserProfile.get_by_student_id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import get_by_student_id [as 别名]
def create(self, validated_data):
user_dict = validated_data['user']
tag_dict = validated_data['tag']
first_in_required = [ f for f in self._required if f in user_dict ][0]
user = {
'id': lambda: UserProfile.objects.get(user__id=user_dict['id']),
'student_id': lambda: UserProfile.get_by_student_id(user_dict['student_id']),
'username': lambda: UserProfile.objects.get(user__username=user_dict['username']),
'email': lambda: UserProfile.get_by_email(user_dict['email']),
}[first_in_required]()
tag = UserTag.objects.get(
slug=tag_dict['slug'],
course_instance=self.context['course_id']
)
obj, created = UserTagging.objects.set(user, tag)
if not created:
raise serializers.ValidationError(
'User {user} already has tag {slug}'.format(
user=user.user.username,
slug=tag.slug,
)
)
return obj
示例2: __init__
# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import get_by_student_id [as 别名]
def __init__(self, *args, **kwargs):
super(StaffSubmissionForStudentForm, self).__init__(*args, **kwargs)
self.fields["students"] = forms.ModelMultipleChoiceField(
queryset=self.exercise.course_instance.get_students(),
required=False)
self.fields["students_by_student_id"] = forms.TypedMultipleChoiceField(
empty_value=UserProfile.objects.none(),
coerce=lambda student_id: UserProfile.get_by_student_id(student_id),
choices=[(p.student_id, p.student_id) for p in self.exercise.course_instance.get_students().exclude(student_id=None)],
required=False)
示例3: test_userprofile_get_by_student_id
# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import get_by_student_id [as 别名]
def test_userprofile_get_by_student_id(self):
self.assertEqual(self.student_profile, UserProfile.get_by_student_id("12345X"))
self.assertEqual(self.grader_profile, UserProfile.get_by_student_id("67890Y"))
self.assertRaises(UserProfile.DoesNotExist, UserProfile.get_by_student_id, "111111")