diff -r f8d837d7ffbc -r e2968797bdae src/ldtplatform/management/commands/loadandadddata.py --- a/src/ldtplatform/management/commands/loadandadddata.py Fri Mar 01 18:08:40 2013 +0100 +++ b/src/ldtplatform/management/commands/loadandadddata.py Thu May 23 00:24:23 2013 +0200 @@ -9,10 +9,10 @@ from django.core.management import call_command from django.core.management.base import BaseCommand, CommandError from ldt.ldt_utils.models import Content, Project +from ldt.security.cache import cached_assign from optparse import make_option +import json import os.path -import json -from ldt.security.cache import cached_assign class Command(BaseCommand): @@ -70,9 +70,9 @@ # Check if temporary files already exist path = os.path.abspath(args[0]) - dir = os.path.dirname(path) - path_file1 = os.path.join(dir, 'temp_data1.json') - path_file2 = os.path.join(dir, 'temp_data2.json') + dirpath = os.path.dirname(path) + path_file1 = os.path.join(dirpath, 'temp_data1.json') + path_file2 = os.path.join(dirpath, 'temp_data2.json') do_import = True if os.path.exists(path_file1) or os.path.exists(path_file2): confirm = raw_input((""" @@ -80,7 +80,7 @@ Do you want to continue ? - Type 'y' to continue, or 'n' to quit: """) % dir) + Type 'y' to continue, or 'n' to quit: """) % dirpath) do_import = (confirm == "y") # Continue @@ -136,12 +136,12 @@ # It will enable to parse and replace easily the old pk by the new ones in the permission datas if m=="ldt_utils.project": pk = str(obj["pk"]) - id = obj["fields"]["ldt_id"] - project_pk_id[pk] = id + ldt_id = obj["fields"]["ldt_id"] + project_pk_id[pk] = ldt_id elif m=="ldt_utils.content": pk = str(obj["pk"]) - id = obj["fields"]["iri_id"] - content_pk_id[pk] = id + ldt_id = obj["fields"]["iri_id"] + content_pk_id[pk] = ldt_id obj["pk"] = None else: obj["pk"] = None @@ -184,9 +184,9 @@ ignored_content_pks = [] perm_data = [] for obj in data_file2: - type = obj["fields"]["content_type"][1] + content_type = obj["fields"]["content_type"][1] old_pk = obj["fields"]["object_pk"] - if type=="project": + if content_type =="project": try: obj["fields"]["object_pk"] = project_pk_id[old_pk] except: @@ -195,7 +195,7 @@ continue # Keeping only valuables objs avoids errors when we we get the new pks perm_data.append(obj) - elif type == "content": + elif content_type == "content": try: obj["fields"]["object_pk"] = content_pk_id[old_pk] except: @@ -237,11 +237,11 @@ # Now we reparse the perm_data and update with the new pks for obj in perm_data: - type = obj["fields"]["content_type"][1] + content_type = obj["fields"]["content_type"][1] obj_id = obj["fields"]["object_pk"] - if type=="project": + if content_type=="project": obj["fields"]["object_pk"] = project_id_pk[obj_id] - elif type == "content": + elif content_type == "content": obj["fields"]["object_pk"] = content_id_pk[obj_id]