biocompute-objects / portal_userdb

1 stars 1 forks source link

Create redirects for objects #349

Open kee007ney opened 6 months ago

kee007ney commented 6 months ago

When someone copies their BCO ID and attempts to share it, they're taken to a Django page, which isn't what most people want. A redirect should be set up so that people can go to the object (e.g. builder for drafts and viewer for published).

So for example if someone shares: https://biocomputeobject.org/HIVE_000002/DRAFT and you click on it, you're taken to: https://biocomputeobject.org/builder?https%3A%2F%2Fbiocomputeobject.org%2FHIVE_000002%2FDRAFT=

HadleyKing commented 6 months ago

from django.http import JsonResponse, HttpResponseRedirect

def my_view(request):
    # Check if the request accepts JSON or if the format is explicitly requested as JSON
    if 'application/json' in request.headers.get('Accept', '') or request.GET.get('format') == 'json':
        data = {'key': 'value'}  # Your JSON data here
        return JsonResponse(data)
    else:
        # Redirect to the external React frontend
        return HttpResponseRedirect('https://your-react-frontend.com')```