On 8 Jul 2015, at 13:33, Andrzej Ostrowski wrote:
Hi,
I'm playing around with devpi themes. My goal is to create a nice theme for my company. I'd like to add extra information to some pages, like the index page or the main page. I added a snippet of code which produces an "index inheritance diagram" on each index page display.
Because the company I work for is not that small, these diagrams can get strange. A sample diagram: index inheritance diagram <https://lh3.googleusercontent.com/--9yr5WSohOc/VZ0BL6xN3YI/AAAAAAAAAAs/8wZq4...>. Each box is an index, I intentionally removed all user and index names, except for root/pypi. It's not my indices, please don't judge me for the design :)
I'm concerned about performance here. First of all, currently I generate those on display action, which doesn't seem the way to go. Could devpi provide a hook so that I'm able to regenerate a diagram on an index update event?
I'm looking into that. For now you could use the _sro method of a stage. It returns a list of stage objects. With something like ','.join(x.name for x in self._sro()) you could build a unique string which you can then hash with something like md5 to build a cache key. Either put the cache into a thread local or onto the filesystem.
Additionally, I'd like to add more information to an index page and the root pages. So the question is: Could functions in devpi_web.views expose more data in get_index() and root()? Potentially other functions? I know I can always get the data with python snippets in the templates, but it all takes precious time.
For instance, in my company, some indices are regular user indices, some of them are project indices. I'd like to sort the list of indices on the root page: display the project ones first, and user indices below.
The way I would see this is the custom_data property of an index.
The bottom line: I think people could easily create fancier themes if the devpi web views functions exposed more data to the templates, even if that data is not used in the default theme. It would be great to get the full indexconfig json structure for each index in both get_index() and root() functions from devpi_web.views module.
Now I'm not sure how much more data others might want to get there. I hope these things make sense.
Any thoughts?
For this you can use regular Pyramid functionality. With the devpiserver_pyramid_configure hook you can write a plugin that adds configuration to Pyramid. It is used by devpi-web itself. One way to add additional things is add_request_method. The request also has access to the context of the view. This is also used by devpi-web. See http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/hooks.html... Another way is the Before Render Event: http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/hooks.html... With that you have access to the dictionary that is returned by a view. It looks like you also have access to more information: http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/templates.... I haven't used this method myself yet, but it looks promising if you need access to all the info as in your example. With these you have access to all the internals, but won't have a guaranteed API. I can't say how stable the various parts will be, we don't want to lock ourself in by promising a stable API at this point. I hope this helps you. Feel free to ask more questions as needed. Regards, Florian Schulze