Skip to content

Conversation

@saevarom
Copy link

I have been experimenting with a headless setup and the dynamic Userbar. What I found lacking is the option to edit a page from the Userbar. This PR along with an edit to the feature in the headless branch of bakerydemo will accomplish that.

The changes needed in the backend to accomplish these changes are:

class UserbarView(TemplateView):
    template_name = Userbar.template_name
    http_method_names = ["get"]

    def dispatch(self, request, *args, **kwargs):
        response = super().dispatch(request, *args, **kwargs)
        client_url = headless_preview_settings.CLIENT_URLS["default"]
        response["Access-Control-Allow-Origin"] = client_url
        return response

    def get_context_data(self, **kwargs):
+        object = None
+        page_id = self.request.GET.get('page_id', None)
+        if page_id:
+            object = Page.objects.filter(id=page_id).first()

-        return Userbar(object=None, position="bottom-left").get_context_data(
+        return Userbar(object=object, position="bottom-left").get_context_data(
            super().get_context_data(request=self.request, **kwargs)
        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant