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


Python UserProfile.getUser方法代码示例

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


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

示例1: poke

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
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,代码行数:33,代码来源:api_functions.py

示例2: unblockFriend

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
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,代码行数:28,代码来源:api_functions.py

示例3: inviteToStatus

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
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,代码行数:61,代码来源:api_functions.py

示例4: setGroupMembers

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
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,代码行数:57,代码来源:api_functions.py

示例5: suggestLocationTime

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
def suggestLocationTime(request):
    response = dict()

    userid = request.REQUEST['userid']
    statusid = request.REQUEST['statusid']
    suggestionType = request.REQUEST['type']
    location = request.REQUEST.get('location', None)
    time = request.REQUEST.get('time', None)

    if suggestionType != 'location' or suggestionType != 'time':
        return errorResponse('type must be location or time')

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

    try:
        cacheKey = Status.getCacheKey(statusid)
        status = Status.getStatus(statusid)
    except Status.DoesNotExist:
        return errorResponse('Invalid status id')

    if suggestionType == 'location':
        location = getLocationObjectFromJson(json.loads(location))
        locationSuggestion = LocationSuggestion.objects.get_or_create(user=userProfile, status=status,
                                                                      location=location)

    if suggestionType == 'time':
        date = datetime.strptime(time, DATETIME_FORMAT)
        timeSuggestion = TimeSuggestion.objects.get_or_create(user=userProfile, status=status, dateSuggested=time)

    response['success'] = True

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

示例6: cancelStatus

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
def cancelStatus(request):
    response = dict()

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

    try:
        userProfile = UserProfile.getUser(userid)
        cacheKey = Status.getCacheKey(statusid)
        status = cache.get(cacheKey)
        if status is None:
            status = Status.getStatus(statusid)
    except UserProfile.DoesNotExist:
        return errorResponse("Invalid user id")
    except Status.DoesNotExist:
        return errorResponse("Invalid statusid")

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

    now = datetime.utcnow()

    if status.expires > now:
        status.expires = now
        status.save()

    response['success'] = True

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

示例7: editGroupName

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
def editGroupName(request):
    response = dict()

    userid = request.REQUEST['userid']
    groupName = request.REQUEST['groupname']
    groupid = request.REQUEST['groupid']

    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("Group does not belong to user")

    group.name = groupName
    group.save()

    response['success'] = True

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

示例8: getNewData

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
def getNewData(request):
    response = dict()

    userid = request.REQUEST['userid']
    since = request.REQUEST.get('since', None)
    if since:
        since = datetime.strptime(since, MICROSECOND_DATETIME_FORMAT)

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

    newSince = datetime.now().strftime(MICROSECOND_DATETIME_FORMAT)

    pokes = getNewPokesData(userProfile, since)
    chats = getNewChatsData(userProfile, since)
    notifications = getNotificationsJson(userProfile, since)

    response['chats'] = chats
    response['newsince'] = newSince
    response['notifications'] = notifications
    response['success'] = True
    response['pokes'] = pokes

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

示例9: deleteStatus

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
def deleteStatus(request):
    response = dict()

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

    try:
        userProfile = UserProfile.getUser(userid)
        cacheKey = Status.getCacheKey(statusid)
        status = cache.get(cacheKey)
        if status is None:
            status = Status.getStatus(statusid)
    except UserProfile.DoesNotExist:
        return errorResponse("Invalid user id")
    except Status.DoesNotExist:
        return errorResponse("Invalid statusid")

    if status.user == userProfile:
        status.deleted = True
        status.save()
        response['success'] = True
        createDeleteStatusNotification(status)
        sendDeleteStatusNotfication(status)
    else:
        response['success'] = False
        response['error'] = "Can not delete another user's status"

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

示例10: sendStatusMessage

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
def sendStatusMessage(request):
    response = dict()

    text = request.REQUEST['text']
    userid = request.REQUEST['userid']
    statusid = request.REQUEST['statusid']
    lastMessageId = request.REQUEST.get('lastmessageid', None)

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

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

    message = StatusMessage.objects.create(user=userProfile, text=text, status=status)
    sendStatusMessageNotification(message)
    createCreateStatusMessageNotification(message)

    response['success'] = True
    response['messages'] = getNewStatusMessages(status, lastMessageId)

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

示例11: rsvpStatus

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
def rsvpStatus(request):
    response = dict()

    userId = request.REQUEST['userid']
    statusId = request.REQUEST['statusid']
    attending = request.REQUEST['attending']

    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 attending == 'true' or attending == 'True':
        status.attending.add(userProfile)
        createAttendingStatusNotification(status, userProfile)
        sendAttendingStatusPushNotification(status, userProfile)
    elif attending == 'false' or attending == 'False':
        status.attending.remove(userProfile)
    else:
        return errorResponse("Invalid Attending value. Must be true or false")

    response['success'] = True

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

示例12: registerForPushNotifications

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
def registerForPushNotifications(request):
    response = dict()

    userid = request.REQUEST['userid']
    token = request.REQUEST['token']
    platform = request.REQUEST['platform']

    try:
        userProfile = UserProfile.getUser(userid)
    except UserProfile.DoesNotExist:
        return errorResponse("User does not exist")

    if platform == 'ios':
        try:
            device = APNSDevice.objects.get(registration_id=token)
            device.user = userProfile
            device.save()
        except APNSDevice.DoesNotExist:
            device = APNSDevice.objects.create(user=userProfile, registration_id=token)
    elif platform == 'android':
        try:
            device = GCMDevice.objects.get(registration_id=token)
            device.user = userProfile
            device.save()
        except GCMDevice.DoesNotExist:
            device = GCMDevice.objects.create(user=userProfile, registration_id=token)
    else:
        return errorResponse("platform must be ios or android")

    response['success'] = True

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

示例13: setSetting

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
def setSetting(request):
    response = dict()

    userid = request.REQUEST['userid']
    key = request.REQUEST['key']
    value = request.REQUEST['value']

    if key != 'statusradius' and key != 'imboredtext':
        return errorResponse("unknown key. Must be statusradius or imboredtext")

    try:
        userProfile = UserProfile.getUser(userid)
    except UserProfile.DoesNotExist:
        return errorResponse("User does not exist")

    try:
        setting = userProfile.settings.get(key=key)
        setting.value = value
        setting.save()
    except Setting.DoesNotExist:
        Setting.objects.create(user=userProfile, value=value, key=key)

    response['success'] = True

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

示例14: getUserDetails

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
def getUserDetails(request):
    response = dict()

    userid = request.REQUEST.get('userid', None)
    userids = request.REQUEST.get('userids', '[]')
    userids = json.loads(userids)

    if userid is None and len(userids) == 0:
        return errorResponse("Need to supply userid or userids")

    users = list()

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

        response['firstname'] = userProfile.user.first_name
        response['lastname'] = userProfile.user.last_name
        response['facebookid'] = userProfile.facebookUID
        response['userid'] = userProfile.id

    elif len(userids) > 0:
        for userid in userids:
            try:
                userProfile = UserProfile.getUser(userid)
            except UserProfile.DoesNotExist:
                return errorResponse("Invalid user id")

            userData = dict()
            userData['firstname'] = userProfile.user.first_name
            userData['lastname'] = userProfile.user.last_name
            userData['facebookid'] = userProfile.facebookUID
            userData['userid'] = userProfile.id

            users.append(userData)

        response['users'] = users

    response['success'] = True
    return HttpResponse(json.dumps(response))
开发者ID:gmuresan,项目名称:buddyup-django-server,代码行数:44,代码来源:api_functions.py

示例15: removeGroupMember

# 需要导入模块: from userprofile.models import UserProfile [as 别名]
# 或者: from userprofile.models.UserProfile import getUser [as 别名]
def removeGroupMember(request):
    response = dict()

    userid = request.REQUEST['userid']
    friendid = str(request.REQUEST['friendid'])
    groupid = request.REQUEST['groupid']

    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("Group does not belong to user")

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

    response['success'] = True

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


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