On Tue, 26 Sep 2006 21:41:50 +0200, Markus Schiltknecht <[EMAIL PROTECTED]> 
wrote:
Thus I think neither Valentino's efforts nor yours are all wasted. And I hope he, you or other nevow hackers still has enough patience to answer my questions.

We always have, although we are a bunch of assholes too. :).

I'm tempted to write a docFactory which compiles a template from multiple files, instead of using macros. That could automatically include all the 'switches' in the template and the designer would not have to hard-wire all children by hand. This would already serve my needs, I guess. Would this still count as 'nevow like' or is it a no-no-no?

This is indeed more nevow-like. When you are in doubt try to work at the lowest level possible because the new behavior will be inherited by the upper layers (that's why I was suggesting to work at the template layer before).


from nevow import rend, loaders, tags as T, inevow, static

class BasePage(rend.Page):
    docFactory = loaders.xmlfile('templates/common.html')
    title = 'per page title'
    main_menu = 1

    def render_title(self, ctx, data):
        ctx.fillSlots('title', self.title)
        return ctx

ctx.tag.fillSlots(...)
return ctx.tag

    def render_switch(self, attr):
        assert(attr is not None)
        def _(ctx, data):
            if hasattr(self, attr) and self.__getattribute__(attr):

It's not clear to me what this is for. but in general it's never a good
idea to use special methods directly. In this case you could have done:

getattr(self, attr, default_value)

                return ctx

Again: ctx.tag

            else:
                return ()
        return _

class ContactInfoPage(BasePage):
    pass

class ContactPage(BasePage):
    addSlash = True
    child_info = ContactInfoPage

def child_info(self, ctx):
   return ContactInfoPage()

class ProductsPage(BasePage):
    addSlash = True
    products = True

class EnterPage(BasePage):
    pass

class RootPage(BasePage):
    addSlash = True
    default_background = 1
    main_menu = 0
    child_kontakt = ContactPage
    child_products = ProductsPage

    child_layout = static.File('layout')
    child_enter = EnterPage()

Same as above, define functions instead.

_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to