[domino] only use one button for updating/creating families
This commit is contained in:
parent
e915d3693a
commit
d6a9ec110c
|
@ -5,7 +5,7 @@ from quixote import get_request, get_publisher, get_session
|
|||
from quixote.directory import Directory
|
||||
|
||||
from qommon.substitution import Substitutions
|
||||
from qommon.form import Form, StringWidget
|
||||
from qommon.form import Form, ValidatedStringWidget
|
||||
import qommon.misc
|
||||
from qommon import get_logger
|
||||
from publisher import WcsPublisher
|
||||
|
@ -17,6 +17,9 @@ from wcs.forms.common import FormStatusPage
|
|||
from abelium_domino_ui import (is_activated, abelium_domino_ws, get_client, get_family)
|
||||
import abelium_domino_ws
|
||||
|
||||
class InternalCodeStringWidget(ValidatedStringWidget):
|
||||
regex = '\d*'
|
||||
|
||||
class AbeliumDominoRegisterFamilyWorkflowStatusItem(WorkflowStatusJumpItem):
|
||||
status = None
|
||||
description = N_('Abelium Domino: Register a Family')
|
||||
|
@ -41,11 +44,13 @@ class AbeliumDominoRegisterFamilyWorkflowStatusItem(WorkflowStatusJumpItem):
|
|||
def fill_form(self, form, formdata, user):
|
||||
family = self.get_family(formdata)
|
||||
if 'family_id' not in form._names:
|
||||
form.add(StringWidget, 'family_id', title=_('Family internal code'),
|
||||
value=family and family.code_interne.encode('utf8'))
|
||||
if not family:
|
||||
form.add_submit('create_button%s' % self.id, _('Create the family'))
|
||||
form.add_submit('update_button%s' % self.id, _('Update the family'))
|
||||
form.add(InternalCodeStringWidget, 'family_id',
|
||||
title=_('Family internal code'),
|
||||
value=family and family.code_interne.encode('utf8'),
|
||||
hint=_('If a family internal code is present, the '
|
||||
'family is updated, if not it is created'))
|
||||
form.add_submit('create_update_button%s' % self.id,
|
||||
_('Create or update the family'))
|
||||
|
||||
def update(self, form, formdata, user, evo):
|
||||
fid_widget = form.get_widget('family_id')
|
||||
|
@ -108,17 +113,17 @@ class AbeliumDominoRegisterFamilyWorkflowStatusItem(WorkflowStatusJumpItem):
|
|||
|
||||
def submit_form(self, form, formdata, user, evo):
|
||||
logger = get_logger()
|
||||
if form.get_submit() != 'create_update_button%s' % self.id:
|
||||
return
|
||||
try:
|
||||
if form.get_submit() == 'update_button%s' % self.id:
|
||||
if form.get_widget('family_id').parse():
|
||||
family = self.update(form, formdata, user, evo)
|
||||
msg = _('Sucessfully updated the family %s')
|
||||
log_msg = _('Sucessfully updated the family %(code)s of %(user)s')
|
||||
elif form.get_submit() == 'create_button%s' % self.id:
|
||||
else:
|
||||
family = self.create(form, formdata, user, evo)
|
||||
msg = _('Sucessfully created the family %s')
|
||||
log_msg = _('Sucessfully created the family %(code)s of %(user)s')
|
||||
else:
|
||||
raise NotImplemented
|
||||
code_interne = family.code_interne.encode('utf8')
|
||||
msg = msg % code_interne
|
||||
logger.info(log_msg, {'code': code_interne, 'user': formdata.get_user()})
|
||||
|
@ -126,7 +131,6 @@ class AbeliumDominoRegisterFamilyWorkflowStatusItem(WorkflowStatusJumpItem):
|
|||
form_user.abelium_domino_code_famille = code_interne
|
||||
form_user.store()
|
||||
except Exception, e:
|
||||
raise
|
||||
if form.get_submit() == 'update_button%s' % self.id:
|
||||
msg = _('Unable to update family: %s') % str(e)
|
||||
elif form.get_submit() == 'create_button%s' % self.id:
|
||||
|
|
Reference in New Issue