Browse Source

Rename field_mappings -> field_renames

pull/6/head
Marcio Mazza 10 years ago
parent
commit
2f96719ff0
  1. 6
      legacy/scripts/field_renames.py
  2. 4
      legacy/scripts/migration.py
  3. 4
      legacy/scripts/scrap_original_forms.py

6
legacy/scripts/field_mappings.py → legacy/scripts/field_renames.py

@ -33,7 +33,7 @@ def print_commented_source(model):
return new_to_old
field_mappings = OrderedDict()
field_renames = OrderedDict()
for app in appconfs:
for model in app.models.values():
new_to_old = OrderedDict()
@ -43,7 +43,7 @@ for app in appconfs:
new = get_field(line)
old = line.split('#')[-1].strip()
new_to_old[new] = old
field_mappings[model] = new_to_old
field_renames[model] = new_to_old
def check_similarity():
@ -52,7 +52,7 @@ def check_similarity():
return SequenceMatcher(None, a, b).ratio()
different_pairs = defaultdict(list)
for model, new_to_old in field_mappings.items():
for model, new_to_old in field_renames.items():
for new, old in new_to_old.items():
if similar(new, old) < 0.7:
different_pairs[model].append((new, old))

4
legacy/scripts/migration.py

@ -4,7 +4,7 @@ from django.db import connections, models
from django.db.models.base import ModelBase
from model_mommy import mommy
from field_mappings import field_mappings
from field_renames import field_renames
from migration_base import legacy_app, appconfs
from parlamentares.models import Parlamentar
@ -126,7 +126,7 @@ def migrate_model(model, to_delete, count_limit=None):
for old in old_records:
old_pk = get_old_pk(old)
new = model()
for new_field, old_field in field_mappings[model].items():
for new_field, old_field in field_renames[model].items():
value = getattr(old, old_field)
model_field = model._meta.get_field(new_field)
transform = special_transforms.get(model_field)

4
legacy/scripts/scrap_original_forms.py

@ -6,7 +6,7 @@ import string
from bs4 import BeautifulSoup
from bs4.element import NavigableString, Tag
from field_mappings import field_mappings
from field_renames import field_renames
from migration import appconfs
from utils import listify, getsourcelines
@ -76,7 +76,7 @@ def extract_verbose_names(model):
field_names = [f.name for f in model._meta.fields if f.name != 'id']
labels = {}
field_names_to_old = field_mappings[model]
field_names_to_old = field_renames[model]
for name in field_names:
old_name = field_names_to_old[name]
label = names_to_labels.get(old_name, None)

Loading…
Cancel
Save