Ejemplo n.º 1
0
Archivo: form.py Proyecto: goschtl/zope
    def _setRedirect(self, provider_id, action_path, keys=''):
        provider = getToolByName(self.context, provider_id)
        try:
            target = provider.getActionInfo(action_path, self.context,
                                            check_condition=1)['url']
        except (ValueError, zExceptions_Unauthorized):
            target = self._getPortalURL()

        kw = {}
        if self.status:
            message = translate(self.status, self.context)
            if isinstance(message, unicode):
                message = message.encode(self._getBrowserCharset())
            kw['portal_status_message'] = message
        for k in keys.split(','):
            k = k.strip()
            v = self.request.form.get(k, None)
            # filter out keys without values or with redundant default values
            if v and v != '0':
                kw[k] = v

        query = kw and ('?%s' % make_query(kw)) or ''
        self.request.RESPONSE.redirect('%s%s' % (target, query))

        return ''
Ejemplo n.º 2
0
    def nextURL(self):
        obj = self._added_obj

        message = translate(self.status, self.context)
        if isinstance(message, unicode):
            message = message.encode(self._getBrowserCharset())
        return "%s/%s?%s" % (obj.absolute_url(), self.ti.immediate_view, make_query(portal_status_message=message))
Ejemplo n.º 3
0
Archivo: form.py Proyecto: goschtl/zope
    def add(self, obj):
        container = self.context
        portal_type = self.ti.getId()

        # check allowed (sometimes redundant, but better safe than sorry)
        if not self.ti.isConstructionAllowed(container):
            raise AccessControl_Unauthorized('Cannot create %s' % portal_type)

        #check container constraints
        ttool = self._getTool('portal_types')
        container_ti = ttool.getTypeInfo(container)
        if container_ti is not None and \
                not container_ti.allowType(portal_type):
            raise ValueError('Disallowed subobject type: %s' % portal_type)

        name = INameChooser(container).chooseName(obj.getId(), obj)
        obj.id = name
        container._setObject(name, obj)
        obj = container._getOb(name)

        obj_type = translate(obj.Type(), container)
        self.status = _(u'${obj_type} added.', mapping={'obj_type': obj_type})
        self._finished_add = True
        self._added_obj = obj
        return obj
Ejemplo n.º 4
0
    def _setRedirect(self, provider_id, action_path, keys=''):
        provider = getToolByName(self.context, provider_id)
        try:
            target = provider.getActionInfo(action_path,
                                            self.context,
                                            check_condition=1)['url']
        except (ValueError, zExceptions_Unauthorized):
            target = self._getPortalURL()

        kw = {}
        if self.status:
            message = translate(self.status, self.context)
            if isinstance(message, unicode):
                message = message.encode(self._getBrowserCharset())
            kw['portal_status_message'] = message
        for k in keys.split(','):
            k = k.strip()
            v = self.request.form.get(
                k, self.request.form.get('{0}.{1}'.format(self.prefix, k),
                                         None))
            if v:
                if isinstance(v, unicode):
                    v = v.encode(self._getBrowserCharset())
                kw[k] = v

        query = kw and '?{0}'.format(make_query(kw)) or ''
        self.request.response.redirect('{0}{1}'.format(target, query))

        return ''
Ejemplo n.º 5
0
    def add(self, obj):
        container = self.context
        portal_type = self.ti.getId()

        # check allowed (sometimes redundant, but better safe than sorry)
        if not self.ti.isConstructionAllowed(container):
            raise AccessControl_Unauthorized('Cannot create %s' % portal_type)

        #check container constraints
        ttool = self._getTool('portal_types')
        container_ti = ttool.getTypeInfo(container)
        if container_ti is not None and \
                not container_ti.allowType(portal_type):
            raise ValueError('Disallowed subobject type: %s' % portal_type)

        name = INameChooser(container).chooseName(obj.getId(), obj)
        obj.id = name
        container._setObject(name, obj)
        obj = container._getOb(name)

        obj_type = translate(obj.Type(), container)
        self.status = _(u'${obj_type} added.', mapping={'obj_type': obj_type})
        self._finished_add = True
        self._added_obj = obj
        return obj
Ejemplo n.º 6
0
    def _setRedirect(self, provider_id, action_path, keys=''):
        provider = getToolByName(self.context, provider_id)
        try:
            target = provider.getActionInfo(action_path,
                                            self.context,
                                            check_condition=1)['url']
        except (ValueError, zExceptions_Unauthorized):
            target = self._getPortalURL()

        kw = {}
        if self.status:
            message = translate(self.status, self.context)
            if isinstance(message, unicode):
                message = message.encode(self._getBrowserCharset())
            kw['portal_status_message'] = message
        for k in keys.split(','):
            k = k.strip()
            v = self.request.form.get(k, None)
            # filter out keys without values or with redundant default values
            if v and v != '0':
                kw[k] = v

        query = kw and ('?%s' % make_query(kw)) or ''
        self.request.RESPONSE.redirect('%s%s' % (target, query))

        return ''
Ejemplo n.º 7
0
Archivo: form.py Proyecto: goschtl/zope
 def label(self):
     obj_type_id = self.widgets['portal_type']._getFormValue()
     # look it up to get an i18n message object with correct i18n domain
     ttool = self._getTool('portal_types')
     fti = ttool.getTypeInfo(obj_type_id)
     obj_type = translate(fti.Title(), self.context)
     return _(u'Add ${obj_type}', mapping={'obj_type': obj_type})
Ejemplo n.º 8
0
 def label(self):
     obj_type_id = self.widgets['portal_type']._getFormValue()
     # look it up to get an i18n message object with correct i18n domain
     ttool = self._getTool('portal_types')
     fti = ttool.getTypeInfo(obj_type_id)
     obj_type = translate(fti.Title(), self.context)
     return _(u'Add ${obj_type}', mapping={'obj_type': obj_type})
Ejemplo n.º 9
0
    def nextURL(self):
        obj = self._added_obj

        message = translate(self.status, self.context)
        if isinstance(message, unicode):
            message = message.encode(self._getBrowserCharset())
        return '%s/%s?%s' % (obj.absolute_url(), self.ti.immediate_view,
                             make_query(portal_status_message=message))
Ejemplo n.º 10
0
    def add(self, obj):
        container = self.context

        name = INameChooser(container).chooseName(obj.getId(), obj)
        obj.id = name
        container._setObject(name, obj)
        obj = container._getOb(name)

        obj_type = translate(obj.Type(), container)
        self.status = _(u'${obj_type} added.', mapping={'obj_type': obj_type})
        self._finished_add = True
        self._added_obj = obj
        return obj
Ejemplo n.º 11
0
Archivo: form.py Proyecto: goschtl/zope
    def add(self, obj):
        container = self.context

        name = INameChooser(container).chooseName(obj.getId(), obj)
        obj.id = name
        container._setObject(name, obj)
        obj = container._getOb(name)

        obj_type = translate(obj.Type(), container)
        self.status = _(u'${obj_type} added.', mapping={'obj_type': obj_type})
        self._finished_add = True
        self._added_obj = obj
        return obj
Ejemplo n.º 12
0
Archivo: form.py Proyecto: goschtl/zope
    def createAndAdd(self, data):
        if not self.ti.product:
            return super(FallbackAddView, self).createAndAdd(data)

        # for portal types with oldstyle factories
        container = self.context
        name = container.invokeFactory(self.ti.getId(), data['id'])
        obj = container._getOb(name)

        obj_type = translate(obj.Type(), container)
        self.status = _(u'${obj_type} added.', mapping={'obj_type': obj_type})
        self._finished_add = True
        self._added_obj = obj
        return obj
Ejemplo n.º 13
0
    def createAndAdd(self, data):
        if not self.ti.product:
            return super(FallbackAddView, self).createAndAdd(data)

        # for portal types with oldstyle factories
        container = self.context
        name = container.invokeFactory(self.ti.getId(), data['id'])
        obj = container._getOb(name)

        obj_type = translate(obj.Type(), container)
        self.status = _(u'${obj_type} added.', mapping={'obj_type': obj_type})
        self._finished_add = True
        self._added_obj = obj
        return obj
Ejemplo n.º 14
0
Archivo: form.py Proyecto: goschtl/zope
 def _handle_success(self, action, data):
     # normalize set and datetime
     for k, v in data.iteritems():
         if isinstance(v, Set):
             data[k] = set(v)
         elif isinstance(v, datetime) and v.tzname() is None:
             data[k] = parseDatetimetz(str(v))
     if form.applyChanges(self.context, self.form_fields, data,
                          self.adapters):
         self.context.reindexObject()
         obj_type = translate(self.context.Type(), self.context)
         self.status = _(u'${obj_type} changed.',
                         mapping={'obj_type': obj_type})
     else:
         self.status = _(u'Nothing to change.')
Ejemplo n.º 15
0
 def _handle_success(self, action, data):
     # normalize set and datetime
     for k, v in data.iteritems():
         if isinstance(v, Set):
             data[k] = set(v)
         elif isinstance(v, datetime) and v.tzname() is None:
             data[k] = parseDatetimetz(str(v))
     if form.applyChanges(self.context, self.form_fields, data,
                          self.adapters):
         self.context.reindexObject()
         obj_type = translate(self.context.Type(), self.context)
         self.status = _(u'${obj_type} changed.',
                         mapping={'obj_type': obj_type})
     else:
         self.status = _(u'Nothing to change.')
Ejemplo n.º 16
0
 def __call__(self, **kw):
     form = self.request.form
     for button in self._BUTTONS:
         if button['id'] in form:
             for permission in button.get('permissions', ()):
                 if not self._checkPermission(permission):
                     break
             else:
                 for transform in button.get('transform', ()):
                     status = getattr(self, transform)(**form)
                     if isinstance(status, bool):
                         status = (status,)
                     if len(status) > 1:
                         message = translate(status[1], self.context)
                         self.request.other['portal_status_message'] = message
                     if not status[0]:
                         return self.index()
                 if self._setRedirect(*button['redirect']):
                     return
     return self.index()
Ejemplo n.º 17
0
 def __call__(self, **kw):
     form = self.request.form
     for button in self._BUTTONS:
         if button['id'] in form:
             for permission in button.get('permissions', ()):
                 if not self._checkPermission(permission):
                     break
             else:
                 for transform in button.get('transform', ()):
                     status = getattr(self, transform)(**form)
                     if isinstance(status, bool):
                         status = (status,)
                     if len(status) > 1:
                         message = translate(status[1], self.context)
                         self.request.other['portal_status_message'] = message
                     if not status[0]:
                         return self.index()
                 if self._setRedirect(*button['redirect']):
                     return
     return self.index()
Ejemplo n.º 18
0
Archivo: form.py Proyecto: goschtl/zope
    def add(self, obj):
        container = self.context

        #check container constraints
        ttool = self._getTool('portal_types')
        container_ti = ttool.getTypeInfo(container)
        portal_type = obj.getPortalTypeName()
        if container_ti is not None and \
                not container_ti.allowType(portal_type):
            raise ValueError('Disallowed subobject type: %s' % portal_type)

        name = INameChooser(container).chooseName(obj.getId(), obj)
        obj.id = name
        container._setObject(name, obj)
        obj = container._getOb(name)

        obj_type = translate(obj.Type(), self.context)
        self.status = _(u'${obj_type} added.', mapping={'obj_type': obj_type})
        self._finished_add = True
        self._added_obj = obj
        return obj
Ejemplo n.º 19
0
    def add(self, obj):
        container = self.context

        #check container constraints
        ttool = self._getTool('portal_types')
        container_ti = ttool.getTypeInfo(container)
        portal_type = obj.getPortalTypeName()
        if container_ti is not None and \
                not container_ti.allowType(portal_type):
            raise ValueError('Disallowed subobject type: %s' % portal_type)

        name = INameChooser(container).chooseName(obj.getId(), obj)
        obj.id = name
        container._setObject(name, obj)
        obj = container._getOb(name)

        obj_type = translate(obj.Type(), self.context)
        self.status = _(u'${obj_type} added.', mapping={'obj_type': obj_type})
        self._finished_add = True
        self._added_obj = obj
        return obj
Ejemplo n.º 20
0
    def _setRedirect(self, provider_id, action_path, keys=''):
        provider = self._getTool(provider_id)
        try:
            target = provider.getActionInfo(action_path, self.context)['url']
        except ValueError:
            target = self._getPortalURL()

        kw = {}
        if self.status:
            message = translate(self.status, self.context)
            if isinstance(message, unicode):
                message = message.encode(self._getBrowserCharset())
            kw['portal_status_message'] = message
        for k in keys.split(','):
            k = k.strip()
            v = self.request.form.get(k, None)
            if v:
                kw[k] = v

        query = kw and ('?%s' % make_query(kw)) or ''
        self.request.RESPONSE.redirect('%s%s' % (target, query))

        return ''
Ejemplo n.º 21
0
Archivo: form.py Proyecto: goschtl/zope
    def _setRedirect(self, provider_id, action_path, keys=''):
        provider = self._getTool(provider_id)
        try:
            target = provider.getActionInfo(action_path, self.context)['url']
        except ValueError:
            target = self._getPortalURL()

        kw = {}
        if self.status:
            message = translate(self.status, self.context)
            if isinstance(message, unicode):
                message = message.encode(self._getBrowserCharset())
            kw['portal_status_message'] = message
        for k in keys.split(','):
            k = k.strip()
            v = self.request.form.get(k, None)
            if v:
                kw[k] = v

        query = kw and ( '?%s' % make_query(kw) ) or ''
        self.request.RESPONSE.redirect( '%s%s' % (target, query) )

        return ''
Ejemplo n.º 22
0
 def successMessage(self):
     obj_type = translate(self.context.Type(), self.context)
     return _(u'${obj_type} changed.', mapping={'obj_type': obj_type})
Ejemplo n.º 23
0
 def label(self):
     obj_type = translate(self.context.Type(), self.context)
     return _(u'Edit ${obj_type}', mapping={'obj_type': obj_type})
Ejemplo n.º 24
0
 def label(self):
     obj_type = translate(self.ti.Title(), self.context)
     return _(u"Add ${obj_type}", mapping={"obj_type": obj_type})
Ejemplo n.º 25
0
 def label(self):
     obj_type = translate(self.context.Type(), self.context)
     return _(u"Edit ${obj_type}", mapping={"obj_type": obj_type})
Ejemplo n.º 26
0
 def successMessage(self):
     obj_type = translate(self.context.Type(), self.context)
     return _(u"${obj_type} changed.", mapping={"obj_type": obj_type})
Ejemplo n.º 27
0
 def label(self):
     obj_type = translate(self.ti.Title(), self.context)
     return _(u'Add ${obj_type}', mapping={'obj_type': obj_type})
Ejemplo n.º 28
0
Archivo: form.py Proyecto: goschtl/zope
 def label(self):
     obj_type = translate(self.context.Type(), self.context)
     return _(u'Edit ${obj_type}', mapping={'obj_type': obj_type})
Ejemplo n.º 29
0
##parameters=success, message='', **kw
##
from Products.CMFDefault.utils import translate

if message:
    message = translate(message, context)
    context.REQUEST.other['portal_status_message'] = message
if kw:
    for k, v in kw.items():
        context.REQUEST.form[k] = v

return success
Ejemplo n.º 30
0
Archivo: form.py Proyecto: goschtl/zope
 def handle_failure(self, action, data, errors):
     if self.status:
         message = translate(self.status, self.context)
         self.request.other['portal_status_message'] = message
Ejemplo n.º 31
0
Archivo: form.py Proyecto: goschtl/zope
 def successMessage(self):
     obj_type = translate(self.context.Type(), self.context)
     return _(u'${obj_type} changed.', mapping={'obj_type': obj_type})
Ejemplo n.º 32
0
 def handle_failure(self, action, data, errors):
     if self.status:
         message = translate(self.status, self.context)
         self.request.other['portal_status_message'] = message
Ejemplo n.º 33
0
Archivo: form.py Proyecto: goschtl/zope
 def label(self):
     obj_type = translate(self.ti.Title(), self.context)
     return _(u'Add ${obj_type}', mapping={'obj_type': obj_type})