210 ctrl = vreg['controllers'].select('edit', req=req) |
210 ctrl = vreg['controllers'].select('edit', req=req) |
211 except NoSelectableObject: |
211 except NoSelectableObject: |
212 return (False, {None: req._('not authorized')}, None) |
212 return (False, {None: req._('not authorized')}, None) |
213 try: |
213 try: |
214 ctrl.publish(None) |
214 ctrl.publish(None) |
215 except ValidationError, ex: |
215 except ValidationError as ex: |
216 return (False, _validation_error(req, ex), ctrl._edited_entity) |
216 return (False, _validation_error(req, ex), ctrl._edited_entity) |
217 except Redirect, ex: |
217 except Redirect as ex: |
218 try: |
218 try: |
219 txuuid = req.cnx.commit() # ValidationError may be raised on commit |
219 txuuid = req.cnx.commit() # ValidationError may be raised on commit |
220 except ValidationError, ex: |
220 except ValidationError as ex: |
221 return (False, _validation_error(req, ex), ctrl._edited_entity) |
221 return (False, _validation_error(req, ex), ctrl._edited_entity) |
222 except Exception, ex: |
222 except Exception as ex: |
223 req.cnx.rollback() |
223 req.cnx.rollback() |
224 req.exception('unexpected error while validating form') |
224 req.exception('unexpected error while validating form') |
225 return (False, str(ex).decode('utf-8'), ctrl._edited_entity) |
225 return (False, str(ex).decode('utf-8'), ctrl._edited_entity) |
226 else: |
226 else: |
227 if txuuid is not None: |
227 if txuuid is not None: |
229 # complete entity: it can be used in js callbacks where we might |
229 # complete entity: it can be used in js callbacks where we might |
230 # want every possible information |
230 # want every possible information |
231 if ctrl._edited_entity: |
231 if ctrl._edited_entity: |
232 ctrl._edited_entity.complete() |
232 ctrl._edited_entity.complete() |
233 return (True, ex.location, ctrl._edited_entity) |
233 return (True, ex.location, ctrl._edited_entity) |
234 except Exception, ex: |
234 except Exception as ex: |
235 req.cnx.rollback() |
235 req.cnx.rollback() |
236 req.exception('unexpected error while validating form') |
236 req.exception('unexpected error while validating form') |
237 return (False, str(ex).decode('utf-8'), ctrl._edited_entity) |
237 return (False, str(ex).decode('utf-8'), ctrl._edited_entity) |
238 return (False, '???', None) |
238 return (False, '???', None) |
239 |
239 |
296 |
296 |
297 def publish(self, rset=None): |
297 def publish(self, rset=None): |
298 txuuid = self._cw.form['txuuid'] |
298 txuuid = self._cw.form['txuuid'] |
299 try: |
299 try: |
300 self._cw.cnx.undo_transaction(txuuid) |
300 self._cw.cnx.undo_transaction(txuuid) |
301 except UndoTransactionException, exc: |
301 except UndoTransactionException as exc: |
302 errors = exc.errors |
302 errors = exc.errors |
303 #This will cause a rollback in main_publish |
303 #This will cause a rollback in main_publish |
304 raise ValidationError(None, {None: '\n'.join(errors)}) |
304 raise ValidationError(None, {None: '\n'.join(errors)}) |
305 else : |
305 else : |
306 self.redirect() # Will raise Redirect |
306 self.redirect() # Will raise Redirect |