summaryrefslogtreecommitdiff
path: root/ishtar_common/management
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-12 15:43:15 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-28 12:15:24 +0100
commit6e4f7a0390b7f49ce79f0e15e07e1d6df309f3ce (patch)
treebb7c35ca850f60028c576ee42e3fb95db20a64be /ishtar_common/management
parent8ec062dab58750d8eb7fc0217d7adcf71d222747 (diff)
downloadIshtar-6e4f7a0390b7f49ce79f0e15e07e1d6df309f3ce.tar.bz2
Ishtar-6e4f7a0390b7f49ce79f0e15e07e1d6df309f3ce.zip
Refactor - clean
Diffstat (limited to 'ishtar_common/management')
-rw-r--r--ishtar_common/management/commands/fix_missing_cached_labels.py6
-rw-r--r--ishtar_common/management/commands/ishtar_import.py2
-rw-r--r--ishtar_common/management/commands/process_pending_update.py6
-rw-r--r--ishtar_common/management/commands/reassociate_similar_images.py16
-rw-r--r--ishtar_common/management/commands/regenerate_external_id.py4
-rw-r--r--ishtar_common/management/commands/regenerate_qrcodes.py6
-rw-r--r--ishtar_common/management/commands/regenerate_search_vector_cached_label.py6
7 files changed, 22 insertions, 24 deletions
diff --git a/ishtar_common/management/commands/fix_missing_cached_labels.py b/ishtar_common/management/commands/fix_missing_cached_labels.py
index 368d98fae..ad2767c56 100644
--- a/ishtar_common/management/commands/fix_missing_cached_labels.py
+++ b/ishtar_common/management/commands/fix_missing_cached_labels.py
@@ -52,7 +52,7 @@ class Command(BaseCommand):
if limit and app != limit:
continue
if not quiet:
- print(u"* app: {}".format(app))
+ print("* app: {}".format(app))
for model in apps.get_app_config(app).get_models():
if model_name and model.__name__.lower() != model_name:
continue
@@ -79,14 +79,14 @@ class Command(BaseCommand):
else:
query |= subquery
q = model.objects.filter(query)
- msg = u"-> processing {}: ".format(model._meta.verbose_name)
+ msg = "-> processing {}: ".format(model._meta.verbose_name)
ln = q.count()
for idx, obj_id in enumerate(q.values('pk').all()):
obj = model.objects.get(pk=obj_id['pk'])
obj.skip_history_when_saving = True
obj._no_move = True
obj._no_geo_check = True
- cmsg = u"\r{} {}/{}".format(msg, idx + 1, ln)
+ cmsg = "\r{} {}/{}".format(msg, idx + 1, ln)
if not quiet:
sys.stdout.write(cmsg)
sys.stdout.flush()
diff --git a/ishtar_common/management/commands/ishtar_import.py b/ishtar_common/management/commands/ishtar_import.py
index a8c9d3736..011af2f8c 100644
--- a/ishtar_common/management/commands/ishtar_import.py
+++ b/ishtar_common/management/commands/ishtar_import.py
@@ -31,7 +31,7 @@ class Command(BaseCommand):
"| name\n")
self.stdout.write("*" * 80 + "\n")
for imp in models.Import.objects.exclude(state="AC").all():
- self.stdout.write(u"|{: ^6}| {: ^32} | {: ^12} | {}\n".format(
+ self.stdout.write("|{: ^6}| {: ^32} | {: ^12} | {}\n".format(
imp.pk, str(imp.importer_type)[:32],
state[imp.state][:12],
imp.name[:128]))
diff --git a/ishtar_common/management/commands/process_pending_update.py b/ishtar_common/management/commands/process_pending_update.py
index 6e97847cc..6feff38c3 100644
--- a/ishtar_common/management/commands/process_pending_update.py
+++ b/ishtar_common/management/commands/process_pending_update.py
@@ -42,7 +42,7 @@ class Command(BaseCommand):
quiet = options['quiet']
for app in APPS:
if not quiet:
- print(u"* app: {}".format(app))
+ print("* app: {}".format(app))
for model in apps.get_app_config(app).get_models():
if model.__name__.startswith('Historical'):
continue
@@ -50,14 +50,14 @@ class Command(BaseCommand):
[True for k in model._meta.get_fields()
if k.name == "need_update"]):
continue
- msg = u"-> processing {}: ".format(model._meta.verbose_name)
+ msg = "-> processing {}: ".format(model._meta.verbose_name)
q = model.objects.filter(need_update=True)
ln = q.count()
for idx, obj_id in enumerate(q.values('pk').all()):
obj = model.objects.get(pk=obj_id['pk'])
obj.skip_history_when_saving = True
obj._no_move = True
- cmsg = u"\r{} {}/{}".format(msg, idx + 1, ln)
+ cmsg = "\r{} {}/{}".format(msg, idx + 1, ln)
if not quiet:
sys.stdout.write(cmsg)
sys.stdout.flush()
diff --git a/ishtar_common/management/commands/reassociate_similar_images.py b/ishtar_common/management/commands/reassociate_similar_images.py
index 0dbb3a765..9e52bc6f6 100644
--- a/ishtar_common/management/commands/reassociate_similar_images.py
+++ b/ishtar_common/management/commands/reassociate_similar_images.py
@@ -127,9 +127,9 @@ class Command(BaseCommand):
for attr in attributes:
ref_value = getattr(ref_item, attr)
other_value = getattr(item, attr)
+ if not other_value:
+ continue
if ref_value:
- if not other_value:
- continue
if other_value != ref_value:
if attr == 'title' and merged_title:
setattr(ref_item, 'title', merged_title)
@@ -138,8 +138,6 @@ class Command(BaseCommand):
(attr, ref_value, other_value)
)
else:
- if not other_value:
- continue
setattr(ref_item, attr, other_value)
base_csv = [
@@ -184,11 +182,11 @@ class Command(BaseCommand):
item.delete()
nb_merged_items += 1
if not quiet:
- out.write(u"\n")
+ out.write("\n")
n = datetime.datetime.now().isoformat().split('.')[0].replace(':', '-')
if conflicts:
- filename = output_path + u"{}-conflict.csv".format(n)
+ filename = output_path + "{}-conflict.csv".format(n)
with open(filename, 'w') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(
@@ -202,10 +200,10 @@ class Command(BaseCommand):
for conflict in conflicts:
writer.writerow(conflict)
if not quiet:
- out.write(u"* {} conflicted items ({})\n".format(
+ out.write("* {} conflicted items ({})\n".format(
nb_conflicted_items, filename))
if merged:
- filename = output_path + u"{}-merged.csv".format(n)
+ filename = output_path + "{}-merged.csv".format(n)
with open(filename, 'w') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(
@@ -218,7 +216,7 @@ class Command(BaseCommand):
for merge in merged:
writer.writerow(merge)
if not quiet:
- out.write(u"* {} merged items ({})\n".format(nb_merged_items,
+ out.write("* {} merged items ({})\n".format(nb_merged_items,
filename))
if not quiet:
out.write("* {} distinct images\n".format(distinct_image))
diff --git a/ishtar_common/management/commands/regenerate_external_id.py b/ishtar_common/management/commands/regenerate_external_id.py
index b64629386..5d1aad88e 100644
--- a/ishtar_common/management/commands/regenerate_external_id.py
+++ b/ishtar_common/management/commands/regenerate_external_id.py
@@ -51,14 +51,14 @@ class Command(BaseCommand):
if not bool(
[k for k in dir(model) if k == "external_id"]):
continue
- msg = u"* processing {} - {}:".format(
+ msg = "* processing {} - {}:".format(
app, model._meta.verbose_name)
ln = model.objects.count()
for idx, object in enumerate(model.objects.all()):
object.skip_history_when_saving = True
object.external_id = None
object._no_move = True
- cmsg = u"\r{} {}/{}".format(msg, idx + 1, ln)
+ cmsg = "\r{} {}/{}".format(msg, idx + 1, ln)
sys.stdout.write(cmsg)
sys.stdout.flush()
object.save()
diff --git a/ishtar_common/management/commands/regenerate_qrcodes.py b/ishtar_common/management/commands/regenerate_qrcodes.py
index 6c1ed8ecc..d915d2e21 100644
--- a/ishtar_common/management/commands/regenerate_qrcodes.py
+++ b/ishtar_common/management/commands/regenerate_qrcodes.py
@@ -54,7 +54,7 @@ class Command(BaseCommand):
for app in APPS:
if limit and app != limit:
continue
- print(u"* app: {}".format(app))
+ print("* app: {}".format(app))
for model in apps.get_app_config(app).get_models():
if model_name and model.__name__.lower() != model_name:
continue
@@ -64,13 +64,13 @@ class Command(BaseCommand):
model._meta.get_field('qrcode')
except FieldDoesNotExist:
continue
- msg = u"-> processing {}: ".format(model._meta.verbose_name)
+ msg = "-> processing {}: ".format(model._meta.verbose_name)
ln = model.objects.count()
tmpdir = tempfile.mkdtemp("-qrcode")
for idx, object in enumerate(model.objects.all()):
object.skip_history_when_saving = True
object._no_move = True
- cmsg = u"\r{} {}/{}".format(msg, idx + 1, ln)
+ cmsg = "\r{} {}/{}".format(msg, idx + 1, ln)
sys.stdout.write(cmsg)
sys.stdout.flush()
object.generate_qrcode(secure=secure, tmpdir=tmpdir)
diff --git a/ishtar_common/management/commands/regenerate_search_vector_cached_label.py b/ishtar_common/management/commands/regenerate_search_vector_cached_label.py
index 6a560df80..ab7f134ff 100644
--- a/ishtar_common/management/commands/regenerate_search_vector_cached_label.py
+++ b/ishtar_common/management/commands/regenerate_search_vector_cached_label.py
@@ -51,7 +51,7 @@ class Command(BaseCommand):
if limit and app != limit:
continue
if not quiet:
- print(u"* app: {}".format(app))
+ print("* app: {}".format(app))
for model in apps.get_app_config(app).get_models():
if model_name and model.__name__.lower() != model_name:
continue
@@ -62,7 +62,7 @@ class Command(BaseCommand):
if k.startswith('_generate_') or
k == "search_vector"]):
continue
- msg = u"-> processing {}: ".format(model._meta.verbose_name)
+ msg = "-> processing {}: ".format(model._meta.verbose_name)
ln = model.objects.count()
for idx, obj_id in enumerate(model.objects.values('pk').all()):
obj = model.objects.get(pk=obj_id['pk'])
@@ -74,7 +74,7 @@ class Command(BaseCommand):
obj.point_2d = None
obj.x = None
obj.y = None
- cmsg = u"\r{} {}/{}".format(msg, idx + 1, ln)
+ cmsg = "\r{} {}/{}".format(msg, idx + 1, ln)
if not quiet:
sys.stdout.write(cmsg)
sys.stdout.flush()