Just to kind of close this. After thinking about it, maybe the
current functionality is more correct than what I was trying for.
My problem seems to be in here:
29 def _process_output(output, template, format, content_type,
mapping, fragment=False):
...
51 for value in output.itervalues():
52 if hasattr(value, "retrieve_css"):
53 retrieve = getattr(value, "retrieve_css")
54 if callable(retrieve):
55 css.add_all(value.retrieve_css())
56 if hasattr(value, "retrieve_javascript"):
57 retrieve = getattr(value, "retrieve_javascript")
58 if callable(retrieve):
59 for script in value.retrieve_javascript():
60 if hasattr(script, "location"):
61 js[script.location].add(script)
62 else:
63 js[js_location.head].add(script)
An array or dictionary does not have a retrieve_css,
retrieve_javascript attribute so it just gets skipped when pulling css
and javascript. I kind of like how I do things now but I guess there
is no real reason to do it.
Thanks.
-Ian
On 9/15/06, Ian Wilson <[EMAIL PROTECTED]> wrote:
> The widget itself displays fine and sadly enough I use dictionaries
> all over the place with widgets in them. Just the CSS does not get
> included for some reason. My original example was terrible I'm sorry.
>
> So let's say I extend a TextField like this:
>
> class MyTextField(TextField):
> css = [CSSLink("tester.widgets.css", "mytextfield.css")]
>
> And then use a form like this:
>
> form = TableForm(name="form", fields=[MyTextField()], submit_text="Save")
>
> Now here is the problem(two cases of returning to a template):
>
> controller
>
> widget, widgetData = {}, {}
> widget['form'] = form
> widgetData['form'] = {}
> return dict(widget=widget, widgetData=widgetData)
>
> template
>
> ${widget['form'](**widgetData['form'])}
>
> out
>
> <HEAD><META CONTENT="text/html; charset=utf-8" HTTP-EQUIV="Content-Type">
>
>
> <STYLE TYPE="text/css">
> #pageLogin
> {
> font-size: 10px;
> font-family: verdana;
> text-align: right;
> }
> </STYLE>
> </HEAD>
>
> ---------------------VERSUS----------------------
>
> controller
>
> widget = form
> widgetData = {}
> return dict(widget=widget, widgetData=widgetData)
>
> template
>
> ${widget(**widgetData)}
>
> out
> <HEAD><META CONTENT="text/html; charset=utf-8" HTTP-EQUIV="Content-Type">
> <LINK MEDIA="all"
> HREF="/tg_widgets/tester.widgets.css/mytextfield.css" TYPE="text/css"
> REL="stylesheet">
>
>
> <STYLE TYPE="text/css">
> #pageLogin
> {
> font-size: 10px;
> font-family: verdana;
> text-align: right;
> }
> </STYLE>
> </HEAD>
>
>
> In both cases the actual widget displays fine, but in only one does
> the css get included in the html block HEAD.
>
> Thanks.
>
> -Ian
>
> On 9/15/06, Jorge Godoy <[EMAIL PROTECTED]> wrote:
> >
> > "Ian Wilson" <[EMAIL PROTECTED]> writes:
> >
> > > Do I really have to pass all the widgets as explict members of the return
> > > dict?
> >
> > Hmmm... No, you don't.
> >
> > In [1]:from turbogears import widgets
> >
> > In [2]:a = [widgets.TextField(name='widget_a'),
> > widgets.CheckBox(name='widget_b')]
> >
> > In [3]:a
> > Out[3]:
> > [TextField(name='widget_a', convert=True, field_class='textfield',
> > attrs={}, css_classes=[]),
> > CheckBox(name='widget_b', convert=True, field_class='checkbox', attrs={},
> > css_classes=[])]
> >
> > In [4]:a[0].render()
> > Out[4]:'<INPUT ID="widget_a" TYPE="text" CLASS="textfield" NAME="widget_a">'
> >
> > In [5]:a[1].render()
> > Out[5]:'<INPUT CLASS="checkbox" TYPE="checkbox" ID="widget_b"
> > NAME="widget_b">'
> >
> >
> > As you can see, they can be wrapped on a list. Lets try a dict:
> >
> > In [6]:d = dict(widget_a = a[0], widget_b=a[1])
> >
> > In [7]:d['widget_a'].render()
> > Out[7]:'<INPUT ID="widget_a" TYPE="text" CLASS="textfield" NAME="widget_a">'
> >
> > In [8]:d['widget_b'].render()
> > Out[8]:'<INPUT CLASS="checkbox" TYPE="checkbox" ID="widget_b"
> > NAME="widget_b">'
> >
> >
> > So they can also be in a dictionary.
> >
> >
> > Does it help?
> >
> > --
> > Jorge Godoy <[EMAIL PROTECTED]>
> >
> > > >
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---