Ticket #2204: options.py.diff
File options.py.diff, 2.1 KB (added by , 18 years ago) |
---|
-
options.py
41 41 self.object_name = cls.__name__ 42 42 self.module_name = self.object_name.lower() 43 43 self.verbose_name = get_verbose_name(self.object_name) 44 vowels = "aeiou" 45 consonants = "bcdfghjklmnpqrstvwxyz" 46 # If the word ends in a 'y' and is preceded by a vowel, add 'ies'. 47 if self.verbose_name.endswith('y') and self.verbose_name[-2] in consonants: 48 verbose_name_plural = self.verbose_name[:-1] + 'ies' 49 elif self.verbose_name.endswith('is'): 50 verbose_name_plural = self.verbose_name[:-2] + 'es' 51 elif self.verbose_name.endswith('us'): 52 verbose_name_plural = self.verbose_name[:-2] + 'i' 53 elif self.verbose_name.endswith('o') and self.verbose_name[-2] in consonants: 54 verbose_name_plural = self.verbose_name + 'es' 55 elif self.verbose_name[-2:] in ('ch', 'sh') or self.verbose_name[-1] in ('s', 'x', 'z'): 56 verbose_name_plural = self.verbose_name + 'es' 57 else: 58 verbose_name_plural = self.verbose_name + 's' 44 59 # Next, apply any overridden values from 'class Meta'. 45 60 if self.meta: 46 61 meta_attrs = self.meta.__dict__ … … 50 65 setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name))) 51 66 # verbose_name_plural is a special case because it uses a 's' 52 67 # by default. 53 setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', self.verbose_name + 's'))68 setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', verbose_name_plural)) 54 69 # Any leftover attributes must be invalid. 55 70 if meta_attrs != {}: 56 71 raise TypeError, "'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys()) 57 72 else: 58 self.verbose_name_plural = self.verbose_name + 's'73 self.verbose_name_plural = verbose_name_plural 59 74 del self.meta 60 75 61 76 def _prepare(self, model):