From 883ef9d2e754575307ca0ea58f61a633ffadd195 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Thu, 25 Jun 2015 21:07:35 -0300 Subject: [PATCH] Test for previous class Meta on source generation --- legacy/scripts/scrap_original_forms.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/legacy/scripts/scrap_original_forms.py b/legacy/scripts/scrap_original_forms.py index 119ab5879..26efd9e76 100644 --- a/legacy/scripts/scrap_original_forms.py +++ b/legacy/scripts/scrap_original_forms.py @@ -92,6 +92,7 @@ def source_with_verbose_names(model): field_regex = ' *(.+) = (models\..*)\((.*)\)' new_lines = [] + class_meta_already_exists = False for line in source[1:]: for regex, split in [ (field_regex + ' *# (.+)', lambda groups: groups), @@ -107,6 +108,8 @@ def source_with_verbose_names(model): (' %s = %s(%s)' % (name, path, args), legacy_name)) break else: + if 'class Meta:' in line: + class_meta_already_exists = True new_lines.append((line, '')) yield source[0].rstrip() cols = max(map(len, [line for line, _ in new_lines])) @@ -116,12 +119,17 @@ def source_with_verbose_names(model): yield line + ' # ' + legacy_name else: yield line - if title: - if title.endswith('s'): - title_singular, title_plural = '', title - else: - title_singular, title_plural = title, '' - yield """ + + # class Meta + if class_meta_already_exists: + return + + title = title if title else '' + if title.endswith('s'): + title_singular, title_plural = '', title + else: + title_singular, title_plural = title, '' + yield """ class Meta: verbose_name = _(u'%s') verbose_name_plural = _(u'%s')""" % (title_singular, title_plural)