Example #1
0
def outbox(request, username):
    user = get_object_or_404(User, username=username)

    if request.method == "GET":
        objects = user.activities.filter(remote=False).order_by("-created_at")
        collection = acts.OrderedCollection(objects)
        return JsonResponse(collection.to_json())

    payload = request.body.decode("utf-8")
    activity = json.loads(payload, object_hook=acts.as_activitystream)

    if activity.type == "Entry":
        obj = activity
        activity = acts.Create(to=user.uris.followers, actor=user.uris.id, object=obj)

    activity.validate()

    if activity.type == "Create":
        if activity.object.type != "Entry":
            raise Exception("Sorry, you can only create Entry objects")

        # activity.object.id = note.uris.id
        activity.id = store(activity, user)
        deliver(activity)
        return HttpResponse(status=202)

    if activity.type == "Follow":
        return outbox_follow(activity, user)

    raise Exception("Invalid Request")
Example #2
0
def inbox(request, username):
    user = get_object_or_404(User, username=username)
    if request.method == "GET":
        objects = user.activities.filter(remote=True).order_by("-created_at")
        collection = acts.OrderedCollection(objects)
        return JsonResponse(collection.to_json())

    payload = request.body.decode("utf-8")
    activity = json.loads(payload, object_hook=acts.as_activitystream)
    activity.validate()

    if activity.type == "Create":
        handle_entry(activity)
    elif activity.type == "Follow":
        handle_follow(activity)

    store(activity, user, remote=True)
    return HttpResponse()
Example #3
0
def get_following(request, username):
    user = get_object_or_404(User, username=username)
    following = acts.OrderedCollection(user.following.all())
    return JsonResponse(following.to_json())
Example #4
0
def get_entries(request, username):
    user = get_object_or_404(User, username=username)
    recipes = user.cookbook.recipes.through.objects.filter(cookbook=user.cookbook)
    recipes_as = [recipe.to_activitystream() for recipe in recipes]
    collection = acts.OrderedCollection(recipes_as)
    return JsonResponse(collection.to_json())