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)