0

I want to generate a json from Z SQL method result and to put into json in page template javascript part. This is the format I need.

[
{
    name: 'New',
    data: [
      {y: 0, user_id: 0, issue_status_id: 1},{y: 0, user_id: 5, issue_status_id: 1},{y: 0, user_id: 11, issue_status_id: 1},{y: 0, user_id: 4, issue_status_id: 1},{y: 0, user_id: 6, issue_status_id: 1},{y: 1, user_id: 14, issue_status_id: 1},{y: 0, user_id: 17, issue_status_id: 1},
    ]
}, 
{
    name: 'In Progress',
    data: [
      {y: 0, user_id: 0, issue_status_id: 2},{y: 0, user_id: 5, issue_status_id: 2},{y: 0, user_id: 11, issue_status_id: 2},{y: 0, user_id: 4, issue_status_id: 2},{y: 0, user_id: 6, issue_status_id: 2},{y: 0, user_id: 14, issue_status_id: 2},{y: 1, user_id: 17, issue_status_id: 2},
    ]
}, 

]

I am grouping by "name". Example data

assigned_to_id  assigned_name id name totalssignedbystatus
4   K   1   New 0
11  G   1   New 0
18  V   1   New 0

I can't find any normal example on this....

SteveM
  • 6,058
  • 1
  • 16
  • 20
Aitvaras
  • 261
  • 4
  • 15

1 Answers1

1

I'm going to guess that this seems like a puzzle because you're trying to do it with Python scripts via the ZMI. Those are good for simple things, but you hit the wall as soon as you start trying to do anything more complex.

Instead, learn how to create a Python add-on and integrate it via buildout. Using the ZopeSkel code generator, this is really very easy. You'll find a skeleton available for a browser view, which is the baseline for this type of project.

Once you're working at this level, you'll have direct access to MySQL-python (or SQL Alchemy if you want to do something fancier). And, the Python-standard json module will make the jsonification of Python data structures trivial. Finally, you'll be able to use a browser view to make it available in page templates.

SteveM
  • 6,058
  • 1
  • 16
  • 20
  • This might be helpful http://developer.plone.org/templates_css_and_javascripts/ajax.html#json-views-and-loading-data-via-ajax – Mikko Ohtamaa Dec 05 '12 at 22:36
  • I would like to start from simple things... I need to create some content into an existing site. Ruby on rails templating is much much more nicer than Plone.... – Aitvaras Dec 06 '12 at 11:21
  • If your point is to create content, transmogrifier is the tool. There are even transmogrifier add ons to use json for a content source. – SteveM Dec 06 '12 at 15:07
  • OK, I have done it with a python script, but it is not beautiful as I do not have a power of json library. I will look into transmogrifier. – Aitvaras Dec 08 '12 at 10:37
  • I don't get your ruby on rails comment. Templating has nothing to do with generating JSON data. – vangheem Dec 13 '12 at 12:39