/srv/irclogs.ubuntu.com/2009/12/05/#launchpad-dev.txt

=== abentley1 is now known as abentley
adiroibanwhen using context/@@+fragment, is there a nice way to pass GET or POST variables to +fragment ?19:54
=== rockstar is now known as Guest38735
=== rockstar` is now known as rockstar
sinzuiadiroiban: we often add a initial_values property to the view that will provide a dict of sane values for the missing parameters20:17
* sinzui looks for example20:17
sinzuiadiroiban: LaunchpadFormView sets the missing params from the initial_values dict as is done in lp/registry/browser/announcement.py20:20
adiroibansinzui: thanks. I'll take a look20:21
adiroibansinzui: the current view is just a LaunchpadView. I have something realy simple, and I don't want to make it a LaunchpadFormView just for sending one GET variable20:30
adiroibani want to call https://translations.launchpad.dev/ubuntu/hoary/+translations?something20:30
adiroibanand have "something" also visible in https://translations.launchpad.dev/ubuntu/hoary/+langchart20:30
sinzuiadiroiban: I would redefine the views __init__ to call initial_values  and have it inject the values into  view.request.form20:31
* sinzui wonders if that has been done before20:31
adiroibansinzui: I will try20:33
adiroiban:)20:33
sinzuiadiroiban: there are several places where views are doing something like20:37
sinzui    self.request.form['displayname'] = my_value20:37
sinzuito ensure sane data is in the request before a redirect or some handoff to another process. I think doing this in an __init__ is okay.20:37
adiroibanok. I'll try and see what I can get20:38
sinzuiadiroiban: I think you want to check the form using this style:20:39
sinzui   if request.form.get('something', None) is None:20:39
sinzui        request.form['something'] = 'sane default'20:39
adiroibani'm still learning zope and lp... so I don't know if I should pass some flag over HTTP get or encode it in the url20:44
adiroibanalso I still need to read about the lifecycle/lifetime of a zope view component20:46
sinzuiadiroiban: I do not think zope will help you since we are using LaunchpadView and LaunchpadFormView20:49
sinzuiadiroiban: Those views in lib/canonical/launchpad/webapp define all the objects commonly available, the order they are gotten, and process the form data and do validation20:51
sinzuiadiroiban: The only zope knowledge I need to know is zope.formlib when I am doing something very strange in setupFields or setupWidgets. We have some many examples in views now that I do not think you need to learn that from Zope.20:52
adiroibansinzui: thanks.20:54
adiroibanright now I'm trying to so simple things ... but then I still need to learn the LP way of doing things20:55
adiroibanso I have this page: https://translations.launchpad.dev/ubuntu/hoary/+translations?all=yes20:56
adiroibanwhich has an included fragment20:56
sinzuiadiroiban: the general execution path is View __init__ (we  rarely mess with this, but I think you want to in this case) -> initialize (setup form stuff) -> setupFields -> setupWidgets() -> validate -> Actions -> render()20:57
adiroibanand I want to see the "all=yes" value in the fragment20:57
sinzuiadiroiban: Something like this I think:21:00
sinzui    def __init__(self, context, request):21:00
sinzui        super(MYVIEW, self).__init__(context, request)21:00
sinzui        # This view may be included as a portlet using default values.21:00
sinzui        if self.request.form.get('all', None) is None:21:00
sinzui            request.form['all'] = 'yes'21:00
adiroibanok. but in my particular case. I have the same view for the main page and the portlet page ...21:02
adiroibandoes it mean I have to slit them in different views?21:02
sinzuiadiroiban: You could subclass to have different behaviours, but I think this is a case where the view should do the right thing for default and query cases21:07
sinzuiSince setting the form in __init__ is extraordinary, we need a comment to explain that the view is used as a portlet.21:08
adiroibansinzui: think I still need to read more as I have no idea when the __init__ or LaunchpadView.initialize() is called21:09
sinzuiinit is called when the object is created...it is the constructor21:10
adiroibanand when is that . Each time I'm accessing the specific URL ?21:10
sinzuiYes, each time. All objects are garbage collected at the end of the request.21:11
adiroibanand if I have something like this: <div tal:replace="structure view/translation_focus/@@+langchart" />21:12
adiroibanit will not create a new request for that inclusion ?21:12
sinzuiThat is right21:13
adiroibanthen I can no use that trick21:13
sinzuiThe that syntax means: Lookup and execute the adapter for translation_focus (a series) named +langchart21:14
sinzuiadiroiban: why do you need a new request?21:14
adiroibansinzui: I don't need a new request.21:15
adiroibani have distroseries/+translate page21:15
adiroibanthat "includes" the +langchart page21:15
adiroibannow I'm calling +translate?all=yes21:15
adiroibanand I want that "all=yes" to be propagated to +langchart21:16
sinzuiah21:16
sinzuithat is extraordinary21:16
adiroibanmaybe this is not the right way to do it21:17
sinzuiSo you are not seeing the form when the +langchart is called?21:17
adiroibanif it's from +translations , no21:18
adiroibandirect access is OK21:18
adiroibandirect - hacking the URL21:18
sinzuiI think you want to subclass the view then and set the all=yes as I suggested21:19
sinzuiyou want to register the new view as a new name in browser/configure.zcml.21:19
sinzui        <browser:page21:20
adiroibanyep. I can have +translations and +translations-all21:20
sinzui            for="lp.registry.interfaces.distroseries.IDistroSeries"21:20
sinzui            class="lp.translations.browser.distroseries.AllLangsView"21:20
sinzui            name="+alllangchart"21:20
sinzui            template="../templates/distroseries-langchart.pt"/>21:20
adiroibanor +langchart-all ;)21:22
adiroibanso basically, there is no way to pass a HTTP or TAL "variable" to a fragment page?21:24
adiroibanand the only way is to create a new view ?21:24
sinzuiThere is, by way of define a metal macro instead of adapting to a view21:24
adiroibanthen maybe it is best to use a macro?21:27
sinzuiYou would need to rewite the existing template to use the macro. I think that is more work then subclassing and registering21:29
adiroibansinzui: thanks for the help!21:33
adiroibanso to finalize. there is no easy way for something like this: <div tal:replace="structure view/translation_focus/@@+langchart?all=yes" />21:34
adiroibaneasy, trivial21:34
sinzuiI do not think so21:36
adiroibanthe @@+fragment way of include is specific to Zope , or is a LP TALES extension?21:40
sinzuiIt is TALES, which is neither zope or lp21:40
adiroiban:)21:40
sinzuiHere is a quick reference I often use. http://www.owlfish.com/software/simpleTAL/tal-guide.html21:41
sinzuiTALES and METAL are associated with zope, but the engine is not specific to zope any more21:42
adiroibanwell. I will go with the sollution where multiple views are created and I will see what is the feedback from the reviewer :)21:47

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!