def execute(self, args):
        model_cls = creatable_models.get(args.type)

        form = RawDataValidatingFactory(args.keywords,
                                        model_cls,
                                        marker=getattr(self.current_obj,
                                                       '__contains__', None))

        if form.errors:
            form.write_errors(to=self)
            return

        obj = form.create()

        vh = PreValidateHookMixin(obj)
        try:
            blocking_yield(vh.validate_hook(self.protocol.principal))
        except Exception:
            msg = 'Cancelled executing "%s" due to validate_hook failure' % self.name
            self.write('%s\n' % msg)
            log.msg(msg, system='set')
            return

        interaction = self.protocol.interaction
        if not interaction:
            auth = getUtility(IAuthentication, context=None)
            principal = auth.getPrincipal(None)
        else:
            principal = interaction.participations[0].principal

        obj.__owner__ = principal

        obj_id = self.current_obj.add(obj)

        self.write("%s\n" % obj_id)
    def execute(self, args):
        model_cls = creatable_models.get(args.type)

        form = RawDataValidatingFactory(args.keywords, model_cls,
                                        marker=getattr(self.current_obj, '__contains__', None))

        if form.errors:
            form.write_errors(to=self)
            return

        obj = form.create()

        vh = PreValidateHookMixin(obj)
        try:
            blocking_yield(vh.validate_hook(self.protocol.principal))
        except Exception:
            msg = 'Cancelled executing "%s" due to validate_hook failure' % self.name
            self.write('%s\n' % msg)
            log.msg(msg, system='set')
            return

        interaction = self.protocol.interaction
        if not interaction:
            auth = getUtility(IAuthentication, context=None)
            principal = auth.getPrincipal(None)
        else:
            principal = interaction.participations[0].principal

        obj.__owner__ = principal

        obj_id = self.current_obj.add(obj)

        self.write("%s\n" % obj_id)
    def execute(self, args):
        obj = (yield db.ro_transact(self.traverse)(args.path))
        if not obj:
            self.write("No such object: %s\n" % args.path)
            return

        vh = PreValidateHookMixin(obj)
        try:
            yield vh.validate_hook(self.protocol.principal)
        except Exception:
            msg = 'Canceled executing "set" due to validate_hook failure'
            self.write('%s\n' % msg)
            log.msg(msg, system='set')
            return

        @db.transact
        def apply():
            obj = self.traverse(args.path)
            raw_data = args.keywords

            if args.verbose:
                for key, value in raw_data.items():
                    self.write("Setting %s=%s\n" % (key, value))

            form = RawDataApplier(raw_data, obj)

            if not form.errors:
                form.apply()
            else:
                form.write_errors(to=self)

        yield apply()
    def execute(self, args):
        obj = (yield db.ro_transact(self.traverse)(args.path))
        if not obj:
            self.write("No such object: %s\n" % args.path)
            return

        vh = PreValidateHookMixin(obj)
        try:
            yield vh.validate_hook(self.protocol.principal)
        except Exception:
            msg = 'Canceled executing "set" due to validate_hook failure'
            self.write('%s\n' % msg)
            log.msg(msg, system='set')
            return

        @db.transact
        def apply():
            obj = self.traverse(args.path)
            raw_data = args.keywords

            if args.verbose:
                for key, value in raw_data.items():
                    self.write("Setting %s=%s\n" % (key, value))

            principals = map(lambda p: p.id, effective_principals(self.user))

            if 'admins' in principals:
                setattr(obj, '_admin_access', True)
            elif getattr(obj, '_admin_access', False):
                log.msg(
                    'WARNING: admin access in SetAttrCmd when accessed by non-admin (%s: %s)!'
                    % (self.user, principals),
                    system='set-cmd')

            try:
                form = RawDataApplier(raw_data, obj)

                if not form.errors:
                    form.apply()
                else:
                    form.write_errors(to=self)
            finally:
                if hasattr(obj, '_admin_access'):
                    delattr(obj, '_admin_access')

        yield apply()
    def execute(self, args):
        obj = (yield db.ro_transact(self.traverse)(args.path))
        if not obj:
            self.write("No such object: %s\n" % args.path)
            return

        vh = PreValidateHookMixin(obj)
        try:
            yield vh.validate_hook(self.protocol.principal)
        except Exception:
            msg = 'Canceled executing "set" due to validate_hook failure'
            self.write('%s\n' % msg)
            log.msg(msg, system='set')
            return

        @db.transact
        def apply():
            obj = self.traverse(args.path)
            raw_data = args.keywords

            if args.verbose:
                for key, value in raw_data.items():
                    self.write("Setting %s=%s\n" % (key, value))

            principals = map(lambda p: p.id, effective_principals(self.user))

            if 'admins' in principals:
                setattr(obj, '_admin_access', True)
            elif getattr(obj, '_admin_access', False):
                log.msg('WARNING: admin access in SetAttrCmd when accessed by non-admin (%s: %s)!'
                        % (self.user, principals), system='set-cmd')

            try:
                form = RawDataApplier(raw_data, obj)

                if not form.errors:
                    form.apply()
                else:
                    form.write_errors(to=self)
            finally:
                if hasattr(obj, '_admin_access'):
                    delattr(obj, '_admin_access')

        yield apply()