def ask_detail_for_field(name, detail_type, ask_only_required=True, help_map={}): value = None if MODEL_MAP.get(type(detail_type), None): func = MODEL_MAP[type(detail_type)] value = func() return value # collections are a special case if type(detail_type) == booby.fields.Collection: # collection value = ask_collection_detail(name, detail_type.model, ask_only_required, help_map) elif is_model(detail_type): # collection, and model field value = ask_details_for_type(detail_type, ask_only_required, help_map) elif issubclass(type(detail_type), booby.fields.Field): # non-collection, and non-model field value = ask_simple_field(name, type(detail_type), help_map) elif issubclass(detail_type, booby.fields.Field): # collection, and non-model field value = ask_simple_field(name, detail_type, help_map) return value
def ask_field(self, field_name): field_type = self.model_type.__dict__.get(field_name, None) if not field_type: print "No field of that name." new_value = ask_detail_for_field(field_name, field_type, None, self.help_map) if is_model(new_value): new_value = new_value.to_json() return new_value
def test_should_return_false_if_object_isnt_a_model_instance(self): expect(is_model(object())).to(be_false)
def test_should_return_false_if_object_isnt_a_model_subclass(self): expect(is_model(object)).to(be_false)
def test_should_return_true_if_object_is_a_model_subclass(self): expect(is_model(User)).to(be_true)
def test_should_return_true_if_object_is_a_model_instance(self): expect(is_model(User())).to(be_true)
def ensure_json_value(value): if is_model(value): return dict(value) else: return value