def get_input(self, field, oldvalue, new): """Gets a value from command line input. :param field: The fieldname of the edited field :param oldvalue: The old value of the field :param new: Whether the entry is new""" if new: prompt = '%s: ' % phonebook.translate_field(field) else: prompt = '%s [%s]: ' prompt = prompt % (phonebook.translate_field(field), oldvalue) return raw_input(prompt)
def edit(self, entry): """Edits `entry`. :returns: The edited `entry`""" new = entry.parent is None print if new: # entry is new print >> stdout, self.NEW_MSG else: print >> stdout, self.EDIT_MSG % entry self.initialize_editor() for field in self.fields: oldvalue = unicode(entry[field]) while True: value = self.get_input(field, oldvalue, new) try: entry[field] = value break except ValueError: msg = _('You entered an invalid value for the field' '"%s"!') print >> stdout, msg % phonebook.translate_field(field) self.finalize_editor() return entry
def _cmd_help_fields(self, options, *args): if not args: args = phonebook.FIELDS try: items = [(phonebook.translate_field(field), unicode(field)) for field in args] except phonebook.NoSuchField, e: exit(_('There is no field %s.') % e.field)
def get_input(self, field, oldvalue, new): """Gets a value from command line input. :param field: The fieldname of the edited field :param oldvalue: The old value of the field :param new: Whether the entry is new""" if not new: self.oldvalue = oldvalue else: self.oldvalue = None prompt = u'%s: ' % phonebook.translate_field(field) return raw_input(prompt)