How to get this output:
<h1>Colors</h1>
<li><strong>red</strong></li>
<li>green</li>
<li>blue</li>
From this template:
<h1>{{header}}</h1>
{{#bug}}
{{/bug}}
{{#items}}
{{#first}}
<li><strong>{{name}}</strong></li>
{{/first}}
{{#link}}
<li>{{name}}</li>
{{/link}}
{{/items}}
{{#empty}}
<p>The list is empty.</p>
{{/empty}}
This data:
{
"header": "Colors",
"first": true,
"items": [
{"name": "red", "first": true, "url": "#Red"},
{"name": "green", "link": true, "url": "#Green"},
{"name": "blue", "link": true, "url": "#Blue"}
],
"empty": false
}
So that the first field is not overridden.
Currently I get this output:
<h1>Colors</h1>
<li><strong>red</strong></li>
<li><strong>green</strong></li>
<li>green</li>
<li><strong>blue</strong></li>
<li>blue</li>
I'm testing here.
The first key is defined at two levels: at the item level, and at the root level.
When it is not defined at the item level, the Mustache engines digs in, and uses the one defined at the root level. This is called the Mustache context stack, and you have just learnt it the hard way.
Now the answer is simple, insn't it? In order to prevent the Mustache engine to dig in the context stack and look for first at the root level, make sure first is defined at the item level, for all items. Set it to false for all items but the first.
Related
I'm trying to find every "color" value and replace it with a specific string, but only the "color" value of every "name" that has Bismuthinite" in it.
[
{
"name": "Poor Gneiss Bismuthinite",
"blockName": "tfc:ore/poor_bismuthinite/gneiss",
"order": 789,
"color": 5015620,
"drawing": false
},
{
"name": "Slate Halite",
"blockName": "tfc:ore/halite/slate",
"order": 1046,
"color": 7153517,
"drawing": false
},
The information wthin the next brackets (block? im not sure what the terminology is, i'm very new to coding in general) should not be selected or altered in any way. Only the information that matches "name" includes Bismuthinite" .
I've tried using a multiline find and replace using the ToolBucket plugin for Notepad++, but either it won't accomplish what I want it to do, or I just don't know how.
Working with django JsonField. Using django-entangled in form. I need data format like below. Need suggestion to avail this.
[
{
"name": "Test 1",
"roll": 1,
"section": "A"
},
{
"name": "Test 2",
"roll": 2,
"section": "A"
}
]
With django-entangled this is not possible, because that library does not offer multiple forms of the same kind.
You can however try my next form library django-formset, which can handle multiple forms of the same kind.
I am trying to use value from dynamic generation.
My payload looks like:
{
"payload": [
{
"questionDefinitionId": "jRs6zAh3GGt3G8tL9SzUrS8SiXyg6EirSElv3VRpX_Q=",
"questionText": "What was your childhood nickname?",
"languageCode": "en",
"questionNumber": 1,
"disabled": false
},
{
"questionDefinitionId": "pmyZ4excucJBuFvSPCr6yIvO74vZS8DUNPx0GYVR57E=",
"questionText": "What is your favorite team?",
"languageCode": "en",
"questionNumber": 2,
"disabled": false
},
{
"questionDefinitionId": "awE_x8cXHcc0uhJ7lgtjzX1NtgA0IQBBWu7iDbVqW-k=",
"questionText": "What is the name of your favorite childhood friend?",
"languageCode": "en",
"questionNumber": 1,
"disabled": false
},
{
This generation is different every time when is executed.
I need to get: jRs6zAh3GGt3G8tL9SzUrS8SiXyg6EirSElv3VRpX_Q=, which is questionDefinitionId value for the questionNumber: 1, but is always generated in the different location in the Json file
but every time their order is in different place in the long list.
Your payload appears a JSON object to me, in this case it makes much more sense to go for JSON Extractor, this will be way easier to implement/read/support/etc.
For example you can get questionDefinitionId attribute value where questionText is What was your childhood nickname? using == Filter Operator like:
$.payload[?(#.questionText == 'What was your childhood nickname?')].questionDefinitionId
Demo:
If you want the questionDefinitionId where questionNumber is 1 amend the JSON Path Expression to look like:
$.payload[?(#.questionNumber == '1')].questionDefinitionId
However in your example there are 2 questions with number 1
See API Testing With JMeter and the JSON Extractor for more information on the concept.
Try this regex:
(?<="questionDefinitionId": ")(.+?)(?=")
I started to look into creating a specific ES-mapping for tweets, but quickly realized that an ES-mapping of the tweet-model would become a nightmare to maintain over time so I started to think about dynamic templates. I've registered a dynamic template for every possible property according to the twitter object description. A tweet is a very hierarchical and redundant format which means that a property, say "created_at", may be present at a number of places - thus the nightmare to maintain a stable explicit mapping.
In the mapping I've created so far I have no explicit mappings ("properties"-attribute is empty) as I want all the mappings to be controlled by dynamic templates. As an example my dynamic template for the "created_at" property looks like:
{
"created_at": {
"match": "created_at",
"mapping": {
"format": "EEE MMM d HH:mm:ss Z YYYY",
"index": "no"
}
}
I thought that having this template would take care of the mapping of a "created_at" property whereever it would appear in the json-structure. I know that I may specify "path_match" in order to explicitly specify a give property-instance but I want all the "created_at" attributes to be mapped according to the template above.
However - when I start indexing data into ES I get numerous errors looking something like:
Caused by: org.elasticsearch.ElasticsearchIllegalArgumentException: unknown property [created_at]
at org.elasticsearch.index.mapper.core.StringFieldMapper.parseCreateFieldForString(StringFieldMapper.java:331)
at org.elasticsearch.index.mapper.core.StringFieldMapper.parseCreateField(StringFieldMapper.java:277)
at org.elasticsearch.index.mapper.core.AbstractFieldMapper.parse(AbstractFieldMapper.java:399)
... 13 more
What am I doing wrong here?
You could try the following example to set up a dynamic template:
curl -XPUT localhost:9200/_template/template_for_created_at -d '
{
"template": "*",
"mappings": {
"_default_": {
"dynamic": true,
"dynamic_templates": [
{
"created_at_tmpl": {
"match": "created_at",
"match_mapping_type": "date",
"mapping": {
"type": "date",
"format": "EEE MMM d HH:mm:ss Z YYYY",
"index": "no",
"null_value": null
}
}
}
]
}
}
}'
More details and examples can be found here: https://www.elastic.co/guide/en/elasticsearch/reference/1.6/indices-templates.html
I'm soo sorry I haven't marked this question as "solved"!!!! I managed to get it working after some investigations. Thanks for the suggestion though.
Cheers
I'm trying to load in around 30k xml files from clinicaltrials.gov into a mySQL database, and the way I am handling multiple locations, keywords, etc. are in a separate model using ManyToManyFields.
The best way I've figured out is to read the data in using a fixture. So my question is, how do I handle the fields where the data is a pointer to another model?
I unfortunately don't know enough about how ManyToMany/ForeignKeys work, to be able to answer...
Thanks for the help, sample code below: __ represent the ManyToMany fields
{
"pk": trial_id,
"model": trials.trial,
"fields": {
"trial_id": trial_id,
"brief_title": brief_title,
"official_title": official_title,
"brief_summary": brief_summary,
"detailed_Description": detailed_description,
"overall_status": overall_status,
"phase": phase,
"enrollment": enrollment,
"study_type": study_type,
"condition": _______________,
"elligibility": elligibility,
"Criteria": ______________,
"overall_contact": _______________,
"location": ___________,
"lastchanged_date": lastchanged_date,
"firstreceived_date": firstreceived_date,
"keyword": __________,
"condition_mesh": condition_mesh,
}
}
A foreign key is simple the pk of the object you are linking to, a manytomanyfield uses a list of pk's. so
[
{
"pk":1,
"model":farm.fruit,
"fields":{
"name" : "Apple",
"color" : "Green",
}
},
{
"pk":2,
"model":farm.fruit,
"fields":{
"name" : "Orange",
"color" : "Orange",
}
},
{
"pk":3,
"model":person.farmer,
"fields":{
"name":"Bill",
"favorite":1,
"likes":[1,2],
}
}
]
You will need to probably write a conversion script to get this done. Fixtures can be very flimsy; it's difficult to get the working so experiment with a subset before you spend a lot of time converting the 30k records (only to find they might not import)