Hi,
I am using MenusPlugin <https://trac-hacks.org/wiki/MenusPlugin> for
displaying trac menus as submenus. At one point of implementation we are
trying to store a list of dictionary of data that is generated by this
menus plugin into postgresql database. Please find the list of dictionary
sample below.
[{'parent_name': u'top', 'href': u'/auth/dashboard', 'name': u'new_dash',
'active': False, 'visited': True, 'enabled': True, u'order': u'-9999999',
'label': <Fragment>}, {'parent_name': u'top', 'href': u'/myprojects', 'name'
: u'allprojects', 'active': True, 'visited': True, 'enabled': True, u'order'
: u'-9999998', 'label': <Fragment>}, {'parent_name': u'top', 'href': u'#',
'name': u'alltimesheet', 'children': <Element "ul">, 'active': False,
'visited': True, 'enabled': True, u'order': u'-9999997', 'label': <Fragment
>}, {'parent_name': u'top', 'href': u'/myteam', 'name': u'myteam',
'children': <Element "ul">, 'active': False, 'visited': True, 'enabled':
True, u'order': u'-9999996', 'label': <Fragment>}, {'name': u'timesheet',
'parent_name': u'top', 'enabled': True, 'label': <Fragment>, 'children': <
Element "ul">, 'href': '#', 'active': False, 'visited': True, u'order': u'4'
}, {'parent_name': 'top', 'name': u'admin', 'enabled': False, 'label': <
Fragment>, 'href': '#', 'active': False, 'visited': True, u'order': u
'999999'}, {'name': u'username', 'parent_name': u'top', 'enabled': True,
'label': <Fragment>, 'children': <Element "ul">, 'href': '#', 'active':
False, 'visited': True, u'order': u'9999999'}]
My aim is to store this whole list of dictionary into a table as is. But as
you can see some Genshi <fragment> and <Element "ul"> are present in this,
following two methods are failing.
1. Pickle object
2. Json
Method 1: (Pickle)
-------------------------
pickle_data = cPickle.dumps(menu_dict, -1) # menu_dict is the data that you
can see above.
# constructed pickle
successfully in this step.
binary_menu = psycopg2.Binary(pickle_data) # converting pickle to Binary is
also done successfully.
# And I hope I can store this
data to db as is but for a try I am unpickling the
# binary data back to it's original form using the
below statement
# and that doesn't work!
cPickle.loads(str(binary_menu)) # this throws some errors as shown below.
Below is the error that I ended up with the last line in above chunk
*Trac detected an internal error: *
UnpicklingError: invalid load key, '''.
I am unable to solve this! so I tried method 2.
Method 2:
---------------
from psycopg2.extras import Json
menu_dict = {'mainnav': menu_dict}
Json(menu_dict) # by this I am trying to convert entire list of dict into
some json object and this doesn't work either.
tried one more varient with the default json conversion.
import json
json.dumps(menu_dict) # this produces below error.
*Trac detected an internal error:*
TypeError: <Fragment> is not JSON serializable
My total aim is to store the first data, that is a list of data into a
table and retrieve it back.
Help me to solve this.
--
You received this message because you are subscribed to the Google Groups "Trac
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/trac-users/9e1f2e7b-d187-4125-867d-2f2b8cbc4987%40googlegroups.com.