Ticket #21081: options.diff
File options.diff, 1.8 KB (added by , 11 years ago) |
---|
-
django/db/models/options.py
4 4 import re 5 5 from bisect import bisect 6 6 import warnings 7 import logging 7 8 8 9 from django.conf import settings 9 10 from django.db.models.fields.related import ManyToManyRel … … 15 16 from django.utils.encoding import force_text, smart_text, python_2_unicode_compatible 16 17 from django.utils.translation import activate, deactivate_all, get_language, string_concat 17 18 19 logger = logging.getLogger('django.models') 20 18 21 # Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces". 19 22 get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', class_name).lower().strip() 20 23 … … 121 124 if self.verbose_name_plural is None: 122 125 self.verbose_name_plural = string_concat(self.verbose_name, 's') 123 126 124 # Any leftover attributes must be invalid.127 # Any leftover attributes are unknown to Django, and might be typos. 125 128 if meta_attrs != {}: 126 raise TypeError("'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())) 129 # Use difflib to check for close string matches, and warn the 130 # user if any are found with a greater than 80% confidence. 131 from difflib import get_close_matches 132 for unknown_attr in six.iterkeys(meta_attrs): 133 matches = get_close_matches(unknown_attr, DEFAULT_NAMES, 1, 0.8) 134 if matches: 135 logger.warning("Unknown Meta option '%s' found, did you mean '%s'?" 136 % (unknown_attr, matches[0])) 127 137 else: 128 138 self.verbose_name_plural = string_concat(self.verbose_name, 's') 129 139 del self.meta