Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support string domain parsing #118

Open
rvalyi opened this issue Oct 3, 2014 · 1 comment
Open

support string domain parsing #118

rvalyi opened this issue Oct 3, 2014 · 1 comment

Comments

@rvalyi
Copy link
Member

rvalyi commented Oct 3, 2014

often Odoo gives us domains as string (in views for instance). But we may need to send them back in json to Odoo. This would help to translate forms better in Aktooor for instance.

Idea: change the domain string a bit and do a JSON.parse on it.
Elements of code:

m = string_domain.match(/time\.strftime\(.*\)/)
m.each do |python_time|
  ruby_time = python_time.gsub("time.strftime(", "Time.now.strftime(")
  string_domain.gsub!(python_time, ruby_time)
end

replaces = {
"(" =>"[",
")" =>"]",
"True" =>"true",
"False" =>"false",
}

replaces.each do |k, v|
  string_domain.gsub!(k, v)
end

domain_rb = JSON.parse(string_domain)

TODO:

  • avoid that () replacements screw time function.
  • deal with variable injections. JSon.parse won't let us bind variables. An idea would be to pass an Ooor object to the domain conversion method. For each field key, we would try to replace the key with its value (send key). To avoid overlapping, the idea would be to match [not azAZ _]key[not azAZ _].
@rvalyi
Copy link
Member Author

rvalyi commented Oct 5, 2014

An other possibility would be https://github.com/byroot/parsr

not a lot of activity but the the guy seems to be doing very serious stuff at Shopify, so will probably do the job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant