Add optional_create flag

This commit is contained in:
Nathaniel McCallum 2013-10-01 13:57:24 -04:00 committed by Petr Viktorin
parent b54cdab33d
commit e05dfbd8b4
2 changed files with 12 additions and 5 deletions

View File

@ -133,16 +133,21 @@ class Create(Method):
has_output = output.standard_entry has_output = output.standard_entry
def __clone(self, param, **kw):
if 'optional_create' in param.flags:
kw['required'] = False
return param.clone(**kw) if kw else param
def get_args(self): def get_args(self):
if self.obj.primary_key: if self.obj.primary_key:
yield self.obj.primary_key.clone(attribute=True) yield self.__clone(self.obj.primary_key, attribute=True)
for arg in super(Create, self).get_args(): for arg in super(Create, self).get_args():
yield arg yield self.__clone(arg)
def get_options(self): def get_options(self):
if self.extra_options_first: if self.extra_options_first:
for option in super(Create, self).get_options(): for option in super(Create, self).get_options():
yield option yield self.__clone(option)
for option in self.obj.params_minus(self.args): for option in self.obj.params_minus(self.args):
attribute = 'virtual_attribute' not in option.flags attribute = 'virtual_attribute' not in option.flags
if 'no_create' in option.flags: if 'no_create' in option.flags:
@ -153,10 +158,10 @@ class Create(Method):
autofill=False, alwaysask=True autofill=False, alwaysask=True
) )
else: else:
yield option.clone(attribute=attribute) yield self.__clone(option, attribute=attribute)
if not self.extra_options_first: if not self.extra_options_first:
for option in super(Create, self).get_options(): for option in super(Create, self).get_options():
yield option yield self.__clone(option)
class PKQuery(Method): class PKQuery(Method):

View File

@ -351,6 +351,8 @@ class Param(ReadOnly):
not be given at all. All crud.Update commands automatically not be given at all. All crud.Update commands automatically
convert required parameters to `nonempty` ones, so the value convert required parameters to `nonempty` ones, so the value
can be unspecified (unchanged) but cannot be deleted. can be unspecified (unchanged) but cannot be deleted.
* optional_create: do not require the parameter for crud.Create
based commands
- hint: this attribute is currently not used - hint: this attribute is currently not used
- alwaysask: when enabled, CLI asks for parameter value even when the - alwaysask: when enabled, CLI asks for parameter value even when the
parameter is not `required` parameter is not `required`