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


Python models.UserProfile类代码示例

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


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

示例1: save

 def save(self, commit=True):
     if not commit:
         raise NotImplementedError("Can't create User and UserProfile without database save")
     user = super(UserCreateForm, self).save(commit=True)
     user_profile = UserProfile(user=user, first_name=self.cleaned_data['first_name'], second_name = self.cleaned_data['second_name'], status=True, latitude = self.cleaned_data['latitude'], longitude = self.cleaned_data['longitude'], timestamp=datetime.datetime.now())
     user_profile.save()
     return user, user_profile
开发者ID:suchareek,项目名称:wlasny,代码行数:7,代码来源:forms.py

示例2: poke

def poke(request):
    response = dict()

    userid = request.REQUEST['userid']
    friendid = request.REQUEST['friendid']
    lastHour = datetime.utcnow().replace(tzinfo=pytz.utc) - timedelta(hours=1)

    try:
        user = UserProfile.getUser(userid)
    except UserProfile.DoesNotExist:
        return errorResponse("Invalid user id")

    try:
        targetUser = UserProfile.getUser(friendid)
    except UserProfile.DoesNotExist:
        return errorResponse("Invalid target user id")

    if targetUser not in user.friends.all():
        return errorResponse("User is not your friend")

    poke = Poke.objects.filter(sender=user, recipient=targetUser, created__gt=lastHour)

    if poke:
        return errorResponse("Already poked user in the last hour")
    poke = Poke.objects.create(sender=user, recipient=targetUser)

    # sendPokeNotification(poke)

    response['success'] = True

    return HttpResponse(json.dumps(response))
开发者ID:gmuresan,项目名称:buddyup-django-server,代码行数:31,代码来源:api_functions.py

示例3: save

 def save(self, profile_callback = None):
     """
     Create the new ``User`` and ``RegistrationProfile``, and
     returns the ``User``.
     
     This is essentially a light wrapper around
     ``RegistrationProfile.objects.create_inactive_user()``,
     feeding it the form data and a profile callback (see the
     documentation on ``create_inactive_user()`` for details) if
     supplied.
     
     """
     new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
                                                                 sex=self.cleaned_data['sex'],
                                                                 age=self.cleaned_data['age'],                                                                    
                                                                 origin=self.cleaned_data['origin'],
                                                                 ethnicity=self.cleaned_data['ethnicity'],
                                                                 disadvantaged=self.cleaned_data['disadvantaged'],
                                                                 employment_location=self.cleaned_data['employment_location'],
                                                                 position=self.cleaned_data['position'],
                                                                 password=self.cleaned_data['password1'],
                                                                 email=self.cleaned_data['email'],
                                                                 profile_callback=profile_callback)
     
     # Extending the user model with UserProfile
     new_profile = UserProfile(user = new_user, 
                               sex=self.cleaned_data['sex'],
                               age=self.cleaned_data['age'],
                               origin=self.cleaned_data['origin'],
                               ethnicity=self.cleaned_data['ethnicity'],
                               disadvantaged=self.cleaned_data['disadvantaged'],
                               employment_location=self.cleaned_data['employment_location'],
                               position=self.cleaned_data['position'])
     new_profile.save()
     return new_user
开发者ID:djredhand,项目名称:phtc,代码行数:35,代码来源:forms.py

示例4: user_registration

def user_registration(request):
    if request.user.is_authenticated():
        return redirect('/')

    form = RegisterForm(request.POST or None)

    if form.is_valid():
        user = form.save()
        user.set_password(user.password)
        user.save()
        profile = UserProfile()
        profile.user = user
        profile.save()
        send_mail(
            'Welcome to ' + DOMAIN + '!',
            'Someone try register on site ' + DOMAIN +
            '. To confirm registration visit this link ' + confirmation_link +
            '. If you aren\'t try to register than  just ignore this email.	''',
            '[email protected]',
            ['[email protected]'],
            fail_silently=False)
        return redirect('/')

    context = RequestContext(request)
    return render_to_response('userprofile/registration.html',
                              {'form': form}, context)
开发者ID:chizel,项目名称:os_dj,代码行数:26,代码来源:views.py

示例5: edit_profile

def edit_profile(request):
    context = RequestContext(request)

    try:
        user_profile = UserProfile.objects.get(user=request.user)
    except UserProfile.DoesNotExist:
        user_profile = UserProfile(user=request.user)

    if request.method == 'POST':
        edit_form = ProfileForm(request.POST)
        if edit_form.is_valid():
            data = edit_form.cleaned_data

            user_profile.full_name = data['full_name']
            user_profile.bio = data['bio']
            user_profile.save()

            return HttpResponseRedirect(
                reverse('userprofile.views.profile',
                        args=(),
                        kwargs={'username': request.user.username}))
        else:
            print edit_form.errors
    else:
        edit_form = ProfileForm({
            'full_name': user_profile.full_name,
            'bio': user_profile.bio
        })

    context_dict = {
        'edit_form': edit_form
    }

    return render_to_response('userprofile/edit.html', context_dict, context)
开发者ID:jatinshah,项目名称:alphatracker,代码行数:34,代码来源:views.py

示例6: savetrainers

def savetrainers():
    with open("sisteme_eklenecek_egitmenler.csv") as e:
        egitmenler = e.readlines()
        for egit in egitmenler:
            print egit
            cols=egit.split('|')
            try:
                egitu = User(first_name=cols[0],last_name=cols[1],email=cols[4].rstrip(),username=cols[4].rstrip())
                egitu.set_password = '123456'
                egitu.save()
                egitup = UserProfile(user=egitu,
                                     organization=cols[2],
                                     tckimlikno='',
                                     ykimlikno='',
                                     gender='',
                                     mobilephonenumber='',
                                     address='',
                                     job='',
                                     city='',
                                     title='',
                                     university='',
                                     department='',
                                     country=cols[3],
                                     is_instructor=True) 
                egitup.save()
                print "olustu"
                print cols[4].rstrip()
            except:
                print "olusmadi"
                print cols[4].rstrip()
开发者ID:bluevoda,项目名称:ab-kurs-kayit,代码行数:30,代码来源:modelops.py

示例7: create

    def create(self, validated_data):
        user_dict = validated_data['user']
        tag_dict = validated_data['tag']

        first_in_required = [ f for f in self._required if f in user_dict ][0]
        user = {
            'id': lambda: UserProfile.objects.get(user__id=user_dict['id']),
            'student_id': lambda: UserProfile.get_by_student_id(user_dict['student_id']),
            'username': lambda: UserProfile.objects.get(user__username=user_dict['username']),
            'email': lambda: UserProfile.get_by_email(user_dict['email']),
        }[first_in_required]()
        tag = UserTag.objects.get(
            slug=tag_dict['slug'],
            course_instance=self.context['course_id']
        )

        obj, created = UserTagging.objects.set(user, tag)
        if not created:
            raise serializers.ValidationError(
                'User {user} already has tag {slug}'.format(
                    user=user.user.username,
                    slug=tag.slug,
                )
            )
        return obj
开发者ID:Aalto-LeTech,项目名称:a-plus,代码行数:25,代码来源:full_serializers.py

示例8: unblockFriend

def unblockFriend(request):
    response = dict()

    userid = request.REQUEST['userid']
    friendid = request.REQUEST['friendid']

    try:
        userProfile = UserProfile.getUser(userid)
    except UserProfile.DoesNotExist:
        return errorResponse("Invalid user id")

    try:
        friendProfile = UserProfile.getUser(friendid)
    except UserProfile.DoesNotExist:
        return errorResponse("Invalid friend id")

    if friendProfile not in userProfile.friends.all():
        return errorResponse("Target is not your friend")

    if friendProfile in userProfile.blockedFriends.all():
        userProfile.blockedFriends.remove(friendProfile)
        userProfile.save()

    response['success'] = True

    return HttpResponse(json.dumps(response))
开发者ID:gmuresan,项目名称:buddyup-django-server,代码行数:26,代码来源:api_functions.py

示例9: inviteToStatus

def inviteToStatus(request):
    response = dict()
    userid = request.REQUEST['userid']
    statusId = request.REQUEST['statusid']
    friends = request.REQUEST.get('friends', '[]')

    friends = json.loads(friends)

    try:
        userProfile = UserProfile.getUser(userid)
    except UserProfile.DoesNotExist:
        return errorResponse('Invalid User')

    try:
        status = Status.getStatus(statusId)
    except Status.DoesNotExist:
        return errorResponse('Invalid Status')

    # if status.user != userProfile:
    #     if status.visibility == Status.VIS_FRIENDS or status.visibility == Status.VIS_CUSTOM:
    #         return errorResponse("Cant invite people to private events")

    buddyupFriends = list()
    facebookFriends = list()
    for friendId in friends:
        friendId = str(friendId)
        if friendId[:2] == 'fb':
            friendId = friendId[2:]

            try:
                friend = UserProfile.objects.get(facebookUID=friendId)
                if friend != status.user and friend not in status.attending.all():
                    buddyupFriends.append(friend)
            except UserProfile.DoesNotExist:
                try:
                    fbFriend = FacebookUser.objects.get(facebookUID=friendId)
                except FacebookUser.DoesNotExist:
                    fbFriend = FacebookUser.objects.create(facebookUID=friendId)
                facebookFriends.append(fbFriend)

        else:
            try:
                friend = UserProfile.getUser(friendId)
                if friend != status.user and friend not in status.attending.all():
                    buddyupFriends.append(friend)

            except UserProfile.DoesNotExist:
                pass

    status.invited.add(*buddyupFriends)
    status.fbInvited.add(*facebookFriends)

    createInvitedToStatusNotification(buddyupFriends, userProfile, status)

    sendInvitedToStatusNotification(status, userProfile, buddyupFriends)

    response['success'] = True

    return HttpResponse(json.dumps(response))
开发者ID:gmuresan,项目名称:buddyup-django-server,代码行数:59,代码来源:api_functions.py

示例10: createTestUser

def createTestUser(request):
    numberOfFriends = request.REQUEST['numfriends']
    response = dict()

    name = "test%d" % random.randint(1, 10000000)
    email = "%[email protected]" % name
    firstName = name
    lastName = name
    user = User(username=email, email=email, first_name=firstName,
                last_name=lastName, password=0)

    user.save()
    userProfile = UserProfile(user=user, device='ios')
    userProfile.save()

    numberOfFriends = int(numberOfFriends)
    friends = UserProfile.objects.all().order_by('-id')[:numberOfFriends]

    blockedFriends = userProfile.blockedFriends.all()
    for friend in friends:
        if friend not in friend.friends.all():
            friend.friends.add(userProfile)
            userProfile.friends.add(friend)

    friends = userProfile.friends.all()
    response['friends'] = list()
    for friend in friends:
        friendData = getUserProfileDetailsJson(friend)
        response['friends'].append(friendData)

    statusesResponse, newSince = getNewStatusesJsonResponse(userProfile, None, None, None)
    myStatusesResponse = getMyStatusesJsonResponse(userProfile)
    groupsData = getMyGroupsJsonResponse(userProfile)

    buddyupSettings = getSettingsData(userProfile)

    newSince = datetime.now().strftime(MICROSECOND_DATETIME_FORMAT)
    notifications = getNotificationsJson(userProfile)
    chatData = getNewChatsData(userProfile)

    response['success'] = True
    response['firstname'] = userProfile.user.first_name
    response['lastname'] = userProfile.user.last_name
    response['userid'] = userProfile.id
    response['facebookid'] = userProfile.facebookUID
    response['statuses'] = statusesResponse
    response['groups'] = groupsData
    response['mystatuses'] = myStatusesResponse
    response['chats'] = chatData
    response['newsince'] = newSince
    response['settings'] = buddyupSettings
    response['notifications'] = notifications
    response['favoritesnotifications'] = userProfile.favoritesNotifications

    return HttpResponse(json.dumps(response))
开发者ID:gmuresan,项目名称:buddyup-django-server,代码行数:55,代码来源:api_functions.py

示例11: setGroupMembers

def setGroupMembers(request):
    response = dict()

    userid = request.REQUEST['userid']
    groupid = request.REQUEST['groupid']
    friendids = request.REQUEST.get('friendids', [])
    friendids = json.loads(friendids)

    try:
        userProfile = UserProfile.getUser(userid)
    except UserProfile.DoesNotExist:
        return errorResponse("Invalid user id")

    try:
        group = Group.objects.get(pk=groupid)
    except Group.DoesNotExist:
        return errorResponse("Invalid group id")

    if group.user != userProfile:
        return errorResponse("User does not own that group")

    userFriends = userProfile.friends.all()
    group.members.clear()
    group.fbMembers.clear()

    for friendid in friendids:
        friendid = str(friendid)
        if friendid[:2] == 'fb':
            friendid = friendid[2:]
            if friendid:
                try:
                    friendProfile = UserProfile.objects.get(facebookUID=friendid)
                    group.members.add(friendProfile)
                except UserProfile.DoesNotExist:
                    try:
                        facebookUser = FacebookUser.objects.get(facebookUID=friendid)
                    except FacebookUser.DoesNotExist:
                        facebookUser = FacebookUser.objects.create(facebookUID=friendid)
                    group.fbMembers.add(facebookUser)
        else:
            try:
                friend = UserProfile.getUser(friendid)
            except User.DoesNotExist:
                return errorResponse("Friend does not exist")

            if friend not in userFriends:
                return errorResponse("User is not a friend")

            group.members.add(friend)

    group.save()

    response['success'] = True

    return HttpResponse(json.dumps(response))
开发者ID:gmuresan,项目名称:buddyup-django-server,代码行数:55,代码来源:api_functions.py

示例12: register

def register(request):
    if request.method == 'POST':
        form = NewUserForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            userprofile = UserProfile(user=new_user, steamURL=form.cleaned_data["steamURL"])
            userprofile.save()
            return HttpResponseRedirect("/inventory")
    else:
        form = NewUserForm()
    return render(request, "registration/register.html", {
        'form': form,
    })
开发者ID:carlinhus,项目名称:steam-api,代码行数:13,代码来源:views.py

示例13: save

 def save(self, commit=True):
     if not commit:
         raise NotImplementedError("Can't create User and UserProfile without database save")
     user = super(UserCreateForm, self).save(commit=True)
     user_profile = UserProfile(
         user = user,
         latitude = self.cleaned_data['latitude'],
         longitude = self.cleaned_data['longitude'],
         points = 0,
         rank_points = 0,
         avatar = self.cleaned_data['avatar'])
     user_profile.save()
     return user, user_profile
开发者ID:ibiss,项目名称:breaking,代码行数:13,代码来源:forms.py

示例14: post

 def post(self, request, *args, **kwargs):
     form = RegistrationForm(request.POST)
     if form.is_valid():
         user = User.objects.create_user(
             username=form.cleaned_data['username'],
             email=form.cleaned_data['email'],
             password=form.cleaned_data['password'],
             first_name=form.cleaned_data['first_name'],
             last_name=form.cleaned_data['last_name'])
         user.save()
         userprofile = UserProfile(user=user, organizacion=request.user.get_profile().organizacion)
         userprofile.save()
         return HttpResponseRedirect('/accounts/register_success/')
     else:
         return render_to_response('register.html', {'form': form}, context_instance=RequestContext(request))
开发者ID:hnejadi,项目名称:shoppingplanner,代码行数:15,代码来源:views.py

示例15: createInst

	def createInst(self,postrequest,numofinst):
		insts=[]
		uprof=UserProfileOPS()
		for i in xrange(numofinst):
			n_str=str(i)+'-'
			upass=uprof.generatenewpass() # uretilen parola olusturulan kullaniciya gonderilecek.
			inst=User(first_name=postrequest[n_str+'first_name'],last_name=postrequest[n_str+'last_name'],
						email=postrequest[n_str+'email'],username=postrequest[n_str+'email'],password=upass)
			inst.save()
			instprof=UserProfile(job=postrequest[n_str+'job'],title=postrequest[n_str+'title'],
                        organization=postrequest[n_str+'organization'],is_instructor=True,
						user=inst)
			instprof.save()
			insts.append(instprof)
		return insts
开发者ID:unicod3,项目名称:ab-kurs-kayit,代码行数:15,代码来源:coursesubops.py


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