Loading ...
Sorry, an error occurred while loading the content.
 

[Cheetahtemplate-discuss] Acquisition

Expand Messages
  • Michel Thadeu
    Hi guys! I want to make something like the zope´s acquisition. In fact, I already done something usable but I wanna suggestions. Look at my idea: I create a
    Message 1 of 2 , Aug 6, 2004
      Hi guys!

      I want to make something like the zope´s acquisition. In fact, I
      already done something usable but I wanna suggestions. Look at my idea:

      I create a general page model, I´ll call it Gmodel.tmpl/py, I have some
      pages based on this model:

      -> Gmodel.tmpl/py
      -> PageA.tmpl/py
      -> PageB.tmpl/py
      -> PageC.tmpl/py

      The model defines some methods, in example _writeBody and writeBody
      (for me, writeBody means writeContent while cheetah, by omission,
      implements writeBody:

      ...
      def _writeBody(self, **kw):
      # do something before showing the body
      self.writeBody(**kw)
      # do something after showing the body
      def writeBody(self, **kw)
      pass
      ...

      I want to use PageA, PageB, PageC on another models, suppose I create
      another model, a specific model called Smodel.tmpl/py:

      -> Smodel.tmpl/py
      -> PageA.py # based on the general model PageA
      -> PageB.py # based on the general model PageB

      If I extends PageA I will have a problem 'cause the page will have the
      general model appearance but I want the specific model appearance. I
      solve this by extending the new PageA from PageA and from Smodel, so
      all method defined in the PageA (not the methods inherited from Gmodel)
      will be used, the other ones come from the Smodel:

      class NewPageA(Gmodel, PageA):
      title=PageA.title
      self.writeBody(self, **kw):
      PageA.writeBody(self, **kw)

      I create a function to automatize this process:

      ...
      def createClass(class1, class2):
      class x(class1, class2):
      title=class2.title
      writeBody=lambda self, **kw: class2.writeBody(self, **kw)
      return x
      ...

      then I can call:

      ...
      from Gmodel import Gmodel
      from PageA import PageA

      PageA=createClass(Gmodel, PageA)
      ...

      There is no problem for pages that reimplement only the title and the
      writeBody, but what about the servlets that reimplement other methods,
      I want to create a function to automatize this too...

      I think to create a class attribute to store what methods should be
      redefined, but these methods are listed on the class one time I write
      it, is there a way to know these methods? Look:

      ...
      class Test(SomeBase):
      def __init__(self, ...):
      pass
      def __str__(self):
      pass
      def test1(self, ...):
      pass
      def teste2(self, ...):
      pass
      ...

      Is there a way to know that I reimplementing __init__, __str__, test1
      and test2 methods?

      Does my idea have a fault, does someone have a better idea, a
      suggestion? Thanks for any help and sorry my poor english :)

      =====
      --
      Michel Thadeu Sabchuk
      Curitiba/PR





      _______________________________________________________
      Yahoo! Acesso Grátis - navegue de graça com conexão de qualidade! Acesse: http://br.acesso.yahoo.com/


      -------------------------------------------------------
      This SF.Net email is sponsored by OSTG. Have you noticed the changes on
      Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
      one more big change to announce. We are now OSTG- Open Source Technology
      Group. Come see the changes on the new OSTG site. www.ostg.com
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Michel Thadeu
      Hi, thanks for helping me! I will read about the mixin too... ... This is the really problem, class1 and class2 are templates, I using the iheritance approach
      Message 2 of 2 , Aug 7, 2004
        Hi, thanks for helping me!

        I will read about the mixin too...

        > > def createClass(class1, class2):
        > > class x(class1, class2):
        > > title=class2.title
        > > writeBody=lambda self, **kw: class2.writeBody(self, **kw)
        > > return x
        > > ...
        >
        > You can do that? Cool.
        >
        > If you list class2 first ( class x(class2, class1) ), doesn't
        > class2's
        > attributes/methods automatically override class1's? Then you
        > wouldn't
        > have to assign them explicitly.

        This is the really problem, class1 and class2 are templates, I using
        the iheritance approach with cheetah so all my pages are templates or
        based on templates...

        Suposse I have the follow servlets:

        #-- module BaseSite --
        class Model(Template):
        # this model defines a standard look-and-feel
        ...
        class Main(Model):
        title='main page'
        def writeBody(self):
        ...
        class Search(Model):
        title='search page'
        def writeBody(self):
        ...
        def searchMethod(self):
        ...
        #----

        And suppose I have another site in another module:

        #-- module GreenSite --
        class Model(Template):
        # this model defines a green look-and-feel
        ...
        Main=createClass(Model, BaseSite.Main)
        Search=createClass(Model, BaseSite.Search)
        #-----

        This way the Main and Search class on the GreenSite will be the same
        of
        the BaseSite, but with green look-and-feel. For Main it's ok 'cause
        Main have only title and writeBody defined (the class have all method
        inherited from BaseSite.Model but I don't care about this modules).

        The Search class will be a problem for me, it haves a method called
        searchMethod, this method is not listed on my function, so I need to
        write another function that works with searchMethod method.

        Again, can I know what methods I am reimplementing on determined
        class?
        Suppose the Search class:

        #-----
        class Search(Model):
        title='some specific title'
        reversedOrder=True # to know if the order will be reversed i.e.
        def writeBody(self, **kw):
        ...
        def getQuery(self):
        ...
        def searchMethod(self):
        ...
        #-----

        I want to have a list with [title, reversedOrder, writeBody,
        getQuery,
        searchMethod], but only these method, not Model inherited methods,
        understand? This way I can create the function that gets a model or a
        template and put on it only the right methods...

        thanks for all help and sorry my poor english :)

        =====
        --
        Michel Thadeu Sabchuk
        Curitiba/PR





        _______________________________________________________
        Yahoo! Acesso Grátis - navegue de graça com conexão de qualidade! Acesse: http://br.acesso.yahoo.com/


        -------------------------------------------------------
        This SF.Net email is sponsored by OSTG. Have you noticed the changes on
        Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
        one more big change to announce. We are now OSTG- Open Source Technology
        Group. Come see the changes on the new OSTG site. www.ostg.com
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      Your message has been successfully submitted and would be delivered to recipients shortly.