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


Python UserProfile.percent_eng_learner方法代码示例

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


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

示例1: create_unknown_user

# 需要导入模块: from student.models import UserProfile [as 别名]
# 或者: from student.models.UserProfile import percent_eng_learner [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)
开发者ID:EduPepperPDTesting,项目名称:pepper2013-testing,代码行数:80,代码来源:sp.py


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