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


Python UserProfile.email方法代码示例

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


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

示例1: import_user_submit

# 需要导入模块: from student.models import UserProfile [as 别名]
# 或者: from student.models.UserProfile import email [as 别名]
def import_user_submit(request):
    # http://www.cnblogs.com/yijun-boxing/archive/2011/04/18/2020155.html
    
    CONTRACT_CVS_COL_CONTRACT_ID=0
    CONTRACT_CVS_COL_DISTRICT_ID=1
    CONTRACT_CVS_COL_EMAIL=2
    CONTRACT_CVS_COL_USERNAME=3
    CONTRACT_CVS_COUNT_COL=4
    
    message={}
    n=0
    if request.method == 'POST':
        f=request.FILES['file']
        dialect = csv.Sniffer().sniff(f.read(1024), delimiters=";,")
        f.seek(0)
        r=csv.reader(f,dialect)
        try:
            for i,line in enumerate(r):
                n=n+1

                contract_id=line[CONTRACT_CVS_COL_CONTRACT_ID]
                district_id=line[CONTRACT_CVS_COL_DISTRICT_ID]
                email=line[CONTRACT_CVS_COL_EMAIL]
                username=line[CONTRACT_CVS_COL_USERNAME]

                for value in line:
                    if len(value.strip())==0:
                        raise Exception("Catch csv line with empty fields line")
                

                if len(line) != CONTRACT_CVS_COUNT_COL:
                    raise Exception("Catch csv line of wrong fields count")

                user = User(username=username, email=email, is_active=True)
                user.set_password(username)
                registration = Registration()

                try:
                    user.save()
                except IntegrityError:
                    if len(User.objects.filter(username=username)) > 0:
                        raise Exception("An account with the Public Username '{username}' already exists.".format(username=username))
                       
                    if len(User.objects.filter(email=email)) > 0:
                        raise Exception("An account with the Email '{email}' already exists.".format(email=email))

                registration.register(user)
    
                profile=UserProfile(user=user)
                profile.contract_id=contract_id
                profile.district_id=district_id
                profile.email=email
                profile.username=username
                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)


                try:
                    _res = user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
                except:
                    log.warning('Unable to send reactivation email', exc_info=True)
                    return HttpResponse(json.dumps({'success': False, 'error': _('Unable to send reactivation email')}))                
                
                
            message={'success': True, "message":"Success! %s users imported." % (n)}
        except Exception as e:
            transaction.rollback()
            message={'success': False,'message':'Import error: %s, At cvs line: %s' % (e,n)}
            
        # title = forms.CharField(max_length=50)
        # file = forms.FileField()
        
    return HttpResponse(json.dumps(message))
开发者ID:EduPepperPD,项目名称:pepper2013,代码行数:81,代码来源:views.py


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