=== abentley1 is now known as abentley | ||
adiroiban | when 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 | ||
sinzui | adiroiban: we often add a initial_values property to the view that will provide a dict of sane values for the missing parameters | 20:17 |
* sinzui looks for example | 20:17 | |
sinzui | adiroiban: LaunchpadFormView sets the missing params from the initial_values dict as is done in lp/registry/browser/announcement.py | 20:20 |
adiroiban | sinzui: thanks. I'll take a look | 20:21 |
adiroiban | sinzui: 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 variable | 20:30 |
adiroiban | i want to call https://translations.launchpad.dev/ubuntu/hoary/+translations?something | 20:30 |
adiroiban | and have "something" also visible in https://translations.launchpad.dev/ubuntu/hoary/+langchart | 20:30 |
sinzui | adiroiban: I would redefine the views __init__ to call initial_values and have it inject the values into view.request.form | 20:31 |
* sinzui wonders if that has been done before | 20:31 | |
adiroiban | sinzui: I will try | 20:33 |
adiroiban | :) | 20:33 |
sinzui | adiroiban: there are several places where views are doing something like | 20:37 |
sinzui | self.request.form['displayname'] = my_value | 20:37 |
sinzui | to 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 |
adiroiban | ok. I'll try and see what I can get | 20:38 |
sinzui | adiroiban: 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 |
adiroiban | i'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 url | 20:44 |
adiroiban | also I still need to read about the lifecycle/lifetime of a zope view component | 20:46 |
sinzui | adiroiban: I do not think zope will help you since we are using LaunchpadView and LaunchpadFormView | 20:49 |
sinzui | adiroiban: 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 validation | 20:51 |
sinzui | adiroiban: 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 |
adiroiban | sinzui: thanks. | 20:54 |
adiroiban | right now I'm trying to so simple things ... but then I still need to learn the LP way of doing things | 20:55 |
adiroiban | so I have this page: https://translations.launchpad.dev/ubuntu/hoary/+translations?all=yes | 20:56 |
adiroiban | which has an included fragment | 20:56 |
sinzui | adiroiban: 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 |
adiroiban | and I want to see the "all=yes" value in the fragment | 20:57 |
sinzui | adiroiban: 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 |
adiroiban | ok. but in my particular case. I have the same view for the main page and the portlet page ... | 21:02 |
adiroiban | does it mean I have to slit them in different views? | 21:02 |
sinzui | adiroiban: 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 cases | 21:07 |
sinzui | Since setting the form in __init__ is extraordinary, we need a comment to explain that the view is used as a portlet. | 21:08 |
adiroiban | sinzui: think I still need to read more as I have no idea when the __init__ or LaunchpadView.initialize() is called | 21:09 |
sinzui | init is called when the object is created...it is the constructor | 21:10 |
adiroiban | and when is that . Each time I'm accessing the specific URL ? | 21:10 |
sinzui | Yes, each time. All objects are garbage collected at the end of the request. | 21:11 |
adiroiban | and if I have something like this: <div tal:replace="structure view/translation_focus/@@+langchart" /> | 21:12 |
adiroiban | it will not create a new request for that inclusion ? | 21:12 |
sinzui | That is right | 21:13 |
adiroiban | then I can no use that trick | 21:13 |
sinzui | The that syntax means: Lookup and execute the adapter for translation_focus (a series) named +langchart | 21:14 |
sinzui | adiroiban: why do you need a new request? | 21:14 |
adiroiban | sinzui: I don't need a new request. | 21:15 |
adiroiban | i have distroseries/+translate page | 21:15 |
adiroiban | that "includes" the +langchart page | 21:15 |
adiroiban | now I'm calling +translate?all=yes | 21:15 |
adiroiban | and I want that "all=yes" to be propagated to +langchart | 21:16 |
sinzui | ah | 21:16 |
sinzui | that is extraordinary | 21:16 |
adiroiban | maybe this is not the right way to do it | 21:17 |
sinzui | So you are not seeing the form when the +langchart is called? | 21:17 |
adiroiban | if it's from +translations , no | 21:18 |
adiroiban | direct access is OK | 21:18 |
adiroiban | direct - hacking the URL | 21:18 |
sinzui | I think you want to subclass the view then and set the all=yes as I suggested | 21:19 |
sinzui | you want to register the new view as a new name in browser/configure.zcml. | 21:19 |
sinzui | <browser:page | 21:20 |
adiroiban | yep. I can have +translations and +translations-all | 21: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 |
adiroiban | or +langchart-all ;) | 21:22 |
adiroiban | so basically, there is no way to pass a HTTP or TAL "variable" to a fragment page? | 21:24 |
adiroiban | and the only way is to create a new view ? | 21:24 |
sinzui | There is, by way of define a metal macro instead of adapting to a view | 21:24 |
adiroiban | then maybe it is best to use a macro? | 21:27 |
sinzui | You would need to rewite the existing template to use the macro. I think that is more work then subclassing and registering | 21:29 |
adiroiban | sinzui: thanks for the help! | 21:33 |
adiroiban | so to finalize. there is no easy way for something like this: <div tal:replace="structure view/translation_focus/@@+langchart?all=yes" /> | 21:34 |
adiroiban | easy, trivial | 21:34 |
sinzui | I do not think so | 21:36 |
adiroiban | the @@+fragment way of include is specific to Zope , or is a LP TALES extension? | 21:40 |
sinzui | It is TALES, which is neither zope or lp | 21:40 |
adiroiban | :) | 21:40 |
sinzui | Here is a quick reference I often use. http://www.owlfish.com/software/simpleTAL/tal-guide.html | 21:41 |
sinzui | TALES and METAL are associated with zope, but the engine is not specific to zope any more | 21:42 |
adiroiban | well. 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!