ProdPageTemplates.plug in.py :  » IDE » Boa-Constructor » boa-constructor-0.6.1 » Plug-ins » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » IDE » Boa Constructor 
Boa Constructor » boa constructor 0.6.1 » Plug ins » ProdPageTemplates.plug-in.py
import os, sys

import Preferences, Utils, Plugins

if not Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
    raise Plugins.SkipPlugin, 'Zope support is not enabled'

#---Model-----------------------------------------------------------------------

# Define new zope image and a Model for opening in the Editor
from ZopeLib.ZopeEditorModels import addZOAImage,ZOAIcons,ZopeDocumentModel,ZopeController
import Models
from Models import Controllers,EditorHelper
from Models.HTMLSupport import HTMLFileModel,HTMLFileController,HTMLFileView

addZOAImage('Page Template', 'Images/ZOA/ZopePageTemplate.png')
addZOAImage('Filesystem Page Template', 'Images/ZOA/ZopePageTemplate.png')

class ZopePageTemplateModel(ZopeDocumentModel):
    imgIdx = ZOAIcons['Page Template']

EditorHelper.imgZopePTFSModel = EditorHelper.imgIdxRange()

class ZopePageTemplateFSModel(HTMLFileModel):
    modelIdentifier = 'PageTemplateHTML'
    defaultName = 'pagetemplate'
    bitmap = 'ZopePageTemplate_s.png'
    imgIdx = EditorHelper.imgZopePTFSModel
    ext = '.pt'

EditorHelper.modelReg[ZopePageTemplateFSModel.modelIdentifier] = ZopePageTemplateFSModel
EditorHelper.extMap['.pt'] = ZopePageTemplateFSModel
EditorHelper.extMap['.zpt'] = ZopePageTemplateFSModel

#---Views-----------------------------------------------------------------------

from ZopeLib import ZopeViews

ZopeViews.zope_additional_attributes += \
      'tal tal:block tal:content tal:replace tal:condition tal:attributes '\
      'tal:define tal:repeat tal:omit-tag tal:on-error '\
      'tales '\
      'metal metal:block metal:use-macro metal:define-macro metal:fill-slot '\
      'metal:define-slot '\
      'i18n i18n:translate i18n:attributes '

class ZopePTHTMLView(ZopeViews.ZopeHTMLView):
    viewName = 'Source.html'
    viewTitle = 'Source.html'
    def generatePage(self):
        props = self.model.transport.properties
        url = 'http://%s:%s@%s:%d/%s/source.html'%(props['username'],
              props['passwd'], props['host'], props['httpport'],
              self.model.transport.whole_name())
        import urllib
        f = urllib.urlopen(url)
        return f.read()

#---Controller------------------------------------------------------------------
class PageTemplateZopeController(ZopeController):
    def OnSave(self, event):
        ZopeController.OnSave(self, event)
        # trigger a reload after saving so that errors saved as comments in the
        # source are displayed
        self.OnReload(event)

class PageTemplateFSController(HTMLFileController):
    Model           = ZopePageTemplateFSModel
    DefaultViews    = [ZopeViews.ZopeHTMLSourceView]
    AdditionalViews = [HTMLFileView]

# Connect controller to the model
Controllers.modelControllerReg[ZopePageTemplateModel] = PageTemplateZopeController
Controllers.modelControllerReg[ZopePageTemplateFSModel] = PageTemplateFSController

#---Explorer--------------------------------------------------------------------

# Node in the explorer
from ZopeLib.ZopeExplorer import ZopeNode,zopeClassMap
class PageTemplateNode(ZopeNode):
    Model = ZopePageTemplateModel
    defaultViews = (ZopeViews.ZopeDebugHTMLSourceView,)
    additionalViews = (ZopeViews.ZopeUndoView, ZopeViews.ZopeSecurityView,
                       ZopePTHTMLView, ZopeViews.ZopeHTMLView)
    def save(self, filename, data, mode='wb'):
        self.getResource().pt_upload('', data)

zopeClassMap['Page Template'] = PageTemplateNode

#---Companion-------------------------------------------------------------------

# Companion used for creation from palette and inspection/posting of props
from ZopeLib.ZopeCompanions import CustomZopePropsMixIn,ZopeCompanion
class PageTemplateZC(CustomZopePropsMixIn, ZopeCompanion):
    def create(self):
        prodPath = '/manage_addProduct/PageTemplates/'
        mime, res = self.call(self.objPath, prodPath+'manage_addPageTemplate',
              id = self.name, title = '')

    def getProps(self):
        path, name = os.path.split(self.objPath)
        mime, res = self.call(path, 'zoa/props/PageTemplate', name=name)
        return eval(res)

    def SetProp(self, name, value):
        props = self.getProps()
        props[name] = value
        path, name = os.path.split(self.objPath)

        mime, res = self.call(self.objPath, 'pt_editAction',
            title = props['title'],
            text = self.call(self.objPath, 'document_src'),
            content_type = props['content_type'],
            expand = props['expand'])

    propOrder = ('title', 'content_type', 'expand')
    propTypeMap = {'title':       ('string', 'title'),
                   'content_type':('string', 'content_type'),
                   'expand':      ('boolean', 'expand'),
                  }

# Add to the Zope palette
import PaletteStore
PaletteStore.paletteLists['Zope'].append('Page Template')
PaletteStore.compInfo['Page Template'] = ['ZopePageTemplate', PageTemplateZC]
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.