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


Python UserProfile.user方法代码示例

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


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

示例1: register

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
 def register(self, request, **kwargs):
     if Site._meta.installed:
         site = Site.objects.get_current()
     else:
         site = RequestSite(request)
     print site
     user = User()
     user.username = kwargs['username']
     user.email = kwargs['email']
     password = kwargs['password1']
     user.set_password(password)
     user.first_name = kwargs['first_name']
     user.last_name = kwargs['last_name']
     user.is_active = False
     user.save()
     profile_user = UserProfile()
     # Любое совпадение наименования полей и аргументов- случайно :), так
     # проще не ошибиться
     profile_user.country = kwargs['country']
     profile_user.city = kwargs['city']
     profile_user.company = kwargs['company']
     profile_user.dokladchik = kwargs['dokladchik']
     profile_user.surname = kwargs['surname']
     profile_user.job = kwargs['job']
     profile_user.accepted_eula = kwargs['accepted_eula']
     profile_user.user = user
     profile_user.save()
     prof = RegistrationProfile.objects.create_profile(user)
     prof.send_activation_email(site)
     return user
开发者ID:Denis-Savin,项目名称:ivpy,代码行数:32,代码来源:backend.py

示例2: active_user

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
def active_user(request, uidb36=None, token=None,
                         template_name='register/activation_confirm.html',
                         token_generator=default_token_generator,
                         current_app=None, extra_context=None):
    """
    View that checks the hash in a active user link and make user to be active
    """
    assert uidb36 is not None and token is not None # checked by URLconf
   
    try:
        uid_int = base36_to_int(uidb36)
        user = User.objects.get(id=uid_int)
    except (ValueError, User.DoesNotExist):
        user = None

    if user is not None and token_generator.check_token(user, token):
        validlink = True
        user.is_active = True
        user.save()
        
        #初始化userprofile
        profile_count = UserProfile.objects.filter(user=user).count()
        if profile_count == 0:
            profile = UserProfile()
            profile.user = user
            profile.song_ord_filed = 'post_datetime'
            profile.save()
    else:
        validlink = False
    context = {
        'validlink': validlink,
    }
    context.update(extra_context or {})
    return render_to_response(template_name, context,
                              context_instance=RequestContext(request, current_app=current_app))
开发者ID:andy071001,项目名称:dongtingfm,代码行数:37,代码来源:views.py

示例3: save

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
 def save(self,request):
     if self.cleaned_data['city'] or self.cleaned_data['website'] or self.cleaned_data['intro'] or self.cleaned_data['qq'] or self.cleaned_data['msn'] or self.cleaned_data['avatar']:
        
         current_user = request.user
        
         try:
             profile = current_user.get_profile()
         except UserProfile.DoesNotExist:
             profile = None
         
         if not profile:
             profile = UserProfile()
             profile.user = current_user
             profile.song_ord_filed = 'post_datetime'
             
         profile.city = self.cleaned_data['city']
         profile.website = self.cleaned_data['website']
         profile.intro = self.cleaned_data['intro']
         profile.qq = self.cleaned_data['qq']
         profile.msn = self.cleaned_data['msn']
         if 'avatar' in request.FILES:
             
             #删除掉原头像
             import os
             if profile and profile.avatar and os.path.exists(profile.avatar.path):
                 os.remove(profile.avatar.path)
                              
             profile.avatar = self.cleaned_data['avatar']#request.FILES["avatar"]
         profile.save()
         
         if self.cleaned_data['username'] != current_user.username:
             current_user.username = self.cleaned_data['username']
             current_user.save()
开发者ID:andy071001,项目名称:dongtingfm,代码行数:35,代码来源:forms.py

示例4: create_user_from_weibo

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
def create_user_from_weibo(request, template_name='register/create_user_from_weibo.html'):

    oauth_access_token = request.session.get('oauth_access_token', None)

    if request.user.is_authenticated() or oauth_access_token is None:
        return HttpResponseRedirect(reverse('home.views.index'))

    client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=_get_weibo_callback_url(request))
    client.set_access_token(oauth_access_token['access_token'], oauth_access_token['expires_in'])

    weibo_user = client.get.users__show(uid=oauth_access_token['uid'])
    weibo_username = weibo_user.screen_name

    template_var = {}
    form = RegistrationForm(initial={'username': weibo_username })
    if request.method == 'POST':
        form = RegistrationForm(request.POST.copy())
        if request.method == 'POST':
            if form.is_valid():
                username = form.cleaned_data['username']
                email = form.cleaned_data['email']
                password = form.cleaned_data['password']
                user = User.objects.create_user(username,email,password)
                user.is_active = True
                user.save()

                profile = UserProfile()
                profile.user = user
                profile.song_ord_filed = 'post_datetime'
                profile.save()

                #weibo信息记录
                w_user = WeiboUser()
                w_user.user = user

                w_user.weibo_user_id = oauth_access_token['uid']
                w_user.weibo_username = weibo_username
                w_user.oauth_access_token = oauth_access_token['access_token']
                w_user.save()

                #发微博提示
                if request.POST.get('update_msg'):
                    msg = request.POST.get('bind_msg')[0:140]
                    client.post.statuses__update(status=msg)

                user = authenticate(username=username, password=password)
                auth_login(request,user)

                return HttpResponseRedirect(reverse('songs.views.my_home'))

    template_var['form'] = form
    template_var['weibo_username'] = weibo_username
    return render_to_response(template_name, template_var, context_instance=RequestContext(request))
开发者ID:andy071001,项目名称:dongtingfm,代码行数:55,代码来源:views.py

示例5: createBranchAdmin

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
def createBranchAdmin():
    user = User()
    user.username = 'branchA'
    user.first_name = 'A分部管理員'
    user.set_password('branchA')
    user.email = '[email protected]'
    user.save()

    userProfile = UserProfile()
    userProfile.branch = Branch.objects.create(name='分部A', address='分部A', phone='0912345678')
    userProfile.user = user
    userProfile.save()
    return user
开发者ID:charles5991,项目名称:cyutmit,代码行数:15,代码来源:util.py

示例6: index

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
def index(request,u_id,page=1):
    """
    查看用户个人资料
    """

    # 初始化
    try:
        u_id = int(u_id)
    except :
        return HttpResponse(u_id)

    # 根据ID得到用户对象
    try:
        user = User.objects.get(id=u_id)
    except User.DoesNotExist:
        raise Http404()

    # 如果是当前用户自己则跳转到个人中心
    if request.user == user:
        return HttpResponseRedirect('/home/')
    elif request.user.is_authenticated():
        visitor,visitor_created= Visitor.objects.get_or_create(master=user,visitor=request.user)
        visitor.sub_time = datetime.datetime.now()
        visitor.save()
    # 得到用户档案
    try:
        profile = user.get_profile()
    except UserProfile.DoesNotExist:
        profile = UserProfile()
        profile.user = user
        profile.save()

    # 如果账号以删除
    if profile.deleted == True:
        return render('home_none.html',locals(),context_instance=RequestContext(request))
    
    # 对未登录的用户只显示前15条动态
    if not request.user.is_authenticated():
        develop_all = Develop.objects.filter(user=profile.user)[:5]
    else:
        develop_all = Develop.objects.filter(user=profile.user)

    paginator = Paginator(develop_all,15)
    pre_url = 'home/%d' %profile.user.id
    current_page = 'develop'
    try:
        develops = paginator.page(page)
    except (EmptyPage,InvalidPage):
        develops = paginator.page(paginator.num_pages)
    return render('home_index.html',locals(),context_instance=RequestContext(request))
开发者ID:gnemoug,项目名称:pythoner.net,代码行数:52,代码来源:profile.py

示例7: create_userprofile

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
def create_userprofile(user):
  p = UserProfile()
  p.user = user
  p.birth = datetime.datetime.now()
  p.mobile = '+417X1234567'
  p.private_phone = '+41221234567'
  p.instrument = random.choice([k[0] for k in UserProfile.instrument_choices])
  p.language = random.choice([k[0] for k in settings.LANGUAGES])
  p.im = user.email
  p.im_carrier = random.choice([k[0] for k in UserProfile.im_choices])
  p.website = 'www.example.com'
  p.saying = 'Nothing to say'
  p.address = 'Do not known St, xyz, No Country'
  p.save()
开发者ID:anjos,项目名称:unidos-website,代码行数:16,代码来源:tests_initial.py

示例8: createSuperuser

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
def createSuperuser():
    admin = User()
    admin.username = 'admin'
    admin.first_name = '管理員'
    admin.set_password('admin')
    admin.email = '[email protected]'
    admin.is_staff = True
    admin.is_superuser = True
    admin.save()
    
    userProfile = UserProfile()
    userProfile.branch = Branch.objects.create(name='總部', address='XX', phone='0912345678')
    userProfile.user = admin
    userProfile.save()
    return admin
开发者ID:charles5991,项目名称:cyutmit,代码行数:17,代码来源:util.py

示例9: songs_by_user

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
def songs_by_user(request, uid, template_name):
    if long(uid) == request.user.id:
        return my_songs(request, template_name)
    else:
        user_profile = None
        u = None
        template_var = {}
        try:
            u = User.objects.get(id=uid)
            songs = Song.objects.select_related().filter(user=u)
            try:
                user_profile = u.get_profile()
            except UserProfile.DoesNotExist:
                user_profile = UserProfile()
                user_profile.user = u
                user_profile.save()

            if request.user.is_authenticated():
                my_blacklist = BlackList.objects.filter(user=request.user, bad_guy=u)
                if my_blacklist:
                    template_var["in_my_blacklist"] = True
        except User.DoesNotExist:
            songs = None

        try:
            if request.user.is_authenticated():
                user_follower = UserFollower.objects.get(user=u, follower=request.user)
                template_var["user_follower"] = user_follower
        except UserFollower.DoesNotExist:
            template_var["user_follower"] = None

        paginator = Paginator(songs, 20)
        try:
            page = int(request.GET.get("page", "1"))
        except ValueError:
            page = 1

        try:
            songs = paginator.page(page)
        except (EmptyPage, InvalidPage):
            songs = paginator.page(paginator.num_pages)

        template_var["favorite_action"] = "add"
        template_var["current_tabnav"] = "user_songs"
        template_var["user_profile"] = user_profile
        template_var["songs"] = songs

        return render_to_response(template_name, template_var, context_instance=RequestContext(request))
开发者ID:laonan,项目名称:dongtingfm,代码行数:50,代码来源:views.py

示例10: create_new_user

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
def create_new_user(email, name = None):
    ups = UserProfile.objects.filter(email = email)
    if len(ups) > 0:
        print (len(ups))
        print ("User(s) with email {} already exists, aborting user creation!".
                format(email))
        return None

    username = new_user_name()
    user = User.objects.create_user(username, email = None, password = None)
    user.is_active = True
    user.is_staff = False
    user.is_superuser = False
    # The following fields are fields we store in the UserProfile object instead
    #   user.first_name
    #   user.last_name
    #   user.email
    user.save()

    up = UserProfile()
    up.user = user
    up.password_is_set = False
    up.magic_login_code = random.randint(100000000, 999999999)
    # If the user doesn't specify a name, email is used as the default
    if name is None:
        up.name = email
    else:
        up.name = name
    up.email = email
    up.phone = ''
    up.verification_code = new_phone_verification_number()
    up.is_verified = False
    up.state = 'CA'

    up.message_frequency = 3
    up.forecast_email = False
    up.set_equipment([])
    up.beta_test = True

    # In the future, we should separate phone-number, etc., into a separate model

    up.save()

    print ("User {} created.".format(email))
    return user
开发者ID:colinmccormick,项目名称:watttime,代码行数:47,代码来源:views.py

示例11: add_customer

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
def add_customer(request):
    form = RegistrationFormAdmin()
    if request.method == "POST":
        form = RegistrationFormAdmin(request.POST)
        if form.is_valid():
            username = generate_username(form.cleaned_data['first_name'],
                                         form.cleaned_data['last_name'],
            )
            random_password = get_pronounceable_password()
            user = User.objects.create_user(
                    username,
                    form.cleaned_data['email'],
                    random_password
            )
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.is_active = True
            user.save()

            userprofile = UserProfile()
            userprofile.title = form.cleaned_data['title']
            userprofile.date_of_birth = form.cleaned_data['date_of_birth']
            userprofile.phone = form.cleaned_data['phone']
            userprofile.terms = form.cleaned_data['terms']
            userprofile.user = user
            userprofile.save()

            address = Address()
            address.line_1 = form.cleaned_data['line_1']
            address.line_2 = form.cleaned_data['line_2']
            address.city = form.cleaned_data['city']
            address.county = form.cleaned_data['county']
            address.postcode = form.cleaned_data['postcode']
            address.user = user
            address.save()

            send_admin_welcome_email(user, random_password)
            return HttpResponseRedirect('/admin/accounts/userprofile/')

        else:
            form = RegistrationFormAdmin(request.POST)

    return render_to_response('admin/accounts/add_customer.html',
            {'form': form}, context_instance=RequestContext(request))
开发者ID:zatan,项目名称:pleasuresallmine,代码行数:46,代码来源:views.py

示例12: new_profile

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
def new_profile(request):

    if not request.user.is_superuser:
        return HttpResponseRedirect(reverse("member-list"))

    profile = UserProfile()
    profile.user = User()
    form_class = ProfileForm

    if request.method == "POST":
        form = form_class(data=request.POST, files=request.FILES, instance=profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(profile.user.get_absolute_url())
    else:
        form = form_class(instance=profile)

    return render_to_response(
        "profiles/edit_profile.html", {"form": form, "profile": profile}, context_instance=RequestContext(request)
    )
开发者ID:sigurdga,项目名称:nidarholm,代码行数:22,代码来源:views.py

示例13: process_request

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
 def process_request(self, request):
     if request.user.is_authenticated():
         return
     PartyHooks.execute_hook('user.prelogin', request=request)
     hostname = request.META['REMOTE_HOST'] or request.META['REMOTE_ADDR']
     try:
         # reverse the profile back to user based on hostname
         up = UserProfile.objects.get(hostname=hostname)
         user = up.user
         user.backend = 'django.contrib.auth.backends.ModelBackend'
         request.user = user
         auth.login(request, up.user)
         if request.path not in ['/favicon.ico'] and not settings.STATIC_URL in request.path:
             if up.departed:
                 up.departed = False
                 up.save()
                 PartyHooks.execute_hook('user.returns')
                 messages.success(request, "Welcome back to the LAN!")
     except UserProfile.DoesNotExist:
         # if we're the first user, we're always an admin
         first_admin = (User.objects.count() == 0)
         # add a new user
         random_password = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(12))
         username = request.META['REMOTE_HOST'] or 'User-'+''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(6))
         user = User.objects.create_user(username, None, random_password)
         user.save()
         profile = UserProfile()
         profile.user = user
         profile.hostname = hostname
         if first_admin:
             profile.set_flag(FLAG_ADMIN)
         profile.save()
         request.user = user
         user = auth.authenticate(username=username, password=random_password)
         auth.login(request, user)
         if first_admin:
             # redirect to admin panel for setup
             messages.success(request, "Welcome to pyParty!  As the first user, you're automatically an admin.  Please continue setting up pyParty as you normally would!")
             return HttpResponseRedirect('/admin/')
         else:
             messages.success(request, "Welcome to %s!  We set up an account for you.  There's no need for a password, you will be recognized by your computer.  Feel free to <a href='/accounts/profile/'>continue setting up your profile</a>." % get_setting('lan_name'))
开发者ID:JonnyFunFun,项目名称:pyParty,代码行数:43,代码来源:middleware.py

示例14: signup

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
def signup(request):
    if request.method == "POST":
        form = UserEmailCreationForm(request.POST)
        try:
            User.objects.get(email=request.POST['email'])
            return render(request, 'registration/signup.html', {
                'form': form,
                'error': "Already Exist Email address!"
            })
        except ObjectDoesNotExist:
            if form.is_valid():
                user = form.save()
                user_profile = UserProfile()
                user_profile.user = user
                user_profile.gender = request.POST['gender']
                user_profile.save()
                return redirect('login')
    else:
        form = UserEmailCreationForm()

    return render(request, 'registration/signup.html', {'form': form})
开发者ID:UrangUrang,项目名称:Guide,代码行数:23,代码来源:views.py

示例15: create

# 需要导入模块: from accounts.models import UserProfile [as 别名]
# 或者: from accounts.models.UserProfile import user [as 别名]
    def create(self, validated_data):
        datas = {}
        datas['username'] = validated_data['username']
        datas['email'] = validated_data['email']
        datas['password'] = validated_data['password']
        datas['first_name'] = validated_data['first_name']
        datas['last_name'] = validated_data['last_name']
        datas['password'] = validated_data['password']

        data = utils.generate_activation_key(datas['username'])     # user defined utility function.
        datas['activation_key'] = data
        datas['file_path'] = "accounts/activate/"
        datas['email_path'] = "/ActivationEmail.txt"
        datas['email_subject'] = "Activate Your domainname account."

        new_user = User.objects.create_user(
                username=datas['username'],
                email=datas['email'],
                password=datas['password'],
                first_name=datas['first_name'],
                last_name=datas['last_name'],
        )
        new_user.is_active = True
        new_user.save()
        user_profile = UserProfile()
        user_profile.user = new_user
        user_profile.activation_key = datas['activation_key']
        user_profile.is_active = False  # Will be true if email is verified.
        user_profile.save()
        utils.send_email(datas)
        # message = '''
        #             A Verification email has been sent to your email address.
        #             Please click the link in the email to verify your email address.
        #             '''
        # utils.display_html_message(message, 'success', request)
        return validated_data
开发者ID:adityamohta,项目名称:custom-registration,代码行数:38,代码来源:serializers.py


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