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


Python UserProfile.cohort_id方法代码示例

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


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

示例1: user_submit

# 需要导入模块: from student.models import UserProfile [as 别名]
# 或者: from student.models.UserProfile import cohort_id [as 别名]
def user_submit(request):
    if not request.user.is_authenticated:
        raise Http404
    try:
        if request.POST.get('id'):
            profile=UserProfile.objects.get(user_id=request.POST['id'])
            user=User.objects.get(id=request.POST['id'])
        else:
            profile=UserProfile()
            user=User()

        if request.POST['subscription_status']=='Registered':
            user.is_active=True
        else:
            user.is_active=False

        user.email=request.POST['email']
        user.save()

        profile.user_id=user.id
        profile.school_id=request.POST['school_id']
        profile.cohort_id=request.POST['cohort_id']
        profile.district_id=request.POST['district_id']
        profile.subscription_status=request.POST['subscription_status']
        profile.save()

    except Exception as e:
        db.transaction.rollback()
        return HttpResponse(json.dumps({'success': False,'error':'%s' % e}))
    return HttpResponse(json.dumps({'success': True}))
开发者ID:EduPepperPDTesting,项目名称:pepper2013-testing,代码行数:32,代码来源:views.py

示例2: import_user_submit

# 需要导入模块: from student.models import UserProfile [as 别名]
# 或者: from student.models.UserProfile import cohort_id [as 别名]
def import_user_submit(request):
    message={}
    if request.method == 'POST':
        f=request.FILES['file']
        try:
            count_success=0
            # --- THIS FAILS ON SING COLUMN CVS ---
            # dialect = csv.Sniffer().sniff(f.read(1024), delimiters=";,")
            # f.seek(0)
            # r=csv.reader(f,dialect)
            r=csv.reader(f,delimiter='\t', quotechar='|', quoting=csv.QUOTE_MINIMAL)
            rl = []
            rl.extend(r)
            cohort_id=request.POST.get("cohort_id")
            cohort=Cohort.objects.get(id=cohort_id)
            if cohort.licences < UserProfile.objects.filter(~Q(subscription_status = "Inactive"),cohort_id=cohort_id).count() + len(rl):
                raise Exception("Licences limit exceeded")
            for line in rl:
                exist=validate_user_cvs_line(line)
                # if(exist):
                #     raise Exception("An user already exists, or duplicate lines.")
                email=line[USER_CSV_COL_EMAIL]
                import random
                username=random_mark(20)
                user = User(username=username, email=email, is_active=False)
                user.set_password(username)
                user.save()
                registration = Registration()
                registration.register(user)
                profile=UserProfile(user=user)
                # profile.transaction_id=transaction_id
                # profile.email=email
                # profile.username=username
                profile.cohort_id=cohort_id
                profile.subscription_status="Imported"
                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()

                count_success=count_success+1

                # reg = Registration.objects.get(user=user)
                # d = {'name': profile.name, 'key': reg.activation_key}
                # subject = render_to_string('emails/activation_email_subject.txt', d)
                # subject = ''.join(subject.splitlines())
                # message = render_to_string('emails/activation_emailh.txt', d)
            db.transaction.commit()
            message={"success": True,
                "message":"Success! %s users imported." % (count_success),
                "count_success":count_success,
            }
        except Exception as e:
            db.transaction.rollback()
            message={'success': False,'error':'Import error: %s. At cvs line: %s, Nobody imported.' % (e,count_success+1)}
    return HttpResponse(json.dumps(message))
开发者ID:EduPepperPDTesting,项目名称:pepper2013-testing,代码行数:60,代码来源:views.py

示例3: import_user_submit

# 需要导入模块: from student.models import UserProfile [as 别名]
# 或者: from student.models.UserProfile import cohort_id [as 别名]
def import_user_submit(request):
    message = {}
    if request.method == "POST":
        f = request.FILES["file"]
        try:
            count_success = 0
            count_exist = 0
            # --- THIS FAILS ON SING COLUMN CVS ---
            # dialect = csv.Sniffer().sniff(f.read(1024), delimiters=";,")
            # f.seek(0)
            # r=csv.reader(f,dialect)
            r = csv.reader(f, delimiter="\t", quotechar="|", quoting=csv.QUOTE_MINIMAL)
            rl = []
            rl.extend(r)
            cohort_id = request.POST.get("cohort_id")
            cohort = Cohort.objects.get(id=cohort_id)
            if cohort.licences < UserProfile.objects.filter(cohort_id=cohort_id).count() + len(rl):
                raise Exception("Licences limit exceeded")
            for line in rl:
                exist = validate_user_cvs_line(line)
                # if(exist):
                #     raise Exception("An user already exists, or duplicate lines.")
                email = line[USER_CVS_COL_EMAIL]
                import random

                username = "".join(random.sample("abcdefg&#%^*f1234567890", 20))
                user = User(username=username, email=email, is_active=True)
                user.set_password(username)
                user.save()
                registration = Registration()
                registration.register(user)
                profile = UserProfile(user=user)
                # profile.transaction_id=transaction_id
                # profile.email=email
                # profile.username=username
                profile.cohort_id = cohort_id
                profile.subscription_status = "Imported"
                profile.save()
                # reg = Registration.objects.get(user=user)
                # d = {'name': profile.name, 'key': reg.activation_key}
                # subject = render_to_string('emails/activation_email_subject.txt', d)
                # subject = ''.join(subject.splitlines())
                # message = render_to_string('emails/activation_email.txt', d)
            db.transaction.commit()
            message = {
                "success": True,
                "message": "Success! %s users imported." % (count_success),
                "count_exist": count_exist,
                "count_success": count_success,
            }
        except Exception as e:
            db.transaction.rollback()
            message = {
                "success": False,
                "error": "Import error: %s. At cvs line: %s, Nobody imported." % (e, count_success + 1),
            }
    return HttpResponse(json.dumps(message))
开发者ID:EduPepperPD,项目名称:pepper2013,代码行数:59,代码来源:views.py


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