Skip to content

Commit

Permalink
Merge pull request #627 from mapswipe/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Hagellach37 committed Dec 19, 2022
2 parents fbfcdff + bb16ef8 commit f12a789
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from apps.existing_database.models import Project
from django.core.management.base import BaseCommand
from django.db import models

EMTPY_TEXT = ""


@staticmethod
def parse_organization_name(name):
if name and "\n" in name:
name_parts = [x.strip() for x in name.split("\n")]
if name_parts[1] != "":
return name_parts[1]
return EMTPY_TEXT # Return empty to track this as proccessed


class Command(BaseCommand):
def handle(self, **_):
updated_projects = []
project_qs = Project.objects.filter(
models.Q(organization_name__isnull=True)
& ~models.Q(organization_name=EMTPY_TEXT)
)
self.stdout.write(f"Projects to update: {project_qs.count()}")
for project_id, name in project_qs.values_list("project_id", "name"):
organization_name = parse_organization_name(name)
updated_projects.append(
Project(
project_id=project_id,
organization_name=organization_name,
)
)
Project.objects.bulk_update(updated_projects, ["organization_name"])
self.stdout.write(
self.style.SUCCESS(f"Successfully updated: {len(updated_projects)}")
)

0 comments on commit f12a789

Please sign in to comment.