to_json Converts the preference object to the JSON Format. :returns: a JSON object contains information.
(self)
| 337 | Preferences.modules[name] = self |
| 338 | |
| 339 | def to_json(self): |
| 340 | """ |
| 341 | to_json |
| 342 | Converts the preference object to the JSON Format. |
| 343 | |
| 344 | :returns: a JSON object contains information. |
| 345 | """ |
| 346 | res = { |
| 347 | 'id': self.mid, |
| 348 | 'label': self.label or self.name, |
| 349 | 'name': self.name, |
| 350 | 'categories': [] |
| 351 | } |
| 352 | for c in self.categories: |
| 353 | cat = self.categories[c] |
| 354 | interm = { |
| 355 | 'id': cat['id'], |
| 356 | 'name': cat['name'], |
| 357 | 'label': cat['label'] or cat['name'], |
| 358 | 'preferences': [] |
| 359 | } |
| 360 | |
| 361 | res['categories'].append(interm) |
| 362 | |
| 363 | for p in cat['preferences']: |
| 364 | pref = (cat['preferences'][p]).to_json().copy() |
| 365 | pref.update({'mid': self.mid, 'cid': cat['id']}) |
| 366 | interm['preferences'].append(pref) |
| 367 | |
| 368 | return res |
| 369 | |
| 370 | def __category(self, name, label): |
| 371 | """ |