Use a link as a form field without javascript - django

i'm almost done developing a search engine in django 1.3. I'm having some filters on the left side of my application.
What i want to do is display those filters as links (not as radiobuttons /selectbox /checkbox) and whenever a user clicks on one of those links, the form is resubmitted with that filter's value submitted (maybe grabbed by a TextInput widget)
Basically, something like the left side filtering in this example from Google, but without javascript (so even a "non js user" can use my website)
Is it possible? How? Or am i bound to javascripts for this purpose?
Thanks all in advance!

Why not simply use GET query parameters?
Imagine the following:
User searches for "bear", the URL becomes: /search/?q=bear
The query parameters are handled by your view (collect all images corresponding to the query parameters)
The query parameters are sent back to the template in a variable;
Each filter link has the query parameters attached to it together with its own specific parameters, so that the filter link for e.g. medium-sized images becomes /search/?q=bear&size=medium;
Upon clicking that filter link, your view will get a q and an size key in its request.GET dictionary;
Repeat ad infinitum (e.g. /search/?q=bear&size=medium&expression=smiling&color=b-w&activity=dancing).

Related

Django multi-select widget. Add arbitrary select components

i would like to make a widget that lets the user select a value from a drop-down list and then add new drop-down lists with values filtered based on the previous selections. I don't know where to start from....
If the amount of drop-downs is finite and determinable by the time you develop the software (e.g. selecting country->city->street) I would suggest to:
add all the extra dropdowns (without data yet) to your form, make sure they are hidden
use jqueryui to un-hide and populate the dropdowns as needed using ajax
Don't forget to disable/hide the whole form by default and only show it if JS is enabled in browser.
Also, you will of course need another view, with which only ajax speaks.
Here for you to catch the idea how the stuff should work. Sorry don't know if they have anything more similar. But: user selects something -> jquery requests data for the next dropdown -> jquery displays next populated dropdown.

go to the most recent state on clicking the back button

Im building a website using django. On my display page, I have a list of items (with the name results), and I have filters which filter "results" and get another list "filtered" on the display page using an ajax call.
Now when I go to some other page, and then click the back button, I get back to the page with the filters selected, but the results are not filtered (I would want the "filters" list rather than the "results" list on going back). How do I get to the most recent state after using the back button? Basically, everything done using javascript and the subsequent actions get flushed.
Can anyone help me with this. Thanks.
Browser history behavior gets complex, but one technique I've used is to embed the state in the hash. That will make the browser treat each different hash value as a different page in the history, and also lets you do things like bookmark a particular filter selection state. I used jquery, along these lines:
$(function() {
if (window.location.hash) {
// parse the hash and update your filter settings, then get the content and display it
};
function update_hash() {
// calculate the hash based on your filter
window.location.hash = new_hash;
};
};
Then bind update_hash as an event handler for changes.

Playframework 2 include a updatable combobox in a list (not a form)

I am using play framework 2.0 .I a page where I list all the elements that the user can edit/delete. one of the listed elements in a look up from another table. I have coded a select in the forms and that works fine.
I would like to include the combo box in the displayed list, so the user can update it right there without having to drill down into each element to update the field. Is there a way to do this? I want to listen to the change in the combobox and update the underlying model.
I tried a few iterations, but the select box seems to want a play.api.data.Field , and not the value I provide.
the parameters to the page is a pageable list like this
#(currentPage: Page[Deal], currentSortBy: String, currentOrder: String, currentFilter: String)
I don't know if I understand the issue, but I think the problem you are stating would be better solved at the client, with some ajax in it...
otherwise, you would be issuing a whole page refresh every time the user updates the items
I would expose the pageable list like a rest-json web service, and I wuld call it from javascript, binding the on-change event...
Here you have an example using select2 to do the lookup and consumign a rest web service: http://bb-jugar.rhcloud.com/assets/js/tmp/select2/demo.html

How to select from a large number of options when completing a form

I am building a web app that allows our field staff to create appointments. This involves creating a record that contains many foreign keys, of which some come from very large tables. For example, the staff will need to select one of potentially thousands of customers.
What's the best way of doing this in Django?
A pop-up box that allows the users to search for customers, gives them the results, the user selects the results, then fills out the main appointment form and then
disappears?
Changing the appointments form to a customer selection page that
then reloads the appointments page with the data in a hidden form? Or
holding the data in some session variables?
Some from of Ajax approach.
A wizard where the flow is: a customer search page, a list of results and they select from results, then a search page for the next option (for example product selection), etc etc
(I'd like to keep it as simple as possible. This is my first Django
project and my first web project for more years than I care to
remember)
ALJ
Imho you should consider some kind of autocomplete fields. I think this results in the best usability for the user. Unfortunately, this always involves Ajax. But if you think that all users have JS turned on this is no problem.
E.g.
django-autocomplete
or what is probably more powerful:
django-ajax-selects
If you do the wizard approach, it will take longer for the user to accomplish the task and makes it harder to change selections.
Edit:
Well with django-ajax-selects you can define how the results should look like. So you can e.g. add the address behind the name.
Quote:
Custom search channels can be written when you need to do a more complex search, check the user's permissions, format the results differently or customize the sort order of the results.
I have done this before by integrating a jQuery autocomplete plugin. But, seeing as this is your first project and your desire to keep it simple, I suppose you could go with the session data option. For instance, you could show a search page where users could search for and select a customer. You could then store the, say, ID of the selected customer object as session data, and use it to pre-populate the corresponding field in the form when displaying the form. That's what I think offhand.

How to filter an inlined foreign key based on master model

In an inline form, in the admin interface, I have a foreign key field.
If you look at the following image: http://www.image-share.com/ipng-147-172.html you will notice an engine field (Set to proximity).
What I'd like is to filter what appear in the list (currently track.context.max_media_duration and track.ambient.max_media_duration) bases on the engine selection.
I'd like it to change when the selection is changed, it will also have to mark existing one that has been filtered out for deletion or delete them.
I don't know where to start to implement such a feature.
Thanks
The easiest approach, in my opinion, would be to do it all as an AJAX callback (e.g. with jQuery). The general code flow might be the following:
Add a jQuery onChange event to the id_engine field.
When the id_engine pull down changes, it triggers a callback.
That callback calls a URL you have set up back to a specific URL and returns values as JSON data.
These values are what you use to overwrite what is found in the pull downs below... jQuery can overwrite these pretty simply. You just have to be careful to match what Django outputs by default -- keeping form names and values similar so Django will know how to handle it when POSTing the data back.