adamghill / django-unicorn Goto Github PK
View Code? Open in Web Editor NEWThe magical reactive component framework for Django ✨
Home Page: https://www.django-unicorn.com
License: MIT License
The magical reactive component framework for Django ✨
Home Page: https://www.django-unicorn.com
License: MIT License
How can I help? I’m a web designer/developer (HTML + CSS) and haven’t taken the leap into the front-end frameworks.
I like the idea of components but all of the overhead in the front-end frameworks is overwhelmingly complex and changes far too often to keep up with a small team.
We have a couple of projects which use Django with templates.
This project looks like something we would be interested in.
How can we help?
CSRF token is missing. Do you need to add {% csrf_token %}?
Strings and booleans get cast as expected, but it'd be nice to have a mechanism to cast to a particular type inside the component. The canonical example would be a datetime
coming from a HTML input and getting parsed to be a
datetime` object inside the component.
Either a property array, dictionary or object. Probably should use dot notation to access.
e.g. <input type="text" unicorn:model="blog.author.name">
you can define:
# settings.py
UNICORN_COMPONENTS_PREFIX = [
'myapp.views','unicorn.components',
]
The locations where the UnicornCompornent will import.
Potentially use https://github.com/avajs/ava?
If {% csrf_token %}
is on the page after {% unicorn_scripts %}
nothing works.
Not sure if it is possible yet but the ability to upvote on multiple tabs/browsers and chat.
To prevent flicker only show/remove unicorn:loading
when the action takes longer than 200ms.
Hi. I've created an empty django project to test unicorn. But somehow the default instructions don't seem to work and cause a template not found error. Here's what I've done:
After this last step 9 it starts to break and throws a TemplateDoesNotExist error:
django.template.loaders.filesystem.Loader: /home/user/uniplayground/templates/unicorn/hello-world.html (Source does not exist)
In my project folder the hello-world.html file generated by step 8 is located under:
/home/user/uniplayground/unicorn/templates/unicorn/hello-world.html
Am I doing something wrong or does the startunicorn command not generate the files into the right structure?
Edit: Moving the HTML file to the template folder that django is looking in seems to work. While leaving the python file in the generated folder structure.
Instead of having to create set_name()
methods, support something like name='World'
.
Similar to https://laravel-livewire.com/screencasts/actions.
HI Adam!
It would be useful to be able to update the unicorn component class variables from another Django app.
You mentioned an API call or database hookup on the page refresh.
How would this be done?
Would this also be possible via AJAX or a Javascript hook?
Thanks!
Ashirvad
Once Django 3.1 and async views are available, see how hard it would be to use an async view if configured.
For example:
<input unicorn:keyup.enter="add" unicorn:keyup.escape="clear"></input>
When using a Django model as a property, if a field is updated as part of unicorn:model
, the model will not get reset as expected.
class HelloWorldView(UnicornView):
book = Book(title="The Sandman")
<input unicorn:model="book.title" type="text" id="bookId">
Maybe there is a way to reuse a class-based view instead of the custom Component
does now.
Instead of only looking in the unicorn
app, be able to set an array of apps to check for components.
Add support for unicorn:model.lazy
to change the event listener to be blur
instead of input
.
The Component class generates a checksum based on the attribute names which could be used to verify that the component gets updated in the message
view code.
It would be useful to handle the special action argument $model
being passed into an action. Probably only useful for db models since normal models can just do self.whatever
in the component view code.
<div>
{% for book in books %}
<div u:db="book" u:pk="{{ book.id }}">
<button u:click="delete($model)`>
<!-- <button u:click="delete({{ book.id }})`> -->
</div>
{% endfor %}
</div>
from django_unicorn.components import UnicornView
from books.models import Book
class DbModelView(UnicornView):
# magically instantiate the appropriate book instance object here based on model class and pk
def delete(book):
book.delete()
# normal way call action with a model requires passing around an id/pk/slug and looking it up
# def delete(book_id):
# book = Book.objects.get(id=book_id)
# book.delete()
class Meta:
db_models = [DbModel("book", Book)]
https://github.com/pyparsing/pyparsing might be saner than the string parsing done in https://github.com/adamghill/django-unicorn/blob/master/django_unicorn/call_method_parser.py.
Being able to send arguments from the parent django template to the unicorn view.
To be able to do something like :
class TestView(UnicornView):
name = "hello-world"
def __init__(self, var):
self.var = var
def set_var(self, var):
self.var = var
{% unicorn 'hello-world' with var=var %} (django {% include %} like )
Or to be able to send arguments to Unicorn.call :
{% unicorn 'hello-world' %}
<button onclick="Unicorn.call('hello-world', 'set_var', 'var_value');">Set the name from outside the component</button>
Even if it's just sending a one-shot primitives it will be very helpful to give some context to the unicorn view.
I was not seeing this on local dev with 0.6.0, but it happens when deployed. I am now able to replicate it on local by throttling network responses.
I think I need to merge the syncInput and callMethod actions that fire "at the same time" into the payload array so that the syncInput doesn't get lost.
hello Adam, long time no talk!
I was trying out the demo on the website and something BitWarden is doing to the input box, I think added it's own attribute to the html, causes the input to be redrawn empty but if you click the button add it will still load something but not everything.
Video:
django-unicorn-glitch.mov.zip
If I disable BitWarden and reload the page, the interaction works fine.
Add support for something like unicorn:model.debounce.1000ms
to set debounce timeout.
Ideally these types would be supported passed into a method call: string, int, decimal, uuid, datetime, dict, list, tuple, set.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.