Beispiel #1
0
 def has_uuid(uuid, product_data):
     has = is_correct_uuid(uuid)
     if not has:
         logger.info(
             NOT_SAVE_TEMPLATE.format(entity='Product',
                                      name=product_data['name'],
                                      field='uuid'))
     return has
Beispiel #2
0
 def has_uuid(uuid, product_data):
     has = is_correct_uuid(uuid)
     if not has:
         logger.info(NOT_SAVE_TEMPLATE.format(
             entity='Product',
             name=product_data['name'],
             field='uuid'
         ))
     return has
Beispiel #3
0
    def assembly_structure(group_uuid: str, group_data_: dict):
        tags_data = group_data_.pop('tags_data', [])
        tags = {
            tag_uuid: {
                'name': tag_name
            }
            for tag_uuid, tag_name in tags_data if is_correct_uuid(tag_uuid)
        }

        return (group_uuid, {**group_data_, 'tags': tags})
Beispiel #4
0
    def assembly_structure(group_uuid: str, group_data_: dict):
        tags_data = group_data_.pop('tags_data', [])
        tags = {
            tag_uuid: {'name': tag_name}
            for tag_uuid, tag_name in tags_data
            if is_correct_uuid(tag_uuid)
        }

        return (
            group_uuid, {
                **group_data_,
                'tags': tags
            }
        )
Beispiel #5
0
def prepare_data(group_data: Iterator) -> Dict[UUID_TYPE, Data]:
    def assembly_structure(group_uuid: str, group_data_: dict):
        tags_data = group_data_.pop('tags_data', [])
        tags = {
            tag_uuid: {
                'name': tag_name
            }
            for tag_uuid, tag_name in tags_data if is_correct_uuid(tag_uuid)
        }

        return (group_uuid, {**group_data_, 'tags': tags})

    return dict(
        assembly_structure(group_uuid, data) for group_uuid, data in group_data
        if is_correct_uuid(group_uuid))
Beispiel #6
0
def fetch_products(root: Element, config: XmlFile) -> Iterator:
    product_els = root.findall(config.xpaths['products'])
    for product_el in product_els:
        name = product_el.find(config.xpaths['name']).text
        uuid = product_el.find(config.xpaths['uuid']).text
        vendor_code = product_el.find(
            config.xpaths['vendor_code']).text.lstrip('0')
        content = product_el.find(config.xpaths['page_content']).text or ''

        tag_value_els = [
            (tag_el.find(config.xpaths['tag_group_uuid']),
             tag_el.find(config.xpaths['tag_value_or_uuid']))
            for tag_el in product_el.findall(config.xpaths['tags'])
            if tag_el is not None
        ]

        tag_uuids = list(
            filter(
                is_correct_uuid,
                (
                    tag_value.text for tag_group, tag_value in tag_value_els
                    # should use 'is not None', because __bool__ does not defined
                    if tag_value is not None)))

        for tag_group, tag_value in tag_value_els:
            if (tag_value is None or tag_value.text is None
                    or is_correct_uuid(tag_value.text)):
                continue

            try:
                tg = TagGroup.objects.get(uuid=tag_group.text)
                tag_by_value = Tag.objects.get_or_create(name=tag_value.text,
                                                         group=tg)[0]
                tag_uuids.append(str(tag_by_value.uuid))
            except TagGroup.DoesNotExist:
                pass

        tags = Tag.objects.filter(uuid__in=tag_uuids)

        yield uuid, {
            'name': name,
            'vendor_code': vendor_code,
            'page': {
                'content': content
            },
            'tags': tags
        }
Beispiel #7
0
def prepare_data(group_data: Iterator) -> Dict[UUID_TYPE, Data]:
    def assembly_structure(group_uuid: str, group_data_: dict):
        tags_data = group_data_.pop('tags_data', [])
        tags = {
            tag_uuid: {'name': tag_name}
            for tag_uuid, tag_name in tags_data
            if is_correct_uuid(tag_uuid)
        }

        return (
            group_uuid, {
                **group_data_,
                'tags': tags
            }
        )

    return dict(
        assembly_structure(group_uuid, data)
        for group_uuid, data in group_data
        if is_correct_uuid(group_uuid)
    )