<commit_before>from django.core.management.base import BaseCommand
import os
import json
from django.conf import settings
from modules.models import Module, Type


class Command(BaseCommand):
    help = "Загрузка справочника модулей"

    def handle(self, *args, **options):
        def update_if_none(m, field, json_val=None):
            if json_val is None:
                return False
            if getattr(m, field) is None:
                m.__dict__[field] = json_val
                return True

        with open(os.path.join(settings.BASE_DIR, "uni_fixtures", "modules.json"), encoding='utf8') as basefile:
            fixtures = json.load(basefile)
            fieldset = (("description", "shortTitle"),
                      ("uni_uuid", "uuid"),
                      ("uni_number", "number"),
                      ("uni_coordinator", "coordinator"),
                      ("uni_type", "type"),
                      ("uni_title", "title"),
                      ("uni_competence", "competence"),
                      ("uni_testUnits", "testUnits"),
                      ("uni_priority", "priority"),
                      ("uni_state", "state"),
                      ("uni_approvedDate", "approvedDate"),
                      ("uni_comment", "comment"),
                      ("uni_specialities", "specialities"),
                      ("uni_file", "file"),
                      ("status", "p"))
            for module in fixtures:
                m = Module.objects.filter(title=module["title"]).first()
                if m:
                    print(m.title)
                    for field in fieldset:
                        update_if_none(m, field[0], module[field[1]])
                    m.save()
                else:
                    # m = Module(
                    #     title=module["title"],
                    #     type=Type.objects.get(title="Модуль") if not "модуль" not in module["type"] else Type.objects.get(title="Майнор")
                    # )
                    print(Type.objects.get(title="Модуль") if not "модуль" not in module["type"] else Type.objects.get(title="Майнор"))<commit_msg>load modules#7<commit_after>from django.core.management.base import BaseCommand
import os
import json
from django.conf import settings
from modules.models import Module, Type


class Command(BaseCommand):
    help = "Загрузка справочника модулей"

    def handle(self, *args, **options):
        def update_if_none(m, field, json_val=None):
            if json_val is None:
                return False
            if getattr(m, field) is None:
                m.__dict__[field] = json_val
                return True

        with open(os.path.join(settings.BASE_DIR, "uni_fixtures", "modules.json"), encoding='utf8') as basefile:
            fixtures = json.load(basefile)
            fieldset = (("description", "shortTitle"),
                      ("uni_uuid", "uuid"),
                      ("uni_number", "number"),
                      ("uni_coordinator", "coordinator"),
                      ("uni_type", "type"),
                      ("uni_title", "title"),
                      ("uni_competence", "competence"),
                      ("uni_testUnits", "testUnits"),
                      ("uni_priority", "priority"),
                      ("uni_state", "state"),
                      ("uni_approvedDate", "approvedDate"),
                      ("uni_comment", "comment"),
                      ("uni_specialities", "specialities"),
                      ("uni_file", "file"))
            for module in fixtures:
                m = Module.objects.filter(title=module["title"]).first()
                if m:
                    print(m.title)
                    for field in fieldset:
                        update_if_none(m, field[0], module[field[1]])
                    m.save()
                else:
                    # m = Module(
                    #     title=module["title"],
                    #     type=Type.objects.get(title="Модуль") if not "модуль" not in module["type"] else Type.objects.get(title="Майнор")
                    # )
                    print(Type.objects.get(title="Модуль") if not "модуль" not in module["type"] else Type.objects.get(title="Майнор"))
{'fraction_non_alphanumeric': 0.1264719736222327, 'fraction_numerical': 0.0016486104569006124, 'mean_word_length': 1.5522836538461537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2401238', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1095, 'n_words': 248}