Ejemplo n.º 1
0
    def __call__(self):
        if not authorized(self.context, self.request):
            raise Unauthorized()

        source = self.request.form.get('source')

        try:
            source = etree.tostring(
                etree.fromstring(source),
                pretty_print=True,
                xml_declaration=True,
                encoding='utf8',
            )
            load_schema(source, cache_key=None)
        except Exception as e:
            message = e.args[0].replace('\n  File "<unknown>"', '')
            return json.dumps({
                'success': False,
                'message': u'ParseError: {0}'.format(message),
            })

        save_schema(self.context.content, xml=source)

        self.request.response.setHeader('Content-Type', 'application/json')
        return json.dumps({'success': True, 'message': _(u'Saved')})
Ejemplo n.º 2
0
 def schema(self):
     language = negotiate(context=self.request) or u''
     try:
         return load_schema(
             aq_base(self.context).schema,
             language=language,
             cache_key=aq_base(self.context).schema_digest,
         )
     except AttributeError:
         self.request.response.redirect(
             '{0:s}/@@design'.format(self.context.absolute_url()), )
         return load_schema(DEFAULT_SCHEMA, cache_key=None)
Ejemplo n.º 3
0
 def schema(self):
     language = negotiate(context=self.request) or u''
     return load_schema(
         aq_base(self.context).schema,
         language=language,
         cache_key=aq_base(self.context).schema_digest,
     )
Ejemplo n.º 4
0
def burnDefaultValues(ob, event):
    schema = load_schema(
        aq_base(ob).schema,
        cache_key=aq_base(ob).schema_digest,
    )
    for name in schema.names():
        field = schema[name]
        try:
            factory = field.defaultFactory
        except AttributeError:
            factory = None
        try:
            default = field.default
        except AttributeError:
            default = None
        if not (factory or default):
            continue
        bound = field.bind(ob)
        try:
            value = bound.get(ob)
        except AttributeError:
            value = None
        if value:
            continue
        if factory:
            if IContextAwareDefaultFactory.providedBy(factory):
                value = factory(ob)
            else:
                value = factory()
        else:
            value = deepcopy(default)
        if value:
            bound.set(ob, value)
            set_contained(value, name, ob)
Ejemplo n.º 5
0
 def __init__(self, context, request):
     language = negotiate(context=request) or u''
     try:
         schema = load_schema(
             aq_base(context).schema,
             language=language,
             cache_key=None,
         )
     except AttributeError:
         schema = load_schema(DEFAULT_SCHEMA, cache_key=None)
     super(FlowSchemaContext, self).__init__(
         schema,
         request,
         name='@@{0:s}'.format(self.__name__),
         title=_(u'design'),
     )
     self.content = context
Ejemplo n.º 6
0
 def __init__(self, context, request, content):
     language = negotiate(context=request) or u''
     self.content = content
     self.schema = load_schema(
         aq_base(content).schema,
         language=language,
         cache_key=aq_base(content).schema_digest,
     )
     super(SubmissionView, self).__init__(context, request)
Ejemplo n.º 7
0
 def schema(self):
     try:
         language = negotiate(context=self.request) or u''
         schema = load_schema(
             aq_base(self.context).schema,
             name='@@impersonate',
             language=language,
             cache_key=aq_base(self.context).schema_digest,
         )
         alsoProvides(schema, IImpersonateFlowSchemaDynamic)
         return schema
     except (AttributeError, KeyError):
         return IFlowImpersonation
Ejemplo n.º 8
0
 def schema(self):
     language = negotiate(context=self.request) or u''
     try:
         try:
             schema = load_schema(
                 aq_base(self.context).schema,
                 name='++add++',
                 language=language,
                 cache_key=aq_base(self.context).schema_digest,
             )
             alsoProvides(schema, IAddFlowSchemaDynamic)
             return schema
         except KeyError:
             schema = aq_base(self.context).schema.replace(
                 'flow.AuthorPortalContent',
                 'zope2.View',
             )
             key = hashlib.md5(schema).hexdigest()
             return load_schema(schema, language=language, cache_key=key)
     except AttributeError:
         self.request.response.redirect(
             u'{0}/@@design'.format(self.context.absolute_url()), )
         return load_schema(DEFAULT_SCHEMA, cache_key=None)
Ejemplo n.º 9
0
 def test_schema_loads(self):
     ob = self.layer['portal'].order
     load_schema(ob.schema, cache_key=ob.schema_digest)