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))
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))
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))