Modify

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 Ryan J Ollos)

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 Volodymyr.Koval

Version of SimpleMultiProjects? plugin - 0.0.3

comment:2 Changed 12 years ago by 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.

comment:3 Changed 12 years ago by falkb

This ticket is related to #10078

comment:4 in reply to:  2 Changed 12 years ago by Ryan J Ollos

Description: modified (diff)

comment:5 Changed 12 years ago by 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:

http://trac-hacks.org/changeset/11247 and http://trac-hacks.org/ticket/9764

Thanks a lot, stored here now. Need some time...

comment:6 in reply to:  5 Changed 12 years ago by Jun Omae

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 in reply to:  2 Changed 12 years ago by Chris Nelson

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'): 
    108108    req.chrome.setdefault('scripts', []).append(script)
    109109    scriptset.add(filename)
    110110
     111# Backported from 0.12
     112def 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
    111123def add_javascript(req, filename):
    112124    """Deprecated: use `add_script()` instead."""
    113125    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 Changed 12 years ago by Ryan J Ollos

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 in reply to:  8 ; Changed 12 years ago by Chris Nelson

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 a to_json function.

The former is easy. The latter seems a slippery slope.

  • to_json is in presentation.py
  • It relies on dumps from json or to_js_string from util.text.
    • In 0.11.6, there is no to_js_string in util.text
    • I'm in Python 2.6.5 and that has dumps so that may work but I don't know how far back

comment:10 Changed 12 years ago by falkb

IIRC json.dumps is available since Python 2.6 (also read here). But look here for how to code a compat switch.

comment:11 in reply to:  9 ; Changed 12 years ago by Chris Nelson

Replying to ChrisNelson:

The former is easy. The latter seems a slippery slope.

  • to_json is in presentation.py
  • It relies on dumps from json or to_js_string from util.text.
    • In 0.11.6, there is no to_js_string in util.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 in reply to:  11 Changed 12 years ago by Ryan J Ollos

Replying to ChrisNelson:

Now I'm stuck. I have to_json in presentation.py but how do I *import* it into layout.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 Chris Nelson

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 Changed 12 years ago by Chris Nelson

However, the page source includes:

<script type="text/javascript" src="/mytrac/chrome/groupticketfields/group_ticket_fields.js"></script>

comment:15 Changed 12 years ago by Ryan J Ollos

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 in reply to:  15 ; Changed 12 years ago by Chris Nelson

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 in reply to:  16 Changed 12 years ago by Chris Nelson

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 in reply to:  14 ; Changed 12 years ago by Chris Nelson

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 in reply to:  18 Changed 12 years ago by Ryan J Ollos

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 Changed 12 years ago by Chris Nelson

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:21 Changed 12 years ago by Chris Nelson

See also #10468.

comment:22 in reply to:  20 ; Changed 12 years ago by Ryan J Ollos

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 in reply to:  22 Changed 12 years ago by Ryan J Ollos

Replying to rjollos:

We've come too far to give up ;) I'm setting up to test in 0.11 and 0.12.

Well, nevermind. I had meant to comment on #10468, and was going to take a crack at getting that working, but since the issue is solved now, I won't worry about it.

comment:24 Changed 11 years ago by falkb

Owner: changed from Christopher Paredes to falkb

comment:25 Changed 11 years ago by falkb

(In [12999]) blindly tried backport to Trac 0.11, I don't have it installed, please report back (refs #10515, refs #10240, refs #10078)

comment:26 Changed 10 years ago by falkb

Resolution: wontfix
Status: newclosed

giving up support of Trac older than 0.12

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain falkb.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.