Exemple #1
0
 def handleSave(self, action):
     data, errors = self.extractData()
     if errors:
         self.status = self.formErrorsMessage
         return
     
     title = data['title']
     description = data['description']
     defaultSiteLayout = data['defaultSiteLayout']
     defaultPageLayoutTemplate = data['defaultPageLayoutTemplate']
     
     portal_types = getToolByName(self.context, 'portal_types')
     
     name = basename = getUtility(IIDNormalizer).normalize(title)
     idx = 1
     while name in portal_types:
         name = "%s-%d" % (basename, idx,)
         idx += 1
     
     clonePageType(portal_types, self.defaultType, name,
             title=title,
             description=description,
             default_site_layout=defaultSiteLayout,
             default_page_layout_template=defaultPageLayoutTemplate,
         )
     
     IStatusMessage(self.request).add(_(u"Page type added"), type="info")
     self.request.response.redirect(self.context.absolute_url() + "/@@deco-controlpanel")
Exemple #2
0
    def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return
        
        name = data['name']
        title = data['title']
        description = data['description']
        content = data['content']
        filename = data['filename']
        
        title = title.encode('utf-8')
        description = description.encode('utf-8')
        
        directory = queryResourceDirectory(SITE_LAYOUT_RESOURCE_NAME, name)
        directory.writeFile(MANIFEST_FILENAME, """\
[%s]
title = %s
description = %s
file = %s
""" % (SITE_LAYOUT_RESOURCE_NAME, title or '', description or '', filename))

        directory.writeFile(filename, content)
        
        IStatusMessage(self.request).add(_(u"Changes saved"), type="info")
        self.request.response.redirect(self.context.absolute_url() + "/@@deco-controlpanel")
Exemple #3
0
class IFieldTile(Interface):
    """Interface for the field tile configuration in the registry
    """
    id = schema.TextLine(title=_(u"The widget id"))
    name = schema.TextLine(title=_(u"Name"))
    label = schema.TextLine(title=_(u"Label"))
    category = schema.TextLine(title=_(u"Category"))
    tile_type = schema.TextLine(title=_(u"Type"))
    read_only = schema.Bool(title=_(u"Read only"))
    favorite = schema.Bool(title=_(u"Favorite"))
    widget = schema.TextLine(title=_(u"Field widget"))
    available_actions = schema.List(title=_(u"Actions"),
                                    value_type=schema.TextLine())
Exemple #4
0
class IAction(Interface):
    name = schema.TextLine(title=_(u"Name"))
    fieldset = schema.TextLine(title=_(u"Fieldset"))
    label = schema.TextLine(title=_(u"Label"))
    action = schema.TextLine(title=_(u"Action"))
    icon = schema.Bool(title=_(u"Icon"))
    menu = schema.Bool(title=_(u"Menu"))
    weight = schema.Int(title=_(u"Weight"))
Exemple #5
0
class IFormat(Interface):
    """Interface for the format configuration in the registry"""
    name = schema.TextLine(title=_(u"Name"))
    category = schema.TextLine(title=_(u"Category"))
    label = schema.TextLine(title=_(u"Label"))
    action = schema.TextLine(title=_(u"Action"))
    icon = schema.Bool(title=_(u"Icon"))
    favorite = schema.Bool(title=_(u"Favorite"))
    weight = schema.Int(title=_(u"Weight"))
Exemple #6
0
 def __call__(self):
     
     self.errors = {}
     
     if self.request.method == 'POST':
         CheckAuthenticator(self.request)
     
     catalog = getToolByName(self.context, 'portal_catalog')
     
     form = self.request.form
     
     if 'form.button.SaveGeneral' in form:
         name = form.get('defaultSiteLayout')
         directory = queryResourceDirectory(SITE_LAYOUT_RESOURCE_NAME, name)
         if directory is None:
             IStatusMessage(self.request).add(_(u"Cannot find resource directory"), type="error")
         else:
             
             filename = SITE_LAYOUT_FILE_NAME
             
             if directory.isFile(MANIFEST_FILENAME):
                 manifest = getManifest(directory.openFile(MANIFEST_FILENAME), SITE_LAYOUT_MANIFEST_FORMAT)
                 filename = manifest.get('file', filename)
             
             registry = getUtility(IRegistry)
             registry['plone.defaultSiteLayout'] = "./++%s++%s/%s" % \
                     (SITE_LAYOUT_RESOURCE_NAME, name, filename)
             
             IStatusMessage(self.request).add(_(u"Default site layout updated"), type="info")
         
     elif 'form.button.DeletePageType' in form:
         portal_type = form.get('name')
         if portal_type == DEFAULT_PAGE_TYPE_NAME:
             IStatusMessage(self.request).add(_(u"Cannot delete the default page type"), type="error")
         elif len(catalog({'portal_type': portal_type})) > 0:
             IStatusMessage(self.request).add(_(u"Cannot delete a type that is in use"), type="error")
         else:
             portal_types = getToolByName(self, 'portal_types')
             del portal_types[portal_type]
             IStatusMessage(self.request).add(_(u"Type deleted"), type="info")
     
     elif 'form.button.DeleteSiteLayout' in form:
         name = form.get('name')
         resources = getUtility(IResourceDirectory, name='persistent')
         sitelayouts = resources[SITE_LAYOUT_RESOURCE_NAME]
         del sitelayouts[name]
         IStatusMessage(self.request).add(_(u"Site layout deleted"), type="info")
     
     elif 'form.button.DeletePageLayout' in form:
         name = form.get('name')
         resources = getUtility(IResourceDirectory, name='persistent')
         pagelayouts = resources[PAGE_LAYOUT_RESOURCE_NAME]
         del pagelayouts[name]
         IStatusMessage(self.request).add(_(u"Page layout deleted"), type="info")
     
     return self.index()
Exemple #7
0
class ITile(Interface):
    """ Interface for the tile configuration in the registry.
    """

    name = schema.TextLine(
        title=_(u"Name"),
        required=True,
    )
    label = schema.TextLine(
        title=_(u"Label"),
        required=True,
    )
    group = schema.TextLine(
        title=_(u"Group"),
        required=True,
        default=u'default',
    )
    icon = schema.TextLine(
        title=_(u"Label"),
        default=u'++resource++plone.app.deco/default_tile_icon.png',
    )
Exemple #8
0
 def handleSave(self, action):
     data, errors = self.extractData()
     if errors:
         self.status = self.formErrorsMessage
         return
     
     title = data['title']
     description = data['description']
     content = data['content']
     
     createSiteLayout(title, description, content)
     
     IStatusMessage(self.request).add(_(u"Changes saved"), type="info")
     self.request.response.redirect(self.context.absolute_url() + "/@@deco-controlpanel")
Exemple #9
0
 def handleSave(self, action):
     data, errors = self.extractData()
     if errors:
         self.status = self.formErrorsMessage
         return
     
     title = data['title']
     description = data['description']
     defaultSiteLayout = data['defaultSiteLayout']
     defaultPageLayoutTemplate = data['defaultPageLayoutTemplate']
     
     self.context.title = title
     self.context.description = description
     self.context.default_site_layout = defaultSiteLayout
     self.context.default_page_layout_template = defaultPageLayoutTemplate
     
     IStatusMessage(self.request).add(_(u"Changes saved"), type="info")
     
     portal_url = getToolByName(self.context, 'portal_url')
     self.request.response.redirect(portal_url() + "/@@deco-controlpanel")
Exemple #10
0
 def cancel(self, action):
     IStatusMessage(self.request).add(_(u"Operation cancelled"), type="info")
     
     portal_url = getToolByName(self.context, 'portal_url')
     self.request.response.redirect(portal_url() + "/@@deco-controlpanel")
Exemple #11
0
 def cancel(self, action):
     IStatusMessage(self.request).add(_(u"Operation cancelled"), type="info")
     self.request.response.redirect(self.context.absolute_url() + "/@@deco-controlpanel")
Exemple #12
0
class IWeightedDict(Interface):
    name = schema.TextLine(title=_(u"Name"))
    label = schema.TextLine(title=_(u"Label"))
    weight = schema.Int(title=_(u"Weight"))
Exemple #13
0
class IWidgetAction(Interface):
    name = schema.TextLine(title=_(u"Name"))
    actions = schema.List(title=_(u"Actions"), value_type=schema.TextLine())
Exemple #14
0
    def __call__(self):
        context = self.context
        request = self.request

        # Set header to json
        request.response.setHeader('Content-Type', 'application/json')

        ctr_tool = getToolByName(self.context, 'content_type_registry')
        id = request['uploadfile'].filename

        content_type = request['uploadfile'].headers["Content-Type"]
        typename = ctr_tool.findTypeName(id, content_type, "")

        # 1) check if we are allowed to create an Image in folder
        if not typename in [t.id for t in context.getAllowedTypes()]:
            error = {}
            error['status'] = 1
            error['message'] =\
                _(u"Not allowed to upload a file of this type to this folder")
            return json.dumps(error)

        # 2) check if the current user has permissions to add stuff
        if not context.portal_membership.checkPermission('Add portal content',
                                                         context):
            error = {}
            error['status'] = 1
            error['message'] =\
                _(u"You do not have permission to upload files in this folder")
            return json.dumps(error)

        # Get an unused filename without path
        id = self.cleanupFilename(id)

        title = request['uploadfile'].filename

        newid = context.invokeFactory(type_name=typename, id=id)

        if newid is None or newid == '':
            newid = id

        obj = getattr(context, newid, None)

        # Set title
        # Attempt to use Archetypes mutator if there is one,
        # in case it uses a custom storage
        if title:
            try:
                obj.setTitle(title)
            except AttributeError:
                obj.title = title

        # set primary field
        pf = obj.getPrimaryField()
        pf.set(obj, request['uploadfile'])

        if not obj:
            error = {}
            error['status'] = 1
            error['message'] = _(u"Could not upload the file")
            return json.dumps(error)

        obj.reindexObject()
        message = {}
        message['status'] = 0
        message['url'] = obj.absolute_url()
        message['title'] = title
        return json.dumps(message)