From 89fa7c5d569cf4cfc92c86adbb00baca2e26ef68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Tue, 12 Nov 2019 18:37:43 +0300 Subject: [PATCH] Fix for merge --- .../management/commands/update_employee.py | 10 +++------- .../management/commands/add_product_tag.py | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/apps/establishment/management/commands/update_employee.py b/apps/establishment/management/commands/update_employee.py index dfe8b5a0..41831f0d 100644 --- a/apps/establishment/management/commands/update_employee.py +++ b/apps/establishment/management/commands/update_employee.py @@ -2,8 +2,7 @@ from django.core.management.base import BaseCommand from django.db import connections from establishment.management.commands.add_position import namedtuplefetchall from establishment.models import Employee -from django.db.models import Q - +from tqdm import tqdm class Command(BaseCommand): help = 'Add employee from old db to new db.' @@ -28,10 +27,7 @@ class Command(BaseCommand): def handle(self, *args, **options): objects = [] - for e in self.employees_sql(): - empl = Employee.objects.filter(old_id=e.profile_id) - if empl.exists(): - empl.name = e.name - empl.save() + for e in tqdm(self.employees_sql()): + empl = Employee.objects.filter(old_id=e.profile_id).update(name=e.name) self.stdout.write(self.style.WARNING(f'Update employee name objects.')) diff --git a/apps/product/management/commands/add_product_tag.py b/apps/product/management/commands/add_product_tag.py index a0f56b71..5633230c 100644 --- a/apps/product/management/commands/add_product_tag.py +++ b/apps/product/management/commands/add_product_tag.py @@ -57,7 +57,7 @@ class Command(BaseCommand): for t in tqdm(self.tag_sql(), desc='Add tags'): category = TagCategory.objects.get(index_name=t.tag_category) - tag = Tag.objects.filter(label={"en-GB": t.tag_value}, + tag = Tag.objects.filter( category=category, value=t.tag_value ) @@ -96,7 +96,21 @@ class Command(BaseCommand): self.stdout.write(self.style.WARNING(f'Add or get tag objects.')) + def check_tag(self): + tags = Tag.objects.filter(value__contains='_').all() + for tag in tqdm(tags, desc='Check label for tag'): + new_label = {} + for k, v in tag.label.items(): + if isinstance(v, str) and '_' in v: + sp = v.split('_') + v = ' '.join([sp[0].capitalize()] + sp[1:]) + new_label[k] = v + tag.label = new_label + tag.save() + + def handle(self, *args, **kwargs): self.add_category_tag() self.add_tag() - self.add_product_tag() \ No newline at end of file + self.add_product_tag() + self.check_tag() \ No newline at end of file