本文整理汇总了Python中student.models.UserProfile.school方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.school方法的具体用法?Python UserProfile.school怎么用?Python UserProfile.school使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.models.UserProfile
的用法示例。
在下文中一共展示了UserProfile.school方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_unknown_user
# 需要导入模块: from student.models import UserProfile [as 别名]
# 或者: from student.models.UserProfile import school [as 别名]
def create_unknown_user(request, ms, data):
'''Create the sso user who\'s not exists in pepper'''
try:
attribute_setting = ms.get('attributes')
# Parse to mapped attribute
parsed_data = {}
for attr in attribute_setting:
mapped_name = attr['map'] if 'map' in attr else attr['name']
if attr['name']:
parsed_data[mapped_name] = data.get(attr['name'])
print attribute_setting
print data
print parsed_data
# Generate username if not provided
if not parsed_data.get('username'):
username = random_mark(20)
else:
username = parsed_data['username']
# Email must be profided
email = parsed_data['email']
user = User(username=username, email=email, is_active=False)
user.set_password(username) # Set password the same with username
user.save()
registration = Registration()
registration.register(user)
profile = UserProfile(user=user)
profile.subscription_status = "Imported"
profile.sso_type = ms.get('sso_type')
profile.sso_idp = ms.get('sso_name')
# Save mapped attributes
for k, v in parsed_data.items():
if k == 'first_name':
user.first_name = parsed_data['first_name']
elif k == 'last_name':
user.last_name = parsed_data['last_name']
elif k == 'sso_user_id':
profile.sso_user_id = parsed_data['sso_user_id']
elif k == 'district':
profile.district = District.object.get(name=parsed_data['district'])
elif k == 'school':
profile.school = School.object.get(name=parsed_data['school'])
elif k == 'grade_level':
ids = GradeLevel.object.filter(name__in=parsed_data['grade_level'].split(',')).values_list('id', flat=True)
profile.grade_level = ','.join(ids)
elif k == 'major_subject_area':
ids = SubjectArea.object.filter(name__in=parsed_data['major_subject_area'].split(',')).values_list('id', flat=True)
profile.major_subject_area = ','.join(ids)
elif k == 'years_in_education':
profile.years_in_education = YearsInEducation.object.get(name=parsed_data['years_in_education'])
elif k == 'percent_lunch':
profile.percent_lunch = Enum.object.get(name='percent_lunch', content=parsed_data['percent_lunch'])
elif k == 'percent_iep':
profile.percent_iep = Enum.object.get(name='percent_iep', content=parsed_data['percent_iep'])
elif k == 'percent_eng_learner':
profile.percent_eng_learner = Enum.object.get(name='percent_eng_learner', content=parsed_data['percent_eng_learner'])
user.save()
profile.save()
cea, _ = CourseEnrollmentAllowed.objects.get_or_create(course_id='PCG_Education/PEP101.1/S2016', email=email)
cea.is_active = True
cea.auto_enroll = True
cea.save()
return https_redirect(request, reverse('register_sso_user', args=[registration.activation_key]))
except Exception as e:
raise e
db.transaction.rollback()
log.error("error: failed to create SSO user: %s" % e)