Opened 12 years ago
Closed 10 years ago
#10240 closed defect (wontfix)
Can't import "Import Error : cannot import name add_script_data"
Reported by: | anonymous | Owned by: | falkb |
---|---|---|---|
Priority: | normal | Component: | SimpleMultiProjectPlugin |
Severity: | blocker | Keywords: | |
Cc: | Trac Release: | 0.11 |
Description (last modified by )
The reason I'm reporting this issue is because I did not find any information regarding the version needed on the hacks page.
I have 0.11.7 installed.
After installation of SimpleMultiProjects plugin I see it only on the admin page.
This plugin is not visible on the roadmap page.
On trac logs I found this error:
Trac[loader] ERROR: Skipping "simplemultiproject = simplemultiproject": (can't import "ImportError: cannot import name add_script_data")
Attachments (0)
Change History (26)
comment:1 Changed 12 years ago by
comment:2 follow-ups: 4 7 Changed 12 years ago by
Hmm... it seems add_script_data
is a new function of 0.12 :-( Do you see a chance to backport it to 0.11? Unfortunately, I don't have 0.11 anymore.
comment:4 Changed 12 years ago by
Description: | modified (diff) |
---|
comment:5 follow-up: 6 Changed 12 years ago by
rjollos wrote on trac-dev@…:
I'm not sure about backporting, but I can show you some examples of what developers did before the function was available. These are the changesets/patches in which I replaced the virtual script with add_script data:
http://trac-hacks.org/changeset/11247 and http://trac-hacks.org/ticket/9764
Thanks a lot, stored here now. Need some time...
comment:6 Changed 12 years ago by
Replying to falkb:
rjollos wrote on trac-dev@…:
I'm not sure about backporting, but I can show you some examples of what developers did before the function was available. These are the changesets/patches in which I replaced the virtual script with add_script data:
Another solution is to add script
element to head
element on ITemplateStreamFilter.filter_stream
.
See source:tracwysiwygplugin/0.11/tracwysiwyg/__init__.py#L60 and source:tracdragdropplugin/0.11/tracdragdrop/web_ui.py#L176.
comment:7 Changed 12 years ago by
Replying to falkb:
Hmm... it seems
add_script_data
is a new function of 0.12 :-( Do you see a chance to backport it to 0.11? Unfortunately, I don't have 0.11 anymore.
This appears a trivial backport. Diffing to 0.11.6:
-
trac/web/chrome.py
index 20e89d5..2cdc2e3 100644
a b def add_script(req, filename, mimetype='text/javascript'): 108 108 req.chrome.setdefault('scripts', []).append(script) 109 109 scriptset.add(filename) 110 110 111 # Backported from 0.12 112 def add_script_data(req, data={}, **kwargs): 113 """Add data to be made available in javascript scripts as global variables. 114 115 The keys in `data` and the keyword argument names provide the names of the 116 global variables. The values are converted to JSON and assigned to the 117 corresponding variables. 118 """ 119 script_data = req.chrome.setdefault('script_data', {}) 120 script_data.update(data) 121 script_data.update(kwargs) 122 111 123 def add_javascript(req, filename): 112 124 """Deprecated: use `add_script()` instead.""" 113 125 add_script(req, filename, mimetype='text/javascript')
With that in place, I can load GroupTicketFieldsPlugin
and it creates sections in my ticket for other fields but the configured fields don't show up in the new section. Still looking into that.
comment:8 follow-up: 9 Changed 12 years ago by
It looks like you are on the right track, but you need the corresponding functionality to parse script_data
in your template (see layout.html) and a to_json
function.
comment:9 follow-up: 11 Changed 12 years ago by
Replying to rjollos:
It looks like you are on the right track, but you need the corresponding functionality to parse
script_data
in your template (see layout.html) and ato_json
function.
The former is easy. The latter seems a slippery slope.
to_json
is inpresentation.py
- It relies on
dumps
fromjson
orto_js_string
fromutil.text
.- In 0.11.6, there is no
to_js_string
inutil.text
- I'm in Python 2.6.5 and that has
dumps
so that may work but I don't know how far back
- In 0.11.6, there is no
comment:10 Changed 12 years ago by
comment:11 follow-up: 12 Changed 12 years ago by
Replying to ChrisNelson:
The former is easy. The latter seems a slippery slope.
to_json
is inpresentation.py
- It relies on
dumps
fromjson
orto_js_string
fromutil.text
.
- In 0.11.6, there is no
to_js_string
inutil.text
- I'm in Python 2.6.5 and that has
dumps
so that may work but I don't know how far back
Now I'm stuck. I have to_json
in presentation.py
but how do I *import* it into layout.html
?
comment:12 Changed 12 years ago by
Replying to ChrisNelson:
Now I'm stuck. I have
to_json
inpresentation.py
but how do I *import* it intolayout.html
?
I think that you need to add it to the data
dictionary: data['to_json'] = to_json
. Take a look at populate_data to see how this works.
comment:13 Changed 12 years ago by
So that gets me further. The page source includes:
<script type="text/javascript"> var field_groups_order=["relationships","main"]; var field_groups=[{"fields":["parents","blockedby","blocking"],"label":"Relationships","name":"relationships"}]; </script>
which is consistent with my configuration:
[group-ticket-fields] relationships = Relationships relationships.fields = parents,blockedby,blocking group_order = relationships,main
but in the ticket, the Relationships section is still empty.
I don't find anything in trac.log
about any failure and I don't get a JavaScript error.
FireBug doesn't list group_ticket_fields.js
among the loaded script resources.
comment:14 follow-up: 18 Changed 12 years ago by
However, the page source includes:
<script type="text/javascript" src="/mytrac/chrome/groupticketfields/group_ticket_fields.js"></script>
comment:15 follow-up: 16 Changed 12 years ago by
One potential problem is that the plugin is calling the function enableFolding
, which is provided in Trac 0.12 by folding.js. This function doesn't exist in Trac 0.11 (see #8942). However, that doesn't seem to be your primary problem here.
comment:16 follow-up: 17 Changed 12 years ago by
Replying to rjollos:
One potential problem is that the plugin is calling the function
enableFolding
, which is provided in Trac 0.12 by folding.js. This function doesn't exist in Trac 0.11 (see #8942). However, that doesn't seem to be your primary problem here.
Yeah, I can live without folding. Hmmm, I wonder if that needs to be protected by a try
?
comment:17 Changed 12 years ago by
Replying to ChrisNelson:
Replying to rjollos:
One potential problem is that the plugin is calling the function
enableFolding
, which is provided in Trac 0.12 by folding.js. This function doesn't exist in Trac 0.11 (see #8942). However, that doesn't seem to be your primary problem here.Yeah, I can live without folding. Hmmm, I wonder if that needs to be protected by a
try
?
No, that call seems safe:
if ($.inArray('foldable', group['properties']) != -1) { $('legend', fieldset).enableFolding($.inArray('collapsed', group['properties']) != -1, true); }
comment:18 follow-up: 19 Changed 12 years ago by
Replying to ChrisNelson:
However, the page source includes:
<script type="text/javascript" src="/mytrac/chrome/groupticketfields/group_ticket_fields.js"></script>
I had not (re)deployed static resources. When I do that the script loads and executes but doesn't quite do what I expect. It moves one label but not the corresponding field and ignores the rest of the fields. Maybe it encountered an error.
comment:19 Changed 12 years ago by
Replying to ChrisNelson:
I had not (re)deployed static resources. When I do that the script loads and executes but doesn't quite do what I expect. It moves one label but not the corresponding field and ignores the rest of the fields. Maybe it encountered an error.
I'm reaching here, but I seem to remember several of the ticket form IDs being renamed between 0.11 and 0.12, and having to fix some problems in another plugin with the stream filter not operating as expected in 0.12 as a result.
comment:20 follow-up: 22 Changed 12 years ago by
The Group Ticket Fields JavaScript seems to go off into the weeds at line 58:
var value_td = $('td').has('#' + field_id); // get the <td>
When I set a breakpoint there and at 59 and continue from 58, I never get to 59.
I'm left with a partially modified ticket:
<legend>Relationships</legend><table id="table_relationships"><tbody><tr><th style="display: table-cell;" class="col1"> <label for="field-parents">Parent Ticket:</label> </th></tr></tbody></table>
Given that piece of the page, I don't see what "td" it is supposed to get, there isn't one. Is it searching for the <td> where the field was originally populated? That I can find in the page source just fine.
This is getting into jQuery territory I'm not familiar with. Maybe I need to give up.
comment:22 follow-up: 23 Changed 12 years ago by
Replying to ChrisNelson:
This is getting into jQuery territory I'm not familiar with. Maybe I need to give up.
We've come too far to give up ;) I'm setting up to test in 0.11 and 0.12.
comment:23 Changed 12 years ago by
comment:24 Changed 11 years ago by
Owner: | changed from Christopher Paredes to falkb |
---|
comment:25 Changed 11 years ago by
comment:26 Changed 10 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
giving up support of Trac older than 0.12
Version of SimpleMultiProjects? plugin - 0.0.3