On Thursday 27 April 2006 13:09, Igor Murashkin wrote:
> Very cool, are you doing some magic for the "Page Properties" feature
> (where you can CRUD it), so as to make it as easy as defining a few new
> models when someone wants to make a different type of page?

In the end TG-Content will use Widgets and each controller will define a _form 
which can be a prepended/appended or otherwise modified copy of the parent 
classes' _form.  TG-Content uses a lot of inheritance, both in the model and 
controller:

## From: content.components.model

class Atom(InheritableSQLObject):
  class sqlmeta:
    table = "atom"

  Name          = UnicodeCol(length=255)
  Title         = UnicodeCol(length=255)
  Description   = UnicodeCol(default=None)
  Navigable     = BoolCol(default=True)
  Keywords      = RelatedJoin('Keyword')
  Author        = ForeignKey('Account', default=None)
  Effective     = DateTimeCol(default=None)
  Expiration    = DateTimeCol(default=None)
  Created       = DateTimeCol(default=datetime.now)
  Updated       = DateTimeCol(default=datetime.now)
  Language      = ForeignKey('Language', default=None)
  Copyright     = UnicodeCol(default = None)
  Related       = RelatedJoin('Atom', intermediateTable="related_atoms",
        joinColumn='atom', otherColumn='related', addRemoveName="Relation")
        
class Page(Atom):
  class sqlmeta:
    table = "pages"

  Content       = UnicodeCol(default=None)
  Type          = UnicodeCol(length=200, default="application/xhtml+xml")
  Related       = RelatedJoin('Atom', intermediateTable="page_related")

class Folder(Atom):
  class sqlmeta:
    table = "folders"
        
  DefaultView   = EnumCol(enumValues=['error', 'summary', 'list'],
        default='summary')
  DefaultAtom   = ForeignKey('Atom', default=None)
  #Children     = --- insert crazy code here ---

class File(Atom):
  class sqlmeta:
   table = "files"
        
  Type          = UnicodeCol(length=200, default="application/octet-stream")
  Data          = BLOBCol(length=2**32-1, default=None)

## From: shopping.model

class Product(model.Page):
  class sqlmeta:
    table = "products"

  Price         = CurrencyCol(default=None)
  Stock         = IntCol(default=None)
  #...

## From: content.components.controllers

class Atom(Controller):
  def __init__(self, id, path = None, parent = None):
    self.id = id
    self.path = path
    self.parent = parent

  @turbogears.expose()
  def _remove(self, name, id):
    pass # ... delete DB and controller tree records

  @turbogears.expose(html=".templates.Atom.properties")
  @content.expose()
  def _properties(self, *args, **kwargs):
    pass # ... update properties

class Page(Atom):
  @turbogears.expose()
  def index(self, **kwargs):
    return self._view(**kwargs)

  @turbogears.expose(html=".templates.Page.view")
  @content.expose()
  def _view(self):
    return dict()

  @turbogears.expose(html=".templates.Page.modify")
  @content.expose()
  def _modify(self, **kwargs):
    pass # ... perform update stuff

  @turbogears.expose(html=".templates.Page.download")
  def _source(self):
    """Display a very simple representation of the page."""
    node = model.Atom.get(self.id)
    return dict(controller=self, node=node)

class Folder(Atom):
  @turbogears.expose()
  def index(self, **kwargs):
    pass # ... display listing, default atom, or error

  @turbogears.expose(html=".templates.Folder.modify")
  @content.expose()
  def _modify(self, **kwargs):
    pass # ... perform update stuff

  @turbogears.expose(html=".templates.Folder.create")
  @content.expose()
  def _create(self, **kwargs):
    pass # ... create a new element filling only base properties, then
    # redirect to _modify.

  @turbogears.expose(html=".templates.Folder.contents")
  @content.expose()
  def _contents(self, style='summary'):
    return dict(style=style)

  @turbogears.expose()
  def _sort(self, order):
    pass # ... ajax drag-n-drop sort handler

class RootController(Folder, turbogears.controllers.RootController):
  """Content-managed site root.  Inherit your root from this."""
  def __init__(self):
    root = model.Folder.get(1)
    Folder.__init__(self, 1, "/", None)
    controllers.descend(self, root, parent_class=self)

  @turbogears.expose(html=".templates.sitemap")
  def sitemap_xml(self):
    pass # ... generate Google Sitemap

  @turbogears.expose(html=".templates.authenticate")
  def _authenticate(self, forward_url=None, previous_url=None, *args,
        **kwargs):
    pass # ... handle identity signin/signout requests

## From: shopping.controllers

class Product(controllers.Page):
  @turbogears.expose(html=".templates.Product.view")
  @content.expose()
  def _view(self):
    return dict()

  @turbogears.expose(html=".templates.Product.modify")
  @content.expose()
  def _modify(self, **kwargs):
    pass # ... handle product-specific updates then cascade to Page._modify.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to