def activitypub_object_view(func):
def inner(request, *args, **kwargs):<EOL><INDENT>def get(request, *args, **kwargs):<EOL><INDENT>config = get_configuration()<EOL>if not config.get("<STR_LIT>"):<EOL><INDENT>return func(request, *args, **kwargs)<EOL><DEDENT>fallback = True<EOL>accept = request.META.get('<STR_LIT>', '<STR_LIT>')<EOL>for content_type in (<EOL>'<STR_LIT:application/json>', '<STR_LIT>', '<STR_LIT>',<EOL>):<EOL><INDENT>if accept.find(content_type) > -<NUM_LIT:1>:<EOL><INDENT>fallback = False<EOL>break<EOL><DEDENT><DEDENT>if fallback:<EOL><INDENT>return func(request, *args, **kwargs)<EOL><DEDENT>get_object_function = get_function_from_config('<STR_LIT>')<EOL>obj = get_object_function(request)<EOL>if not obj:<EOL><INDENT>return HttpResponseNotFound()<EOL><DEDENT>as2_obj = obj.as_protocol('<STR_LIT>')<EOL>return JsonResponse(as2_obj.to_as2(), content_type='<STR_LIT>')<EOL><DEDENT>def post(request, *args, **kwargs):<EOL><INDENT>process_payload_function = get_function_from_config('<STR_LIT>')<EOL>result = process_payload_function(request)<EOL>if result:<EOL><INDENT>return JsonResponse({}, content_type='<STR_LIT:application/json>', status=<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>return JsonResponse({"<STR_LIT:result>": "<STR_LIT:error>"}, content_type='<STR_LIT:application/json>', status=<NUM_LIT>)<EOL><DEDENT><DEDENT>if request.method == '<STR_LIT:GET>':<EOL><INDENT>return get(request, *args, **kwargs)<EOL><DEDENT>elif request.method == '<STR_LIT:POST>' and request.path.endswith('<STR_LIT>'):<EOL><INDENT>return post(request, *args, **kwargs)<EOL><DEDENT>return HttpResponse(status=<NUM_LIT>)<EOL><DEDENT>return inner<EOL>
Generic ActivityPub object view decorator.

Takes an ID and fetches it using the provided function. Renders the ActivityPub object
in JSON if the object is found. Falls back to decorated view, if the content
type doesn't match.