Code Duplication    Length = 18-20 lines in 2 locations

met/metadataparser/models/federation.py 1 location

@@ 132-151 (lines=20) @@
129
130
        return removed
131
132
    def _get_or_create_ecategories(self, entity, cached_entity_categories):
133
        entity_categories = []
134
        efed = Entity_Federations.objects.get_or_create(federation=self, entity=entity)[0]
135
        cur_cached_categories = [
136
            t.category_id for t in efed.entity_categories.all()]
137
        for ecategory in entity.xml_categories:
138
            if ecategory in cur_cached_categories:
139
                break
140
141
            if cached_entity_categories is None:
142
                entity_category, _ = EntityCategory.objects.get_or_create(
143
                    category_id=ecategory)
144
            else:
145
                if ecategory in cached_entity_categories:
146
                    entity_category = cached_entity_categories[ecategory]
147
                else:
148
                    entity_category = EntityCategory.objects.create(
149
                        category_id=ecategory)
150
            entity_categories.append(entity_category)
151
        return entity_categories
152
153
    def _update_entities(self, entities_to_update, entities_to_add):
154
        for e in entities_to_update:

met/metadataparser/models/entity.py 1 location

@@ 368-385 (lines=18) @@
365
        else:
366
            raise ValueError("Not metadata loaded")
367
368
    def _get_or_create_etypes(self, cached_entity_types):
369
        entity_types = []
370
        cur_cached_types = [t.xmlname for t in self.types.all()]
371
        for etype in self.xml_types:
372
            if etype in cur_cached_types:
373
                break
374
375
            if cached_entity_types is None:
376
                entity_type, _ = EntityType.objects.get_or_create(xmlname=etype,
377
                                                                  name=DESCRIPTOR_TYPES_DISPLAY[etype])
378
            else:
379
                if etype in cached_entity_types:
380
                    entity_type = cached_entity_types[etype]
381
                else:
382
                    entity_type = EntityType.objects.create(xmlname=etype,
383
                                                            name=DESCRIPTOR_TYPES_DISPLAY[etype])
384
            entity_types.append(entity_type)
385
        return entity_types
386
387
    def process_metadata(self, auto_save=True, entity_data=None, cached_entity_types=None, federation=None):
388
        if not entity_data: