Commit 634688e8 authored by Anze Vavpetic's avatar Anze Vavpetic
Browse files

added --updateuid option to export_package, which assigns uuids to models with...

added --updateuid option to export_package, which assigns uuids to models with no uuids (new widgets, options, etc).
parent 58fba631
......@@ -46,7 +46,7 @@ def auto_import_all_packages(writeFunc, nobackup):
backupDir = os.path.join(BACKUP_DIR,"db_backup"+timeStamp)
writeFunc('Exporting to backup...\n')
result = export_package.export_package_string(lambda text: writeFunc(' '+text), ('all',), False, True, 1)
result = export_package.export_package_string(lambda text: writeFunc(' '+text), ('all',), False, False, True, 1)
f = open(backupDir, 'w')
......@@ -14,6 +14,11 @@ class Command(BaseCommand):
help='UID field of all exported models will be overwritten with new random values.'),
make_option('-u', '--updateuid',
help='Models without UIDs will be assigned new ones. Use this option when adding new parameters, widgets, etc, to an existing package.'),
make_option('-a', '--all',
......@@ -25,12 +30,15 @@ class Command(BaseCommand):
if (len(args) < 2):
raise CommandError('Arguments "file_name" and "package_name" are required!')
if options['newuid'] and options['updateuid']:
raise CommandError('--newuid and --updateuid flags are mutually exclusive.')
f = open(args[0], 'w')
raise CommandError('There was a problem with creating/overwriting given output file')
result = export_package_string(self.stdout.write, args[1:], options['newuid'], options['all'], int(options['verbosity']))
result = export_package_string(self.stdout.write, args[1:], options['newuid'], options['updateuid'], options['all'], int(options['verbosity']))
......@@ -42,9 +50,10 @@ class Command(BaseCommand):
self.stdout.write('Tip: use higher "verbosity" option numbers to se more detailed output of what is being exported.\n')
self.stdout.write('Export procedure successfully finished. Results written to the file.\n')
def export_package_string(writeFunc, packages, newuid, all, verbosity):
def export_package_string(writeFunc, packages, newuid, updateuid, all, verbosity):
assert isinstance(packages, tuple)
assert isinstance(newuid, bool)
assert isinstance(updateuid, bool)
assert isinstance(all, bool)
objs = []
......@@ -52,12 +61,11 @@ def export_package_string(writeFunc, packages, newuid, all, verbosity):
objs.extend(get_package_objs_in_category(topCat, packages, all))
if len(objs) == 0:
writeFunc('Selected package(s) were not found!\n')
return "[\\n]"
raise CommandError('Selected package(s) were not found!')
#be careful uid is only changed on these instances and is not written to the database
if newuid:
for a in objs:
for a in objs:
if newuid or (not a.uid and updateuid):
a.uid = str(uuid.uuid4())
print_stataistics(objs, verbosity, writeFunc)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment