Comments (10)
Just a question -- why?
from django-ordered-model.
Because GET requests should not, by definition, change state.
from django-ordered-model.
The keyword to search for is CSRF.
from django-ordered-model.
Fair enough -- so does anyone plan to give the author a pull req?
from django-ordered-model.
There are a few practical problems:
- Method
move_up_down_links
doesn't have access torequest
directly, so it can't generate a csrf tokens. - Forms cannot be nested, so the
POST
request has to be generated with javascript instead, which means it won't work without javascript. - Requiring
POST
would break functionality for anyone who used a custom template, probably without visible error.
I still think it's important though, it's not secure now, one can easily manipulate order through a simple CSRF url posted somewhere.
from django-ordered-model.
I think this was fixed?
from django-ordered-model.
Oh, not yet.
from django-ordered-model.
Might be possible to make the up/down links all submit the main form (rather than a nested form, or random get request) with different actions for each button. Would allow dropping all the custom url generation as it would all go via. the existing page change handler, with some magic in the Form generation to recover the action and emit an event or similar to update the model. I'm not nearly enough of a django hacker to get it working though.
from django-ordered-model.
I've been looking at what django-mptt
does (they have a drag-drop re-ordering form widget) and it is quite similar to what I suggested. They use the admin jQuery integration to fire a POST request back to the original page form handler, which they intercept in the changelist_view(self, request)
hook.
https://github.com/django-mptt/django-mptt/blob/master/mptt/admin.py#L147
Client-side, the result from the Ajax call is ignored, and jQuery simply reloads the current page to show the new ordering:
https://github.com/django-mptt/django-mptt/blob/master/mptt/static/mptt/draggable-admin.js#L223
This seems a neat solution. We would need to add inheritance to any changelist page that includes an OrderedTabularInline (replacing the url extending code we have at the moment).
from django-ordered-model.
@shuckc I take it you mean this? https://caniuse.com/#feat=form-submit-attributes
Because as far as I see it, there is no need to do away with the existing move_view
or any jQuery shenanigans - it should be sufficient to change order_controls.html
to use buttons with the formaction
attribute for it to work.
Of course, it would be nice if the move_view
were also be changed to validate that it is used with POST or PUT.
I'm prepared to do this if it's considered a worthwhile change.
from django-ordered-model.
Related Issues (20)
- foo.up(count=1) or foo.down(count=1) HOT 1
- Admin interface `move-up` action sometimes skips numbers HOT 9
- Django `ManyToMany` fields dont order results by through model's `Model.Meta.ordering` HOT 14
- Increase in queries number HOT 6
- 3.7.x causes error on Django startup HOT 4
- Additional checks for Admin
- If order_with_respect_to is a foreign key of a foreign key it generates aditional queries. HOT 4
- OrderWithRespectToTestsManyToMany.test_down defined twice HOT 1
- Upgrading from 3.6 to 3.7.x greatly decreased performance or raising a RecursionError in some situations HOT 3
- order_with_respect_to with non-foreign keys HOT 16
- Generalize `order_with_respect_to` beyond FK fields HOT 3
- Out-of-order deletion produces duplicate ordering
- (ordered_model.E001) OrderedModelBase subclass needs Meta.ordering specified check is required as an Error? HOT 1
- Add time complexity information to docs HOT 3
- `OrderedManyToMany` does not respect Django query cache HOT 3
- Order With Respect To with Non Foreign Key Fields HOT 1
- `post_delete` signal called for both parent and child models, causing orders to be incorrect HOT 2
- Ordering with Floats HOT 2
- [QUESTION] New release of 3.7.5 or 3.8 at PyPI HOT 1
- order_with_respect_to with non-foreign keys HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-ordered-model.