In my app, i have main naivgation link with sublinks (drop down menus) - i am calling my collection from navigation view, and i am getting the json response like this:
[{"label": "General","link":"#/general",
"subLinks": [{"label": "Dashboard", "link": "#/dashboard"},
{"label": "My Task", "link": "#/mytask"},
{"label": "My Documents", "link": "#/mydocuments"},
{"label": "My Templates", "link": "#/mytemplates"},
{"label": "Repositories", "link": "#/reposotories", "subLinks": []},
{"label": "SavedSearches", "link": "#/savedSearches", "subLinks": []}
]
my question is how to convert this in to backbone models.. especially how can i handle the sublinks relation of each main links..? (how to make nested models in main model)
You have to use parse.
With parse, you are in control of translating the raw response to your model object. There, for instance, you could take the raw subLinks array and feed it to a Collection of yours, and then set the popoluated collection as a property of your Model.
Related
i'm new to Wagtail and struggling to create content programmatically from a Django management command.
I have defined a StructBlock and Page with a StreamField like so:
class TaskBlock(blocks.StructBlock):
tasks = blocks.ListBlock(
blocks.StructBlock(
[
("title", blocks.CharBlock()),
("length", blocks.IntegerBlock())
]
)
)
class Meta:
template = "tasks/task_block.html"
icon = "edit"
label = "Task"
class TaskPage(Page):
tasks_first = StreamField([("tasks_first", TaskBlock())], null=True)
content_panels = Page.content_panels + [StreamFieldPanel("tasks_first")]
My command looks like:
class Command(BaseCommand):
def handle(self, *args, **options):
parent_page = Page.objects.get(title="Task Master").specific
task_page = TaskPage(
title="Task Page 5",
slug="task-page-5",
tasks_first=json.dumps(
[
{
"type": "tasks_first",
"value": [
{
"type": "tasks",
"value": [
{"type": "title", "value": "this is a task"},
{"type": "length", "value": 5}
],
}
],
}
]
),
)
parent_page.add_child(instance=task_page)
revision = task_page.save_revision()
revision.publish()
task_page.save()
The page is successfully created with a Task block, but the task is blank and does not contain the test data defined in the json.
I'm probably missing some basic knowledge on how to define the json for the TaskBlock() in the StreamField tasks_first.
Could you give me some guidance?
Probably clearer to start from the inside and work outwards here...
The JSON representation of a StructBlock value is a simple dict, where the keys are the sub-block names and the values are their values - you don't need "type" and "value" here. So, a value for the innermost StructBlock would look like:
{"title": "this is a task", "length": 5}
The value for ListBlock is a list of these values. If we only want one task in the list, this will be:
[
{"title": "this is a task", "length": 5}
]
TaskBlock is a StructBlock with a single sub-block named "tasks", so again this should be a simple dict:
{
"tasks": [
{"title": "this is a task", "length": 5}
]
}
And finally we place this in the stream - this is where the "type" and "value" come in.
[
{
"type": "tasks_first",
"value": {
"tasks": [
{"title": "this is a task", "length": 5}
]
}
}
]
This, then, is what you pass to json.dumps(...).
Finally, are you sure you need a StreamField at all here? If you just want a page with a list of tasks on, you could do this with an InlinePanel where each child object is one task.
I am using SOAP API to communicate with Polarion server. In one of WSDL files, there are defined a few webservices to query work items, but I could not find a single example how to use them.
Let say that I want to ask the server for all work items that are 'Test Case' type in project 'My First Project'. What parameter values should I pass to 'queryWorkItems' or 'queryWorkItemsBySQL'?
I have found following documentation with structure of the requests:
https://almdemo.polarion.com/polarion/sdk/doc/javadoc/com/polarion/alm/ws/client/tracker/TrackerWebService.html#queryWorkItems(java.lang.String,java.lang.String,java.lang.String%5B%5D)
https://almdemo.polarion.com/polarion/sdk/doc/javadoc/com/polarion/alm/ws/client/tracker/TrackerWebService.html#queryWorkItemsBySQL(java.lang.String,java.lang.String%5B%5D)
Unfortunately I have no idea what 'query' or 'sqlQuery' should be like.. Could you provide any examples?
I have found how to build and send API requests with Lucene queries. In this video, there is shown how to build (in video since 0:40) and convert them in text format (in video since 2:52):
https://www.youtube.com/watch?v=DSRKfdr2aJc
Once you have txt query in Lucene format build, you send API webservice request:
queryWorkItems(query, sort, fields)
Example (Python syntax):
queryWorkItems(query="project.id:MyProject AND type:testcase", sort="uri", fields=["id", "assignee"])
Dictionary of [Work Item field] -> [field type]:
FIELDS = {
"approvals": "ArrayOfApproval",
"assignee": "ArrayOfUser",
"attachments": "ArrayOfAttachment",
"author": "User",
"categories": "ArrayOfCategory",
"comments": "ArrayOfComment",
"created": "dateTime",
"description": "Text",
"dueDate": "date",
"externallyLinkedWorkItems": "ArrayOfExternallyLinkedWorkItem",
"hyperlinks": "ArrayOfHyperlink",
"id": "string",
"initialEstimate": "duration",
"linkedOslcResources": "ArrayOfLinkedOslcResource",
"linkedRevisions": "ArrayOfRevision",
"linkedRevisionsDerived": "ArrayOfRevision",
"linkedWorkItems": "ArrayOfLinkedWorkItem",
"linkedWorkItemsDerived": "ArrayOfLinkedWorkItem",
"location": "Location",
"moduleURI": "SubterraURI",
"outlineNumber": "string",
"plannedEnd": "dateTime",
"plannedIn": "ArrayOfPlan",
"plannedStart": "dateTime",
"planningConstraints": "ArrayOfPlanningConstraint",
"previousStatus": "EnumOptionId",
"priority": "PriorityOptionId",
"project": "Project",
"remainingEstimate": "duration",
"resolution": "EnumOptionId",
"resolvedOn": "dateTime",
"severity": "EnumOptionId",
"status": "EnumOptionId",
"timePoint": "TimePoint",
"timeSpent": "duration",
"title": "string",
"type": "EnumOptionId",
"updated": "dateTime",
"workRecords": "ArrayOfWorkRecord",
"customFields": "ArrayOfCustom",
"uri": "SubterraURI",
"unresolvable": "boolean",
}
I have created the following JSON-LD for a blogpost in my blog:
{
"#context": "http://schema.org",
"#type": "BlogPosting",
"mainEntityOfPage": {
"#type": "WebPage",
"#id": "https://www.example.com"
},
"headline": "My Headline",
"articleBody": "blablabla",
"articleSection": "bla",
"description": "Article description",
"inLanguage": "en",
"image": "https://www.example.com/myimage.jpg",
"dateCreated": "2019-01-01T08:00:00+08:00",
"datePublished": "2019-01-01T08:00:00+08:00",
"dateModified": "2019-01-01T08:00:00+08:00",
"author": {
"#type": "Organization",
"name": "My Organization",
"logo": {
"#type": "ImageObject",
"url": "https://www.example.com/logo.jpg"
}
},
"publisher": {
"#type": "Organization",
"name": "Artina Luxury Villa",
"name": "My Organization",
"logo": {
"#type": "ImageObject",
"url": "https://www.example.com/mylogo.jpg"
}
}
}
Now, I have some blog posts that contain multiple paragraphs and each paragraph is accompanied by an image. Any ideas how can I depict such a structure with JSON-LD?
Background
I have created a simple blog which uses a JSON file for 2 purposes: (a) feed the blog with posts instead using a DB (by using XMLHttpRequest and JSON.parse) and (b) to add JSON-LD structured data to the code for SEO purposes.
When I read the JSON file I have to know which image belongs to which paragraph of the text in order to display it correctly.
Note: As you seem to need this only for internal purposes, and as there is typically no need to publically provide data about this kind of structure, I think it would be best not to provide public Schema.org data about it. So you could, for example, use it to build the page, and then remove it again (or whatever works for your case). Then it would also be possible to use a custom vocabulary (under your own domain) for this, if it better fits your needs.
You could use the hasPart property to add a WebPageElement for each paragraph+image block.
Each WebPageElement can have text and image (and, again, hasPart, if you need to nest them).
Note that JSON-LD arrays are unordered by default. You can use #list to make it ordered.
"hasPart": { "#list":
[
{
"#type": "WebPageElement",
"text": "plain text",
"image": "image-1.png"
},
{
"#type": "WebPageElement",
"text": "plain text",
"image": "image-2.png"
}
]
}
For the blog posting’s header/footer, you could use the more specific WPHeader/WPFooter instead of WebPageElement.
I have a simple json view like this
{
"articles": [
{
"id": 1,
"title": "Article one",
},
{
"id": 2,
"title": "Article two",
}
]
}
This results are paginated, and i'd like to append the pageCount to the results, something like this.
{
"articles": [
{
"id": 1,
"title": "Article one",
},
{
"id": 2,
"title": "Article two",
}
],
"pageCount": 5
}
How can i achieve this? i can't append it directly because it's a resultset object.
Should i be doing this in the view/controller/model?
thanks a lot!
The _serialize key
Given that you are using the JsonView and auto-serialization
Cookbook > Views > JSON and XML Views > Using Data Views with the Serialize Key
you can simply add another variable for the view, and mark it for serialization, like
$this->set('articles', $this->paginate());
$this->set('pageCount', $this->request->params['paging'][$this->Articles->alias()]['pageCount']);
$this->set('_serialize', ['articles', 'pageCount']);
Using view templates
If you're not using auto-serialization, but custom view templates
Cookbook > Views > JSON and XML Views > Using a Data View with Template Files
you can make use of the PaginatorHelper in your template and add the data when converting to JSON, like
$pageCount = $this->Paginator->param('pageCount');
echo json_encode(compact('articles', 'pageCount'));
I need to display product-wise sales data on grid panels on ExtJs3.2 - one grid per product.
The data is received year-wise,and is loaded into a jsonstore.
{"list": [
{
"Year": "2014",
"product": "IS",
"total": "5.0",
},
{
"Year": "2013",
"product": "IS",
"total": "5.6",
},
{
"Year": "2014",
"product": "NS",
"total": "5.7",
},
{
"Year": "2013",
"product": "NS",
"total": "5.1",
}
....
......
]
}
The response is processed to convert into a product-specific 'keyed' dictionary.
{ "IS":[{"Year":"2013","total":"5.1"},{"Year":"2013","total":"5.1"}..],
"NS":[{"Year":"2013","total":"5.1"},{"Year":"2013","total":"5.1"}..],
..}
Each key(and values) are then loaded into separate array stores to feed the respective grids.
Though simplistic - too many objects/structures are being created to achieve this.
Is there a more elegant way to load multiple grids from extracts of the store data?
If you have important reasons not to switch to MVC ExtJS 4 or MVVC ExtJS 5 you could provide data the needed way on server side. E.g. by Node.js what is fetching the JSON and reworking this. Your request could be more specific and your client App would become faster.
An other way would be to write convert() functions into your Ext.data fields and use them as source for the grid.