def input_add_data(self): data = {'own': {}, 'relation': {}} for (key, field) in self.model: if field.initial_value is not None: data['own'][key] = field.initial_value elif isinstance(field, ForeignKeyField): foreign_key = Relationship.select_foreign_key_relationship( field.relationship) if foreign_key: data['own'][key] = foreign_key else: break elif isinstance(field, OneToManyField): foreign_key = Relationship.select_foreign_key_relationship_inverse( field.relationship) if foreign_key: data['relation'][key] = foreign_key else: break elif field.default_value is not None: user_input = input( "%s (%s): " % (Style.make_label(key), field.default_value)) if user_input is '': user_input = field.default_value data['own'][key] = user_input else: data['own'][key] = input("%s: " % Style.make_label(key)) return data
def input_edit_data(self, item): data = {'own': {}, 'relation': {}} for (key, field) in self.model: if not field.updatable: continue if isinstance(field, ForeignKeyField): if Menu.yes_no_question('Change %s?' % field.relationship.name): foreign_key = Relationship.select_foreign_key_relationship( field.relationship) if foreign_key: data['own'][key] = foreign_key else: data['own'][key] = item[key] elif isinstance(field, OneToManyField): foreign_key = Relationship.select_foreign_key_relationship_inverse( field.relationship) if foreign_key: data['relation'][key] = foreign_key else: data['relation'][key] = item[key] # Todo: handle removing relationships else: data['own'][key] = self.update_field(item[key], Style.make_label(key)) return data
def show_item_detail(self, item): print(Style.create_title('%s Data' % self.table_name)) for header in self.repository.get_headers(): label = Style.make_label(header) print('%s: %s' % (label, Colour.blue(str(item[header]))))