Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Django-unicorn? #299

Open
bschollnick opened this issue Dec 10, 2022 · 3 comments
Open

Add support for Django-unicorn? #299

bschollnick opened this issue Dec 10, 2022 · 3 comments

Comments

@bschollnick
Copy link

Folks,

is there someway to add compatibility with Django unicorn? Out of the box it's not working, and the closest I can come up with is an environment patch:

`
from django.templatetags.static import static
from django.urls import reverse
from django_icons.templatetags.icons import icon_tag
from jinja2 import Environment
from django_unicorn.templatetags.unicorn import unicorn_scripts, unicorn

def environment(**options):
env = Environment(**options)
env.globals.update({
'static': static,
'url': reverse,
'icon':icon_tag,
'unicorn':unicorn,
'unicorn_scripts':unicorn_scripts,
})
return env
`

But I'm having issues with unicorn requiring parameters to be passed? I'm talking with the Django-Unicorn folks, but I'm surprised this hasn't come up before... I suspect that since unicorn is suppose to be loaded that it's causing issues? But that's a guess...

@auvipy
Copy link
Collaborator

auvipy commented Dec 10, 2022

what does django unicorn do?

@bschollnick
Copy link
Author

Unicorn is a reactive component framework that progressively enhances a normal Django view, makes AJAX calls in the background, and dynamically updates the DOM. It seamlessly extends Django past its server-side framework roots without giving up all of its niceties or re-building your website.

I’d like to use it to replace my mishmash of AJAX calls…

I’ve located the template tag file, but it’s not behaving the way I would expect… The “unicorn” function is requiring parameters to be passed in.

The author states:

To answer your question, parser and token arguments are used for the unicorn function because it's a custom templatetag that jumps through a bunch of hoops to parse the args, kwargs, render the component (similar to how the include templatetag works if I remember correctly), etc. That all happens in render. For more details on how this works, check out Writing the compilation function in the docs.

I look forward to seeing if this is possible and what you come up with!

While helpful, to me it isn't, since I'm not sure where to investigate next? I can't figure out where the actual javascript is being added to the template, and so forth.

I'm really open to suggestions here, I've made some interesting (but mostly unrelated) discoveries in researching this. Including that I might be seriously unoptimized in my ajax routine... but that doesn't help here...

@wizpig64
Copy link
Collaborator

django-unicorn is an intriguing project. I haven't used it myself yet, but I've looked at the code a little bit. I think given that it uses TemplateResponse, there should be nothing stopping it from working. But the magic they're using has a lot of surface area, so i bet there will be a lot of pitfalls to pave over. For example, their unicorn_errors tag points to unicorn/errors.html, and you might have to that django template with a with a jinja version, and that might require a custom templatetag of its own.

If I had infinite time I'd build out a django-jinja-unicorn project myself just to figure this out, because learning django-unicorn would be cool. But for now, I'll say I'm open to reviewing pull requests.

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

No branches or pull requests

3 participants