I have a list page with some filter, sort and search functionality (which basically creates a QuerySet in the view that then returns the adjusted (filtered, sorted, searched) data). On this list page, I also have a detail view that displays the object details.
This all works fine, but when I navigate to another detail object, the search, filter, sort parameters get reset to their default.
How can I retain the search parameters beyond a server round trip?
Thanks!
You could store the GET parameters as session variables maybe?
To set:
request.session['my_variable'] = request.GET.get('some_get_parameter')
To get:
my_variable_value = request.session.get('my_variable')
Using .get() to retrieve parameters and session variables is a little more robust than just trying to access the dicts directly with request.session['my_variable'] for example, as if my_variable is not in the session, you'll get a key error, but get() returns None if the variable is not found.
Related
I have a multi-valued people picker and a multi-valued Lookup field that I need to read all the entries in a 2013 workflow. I know how to create a workflow that retrieves the data and iterate through each list item using REST and a dictionary. Given I'm iterating through each item, I need to now iterate through each multi-valued field.
In the past, I have done this using a loop iterator and a second dictionary entry representing the data in the multi-valued field, but I don't have access to this code anymore. I can use a loop and use the find function parsing through my responseContent, but this is not reliable since my reponseContent will have multiple records in it and I know it can be done using a second dictionary entry.
My REST query is:
_api/lists/GetByTitle('EmailSetup')/Items?$select=EmailYN,EmailSubject,EmailBody,EmailTo/EMail,Emailcc/EMail,EmailToWorkflowPerson/Title,EmailccWorkflowPersons/Title&$filter=(Title%20eq%20%27BSM%20Review%27)%20and%20(WorkflowName%20eq%20%27ProcessBSMRequests%27)&$expand=EmailTo,Emailcc,EmailToWorkflowPerson,EmailccWorkflowPersons
Where my multi-valued fields are the Emailcc and EmailccWorkflowPerson, (people picker and lookup respectively).
I have my first dictionary as the following data structure that captures the requestHeaders
Accept String application/json;odata=verbose
Content-Type String application/json;odata=verbose
In my first loop I get all my attributes, but not certain how to get the multi-valued fields Emailcc and EmailccWorkflowPersons.
Yes, I can parse through my response, but there's a better way to somehow put these multi-value fields into a structure and then loop through these.
What I need is what is that structure (dictionary) and how do you get the data into that structure and then how do you loop through that structure.
The final result should be of the sort (psuedocode) where Index is which record I am on and Index2 is which multi-value I am on.
d/results([%Varaible: Index%])/Emailcc/Email[%Variable: Index2%])xxx
With a lot of debugging I have gotten half my answer and maybe someone can help me with the other half. The data structure of the data when it comes back via the REST looks like (some masking of our own data):
responseContent={"d":{"results":[{
"__metadata":{"id":"Web\/Lists(guid'c7bb71c8-a9dd-495f-aa5f-4dcacdf8db5c')\/Items(1)","uri":"https:\/\/xxxxx.xxxxxx.xxxxxxxxx.xxx\/hc\/teams\/MES\/_api\/Web\/Lists(guid'c7bb71c8-a9dd-495f-aa5f-4dcacdf8db5c')\/Items(1)","etag":"\"13\"","type":"SP.Data.EmailSetupListItem"},
"EmailTo":{"__metadata":{"id":"b493bee4-ec1a-4b76-a028-11766bdb7e5b","type":"SP.Data.UserInfoItem"},"EMail":"xyxee.dyff#homeward.com"},
"EmailToWorkflowPerson":{"__deferred":{"uri":"https:\/ \/xxxxx.xxxxxx.xxxxxxxxx.xxx\/hc\/teams\/MES\/_api\/Web\/Lists(guid'c7bb71c8-a9dd-495f-aa5f-4dcacdf8db5c')\/Items(1)\/EmailToWorkflowPerson"}},
"Emailcc":{"results":[{"__metadata":{"id":"790a690a-515b-4d07-bba3-73bf325fbbed","type":"SP.Data.UserInfoIt em"},"EMail":"xyxee.dyffns1#homeward.com"},{"__metadata":{"id":"3d77e75c-5fa8-4df6-937c-97e572714843","type":"SP.Data.UserInfoItem"},"EMail":"xyxee.dyffr#homeward.com"}]},
"EmailccWorkflowPersons":{"results":[{"__metadata":{"id":"06582ed9-09 10-4932-9b43-0cfb072942c7","type":"SP.Data.WorkflowPersonsListItem"},"Title":"Assistant Administrator"},{"__metadata":{"id":"13d03566-1703-4550-a21f-08ea286d4940","type":"SP.Data.WorkflowPersonsListItem"},"Title":"Initiator"}]},
"EmailYN":"No",
"EmailSubject":"BSM Request # %%ID%%",
"EmailBody":"<div class=\"ExternalClass645790473F7D4B62BE6224DD7B93990F\">%%IDLINK%%<br><\/div><div class=\"ExternalClass645790473F7D4B62BE6224DD7B93990F\">and the BSM# %%ID%%<br><\/div><div class=\"ExternalClass64 5790473F7D4B62BE6224DD7B93990F\"><br><\/div>"
}]}}
I created another dictionary variable, EmailResults just as the first one to store the multi-value emailcc addresses.
Then the following Get:
Get d/results([%variable: Index%)/Emailcc/results from Variable:responseContent (Output to Variable: EmailccResults)
To get the record count, I use Count Items in the EmailccResults
I set my second index to start at zero and loop through the number baseed on the count in EmailccResults.
To set my intermediate email address (getting one value at a time from the mult-value People picker).
Get d/results([%variable: Index%)/Emailcc/results(%Variable: Index2%)/EMail from Variable: responseContent (Output to Variable: EmailCc)
then I increment the Index2 variable and go to the next record. This works perfectly.
Now my problem is I have a multi-value Lookup that is included in this query (see what the results are above). I attempt the same logic and I am successfully getting the count, but not the Title fields.
My get is:
Get d/results([%variable: Index%)/EmailccWorkflowPersons/results from Variable:responseContent (Output to Variable: EmailccResults)
My actual assignment is:
Get d/results([%variable: Index%)/EmailccWorkflowPersons/results(%Variable: Index2%)/Title from Variable: responseContent (Output to Variable: tmpvar)
** the Lookup works exactly the same way. My problem was that my get above had some blank lines in the text box.
I have a search route with many parameters. At the moment my URL contains all of the parameters set to default values if they aren't set by the user. I want to be able to remove, add the parameters to URL depending on whether the user has selected them. For instance. If the user has selected both min and max prices and sizes it would be;
minprice/0/maxprice/5000000/minsize/0/maxsize/10000/
But if they have only selected price it would be;
minprice/0/maxprice/5000000
I have tried to use the serialize method in my search route, but that seems only to pass the dynamic segments to the router which I have defined, with the rest coming up undefined.
So how can I dynamically add/remove dynamic segments to my route?
Thanks
I ended up using a computed property on my search object. On the property I check for changes in other search properties, I then return a property called 'FullUrl' and use that in my route as a dynamic segement. This gives me complete control over the url.
On a page refresh I simply parse my computed property in order to get my search object properties and maintain state.
I have a lookup field in list in share point 2010, how to set a default value for that field at inserting operation
Using JavaScript, override the PreSaveAction method and push whatever you like into the lookup column. this happens just prior to the post to the web server, so you cna do all validation and checks.
Beware though, the value you insert must exist in the lookup list or the post will fail, ie don't push a value of "abc" if "abc" is not on the list of possible options fo rhte lookup column.
If you want to preselect some value in lookup control (dropdown) when dialog is open you need to do it by JS. You need to hook onload (JS) event of the page. There are some libraries that makes it easier to set SharePoint field values e.g. SPJS-utility. Common way is that you send id of item using URL parameter and get by JS and then set it to field. Speaking of lookup beware of the fact that SP renders lookup control in different way in IE for less than 20 items and for more than 20 item.
I'm listing queryset results and would like to add an option for choosing the order results are displayed.
I would like to pass the actual data from the database to other page for sorting.
I was able to achieve such thing by getting all objects ids and use django session to recreate a new queryset based on the order criteria.
I was thinking if there is any other way to achieve such goal?
10x
Assuming you are currently displaying the data as a table, you could give chance to some javascript client side table sorter such as tablesorter. There are lots of javascript table sorte.
I'm away from my development machine right now, but I think you could just pass the list of ids to a new Queryset, pk__in=list_of_object_ids, and then use the native order_by function.
For example:
objs = Object.objects.filter(pk__in=list_of_object_ids).order_by('value_to_order_by')
Anyway, that's what I would try first, though I'm sure there are better optimizations.
For example, instead of a list of object ids, you could pass a dictionary with a key:value pair that has the value you want to order by.
For example:
[{'obj_id':1,'obj_value':'foo'},{'obj_id':2,'obj_value':'foo'}]
Then use some lambda function to sort it, like here.
Using struts2 how can I keep list values just after click in a jsp button, going through the action and returning to jsp again? Doing this click several times again.
I've been watching that to keep a value from a variable that isn't a list I just need to declare it in the action with it's getter and setter, and put a hidden field or textfield in the jsp, but regarding lists don't worked like that.
You are correct that we need a getter and setters for the respected property in our action class to send and receive date from Action class to JSP and in reverse order.
But since for collection, its not possible to store it in a single field, so you have few options here.
If List is a simple List of String you can create a comma separated string and can use that to go from action to JSP and in reverse order (easy to convert that to list), i will not recommend this approach.
Second option i am thinking to set the list in session and you can always retrieve the list in your action class at any time as per your choice.