On a website I have a <select> element with multiple attribute like so:
<select value="name" multiple>
<option value="willi">Willi</option>
<option value="wonka">Wonka</option>
</select>
If both options are selected, then the Pyramid server’s view function receives the request object with a multidict instance:
MultiDict([('name', 'willi'), ('name', 'wonka')])
Because I’ve been using Colander for data validation and deserialization, I wanted to write a schema for this instance… but after digging around the documentation I’m beginning to wonder if that’s at all possible?
So, how would I deserialize this particular multidict using Colander?
I suspect you'll want to use something like request.POST.mixed() which will return a list for the name key if multiple values were sent (but not a list if just one value) combined with maybe a colander preparer to convert it to a list if it isn't already.
Related
In a Meteor template with Blaze I want to simply duplicate a piece of text entered by the user onto another part of the screen. Is there a way to do this without writing helper JS code? Something like:
<input value="{{theValue}}" type="text">
<p>{{theValue}}</p>
I don't want to store the data in a collection, just duplicate it. Seems like this can't be done without writing a JS helper.
Like you said,i am unaware of any method too without writing a helper for this,
if you are taking the user's input and then you want to display it elsewhere,it would be best to store the input in a Session or reactive variable and then later display it with a helper
in the input event
Session.set("inputValue",the-user's value);
and return a helper wherever you want to display it
'userValue' : function(){
return Session.get("inputValue");
anyway i would update the answer if i find something that can be done without using a helper
Using MyBatis in a Camel route to select key/value pairs from a database table I got the following issue.
My route (as a part of a content enricher):
from("direct:resource")
.setBody().constant(123)
.to("mybatis:selectParameters?statementType=SelectList")
...;
Mapper:
<select id="selectParameters" parameterType="int" resultType="java.util.HashMap">
SELECT
KEY
,VALUE
FROM
TABLE
WHERE
ID=#{id}
</select>
Everything works fine except that the body contains an ArrayList of HashMaps (one for each key/value pair) instead of one HashMap with n k/v pairs.
Any help would be greatly appreciated
I would assume you should use statementType=SelectOne as you only select one row in the SQL query. Because you use SelectList then a List is always returned, even if there is only 1 row from the SQL resultset.
You can see which statement types is possible here: http://camel.apache.org/mybatis
And of course consult the MyBatis documentation for further details on using MyBatis etc.
I am writing a simple crawler using VBA. I found out that the data I am looking for correspond to the node <h6 class="country-name" id="Australia">.
I know that if I wanted to select data from, let us say, <div class="section-country">, I should use .getElementsByClassName("section-country") in my VBA macro.
In presence of both class and id in the node, which command should I insert in my VBA macro to scrape data?
Thanks a lot,
Avitus
EDIT: writing .getElementsByClassName("country-name").getElementsById("Australia") gives me an error. Why?
getElementsByID (plural) doesn't exist - there should only be one item with a given ID. Therefore, use getElementByID (singular) which does exist. If there happen to be multiple elements with the same ID, this function will return the first one.
As others have said, selecting by ID sounds more appropriate to what you want to do than selecting by class
There must be a method like getelementbyxpath you can use this method by using this xpath "//div[#class='country-name' and #id ='Australia']"
eg: getElementsByXpath("//div[#class='country-name' and #id ='Australia']")
Read More here how to set up a crawler for web scraping
I'm running into the limits of my SQL knowledge. I'm pulling related entries into a Safecracker form, as pull-down inputs, and want to retrieve only related entries of a particular category from the database. For example, I've got an 'events' channel, in which you can relate the event to an entry in a 'locations' channel. I don't need to see all of the possible venues, just ones from a particular category that relate to a particular type of event. Anyone have any ideas? Thanks in advance for your help.
I forgot to mention that I already have the query pulling out ALL of my related entries, but so far no luck filtering by category.
<label>RELATED ENTRY TEST</label>
<select name="event_rel_location" id="event_rel_location">
<option value="">--</option>
{exp:query sql="SELECT entry_id AS rel_entry_id, title AS rel_title, (SELECT rel_child_id FROM exp_relationships WHERE rel_id = '{event_rel_location}' LIMIT 10) AS rel_child_id FROM exp_channel_titles WHERE channel_id = 51 AND status='Open' ORDER BY title ASC "}
<option value="{rel_entry_id}" {if rel_child_id == rel_entry_id} selected="selected"{/if}>{rel_title}</option>
{/exp:query}
</select>
Yup, that'll be a tough query ... might be a better use of your time/budget to buy Playa, convert your relationship field to Playa, then use the Playa module tags instead, which allow you to restrict related and reverse-related entries by category ({exp:playa:parents} and {exp:playa:children}).
I'm working on a very, very quick and dirty application using almost entirely scaffold to do it. This is only for internal use, and it's just to replace a spreadsheet, so while I know that I shouldn't rely on scaffolds for real production use, I still intend to use them where I can for efficiency (...just wanted to make sure we aren't taken off track by the inevitable question!).
What I am curious about is since scaffolds can do quick and dirty CRUD, and you can do dynamic finders for searches, is there a way to dynamically show the "list" action of the scaffold with a constraint (i.e. show all items in the list that were created by this "user")? That would be fine for me...
Alternatively, is there anything available in Grails to allow "grouped" tables. Essentially the "list" action from the scaffold, but grouped by a particular attribute (again, think of grouping all the items by the user that created them).
Any help would be appreciated - I've scoured Google and some books with no luck, but wanted to check with the StackOverflow community before I dismiss the notion and write it by hand. Thanks!
We did the same in our Grails application and it's relatively easy:
Create a new form in the list.gsp referring to the list action <g:form action="list" method="post">
Inside that form, declare a table with the fields you want to search on:
<div class="buttons">
<span class="button"><g:submitButton name="list" class="search" value=" ${message(code: 'default.button.search.label', default: 'Search')}"/></span>
</div>
In the list action, build up the query (using findAll, findWhere, .. whatever takes your fancy) and return that to the page:
[wardInstanceList : Ward.findAll(whereClause, [max: params.max, offset: params.offset]) , wardInstanceTotal : (int) Ward.executeQuery("select count(*) " + whereClause).get(0)]
The whereClause looks something like: "from Ward where ward = 'something' and room = 'something else'"