Beispiel #1
0
def _get_derived_website_content_data(request_data: dict,
                                      site_config: SiteConfig,
                                      website_pk: str) -> dict:
    """Derives values that should be added to the request data if a WebsiteContent object is being created"""
    added_data = {}
    if "text_id" not in request_data:
        added_data["text_id"] = uuid_string()
    content_type = request_data.get("type")
    config_item = (site_config.find_item_by_name(
        name=content_type) if content_type is not None else None)
    is_page_content = False
    if site_config and config_item is not None:
        is_page_content = site_config.is_page_content(config_item)
        added_data["is_page_content"] = is_page_content
    dirpath = request_data.get("dirpath")
    if dirpath is None and config_item is not None and is_page_content:
        dirpath = config_item.file_target
        added_data["dirpath"] = dirpath
    slug_key = config_item.item.get(
        "slug") if config_item is not None else None
    if not slug_key:
        slug_key = "title"
    slug = (added_data.get(slug_key) or request_data.get(slug_key)
            or request_data.get("metadata", {}).get(slug_key))
    if slug is not None:
        added_data["filename"] = get_valid_new_filename(
            website_pk=website_pk,
            dirpath=dirpath,
            filename_base=slugify(get_valid_base_filename(slug, content_type)),
        )
    return added_data
def test_is_page_content(basic_site_config, content_dir, folder_file_target,
                         exp_result):
    """
    SiteConfig.is_page_content should return True if the folder target of the repeatable config item starts with the
    content directory in the site config (or a default value)
    """
    site_config = SiteConfig(basic_site_config)
    site_config.raw_data[WEBSITE_CONFIG_CONTENT_DIR_KEY] = content_dir
    config_item = next(item for item in site_config.iter_items()
                       if item.is_folder_item())
    config_item.item["folder"] = folder_file_target
    assert site_config.is_page_content(config_item) is exp_result
Beispiel #3
0
 def apply_rule(data):
     faulty_paths = {}
     site_config = SiteConfig(data)
     for _, config_item in enumerate(site_config.iter_items()):
         if config_item.is_folder_item() and not site_config.is_page_content(
             config_item
         ):
             faulty_paths[config_item.name] = config_item.path
     if faulty_paths:
         return [
             "Found 'folder' item(s) that do not point to the content directory ({}).\n{}".format(
                 site_config.content_dir,
                 "\n".join(
                     [
                         f"{' ' * 8}'{name}' ({path})"
                         for name, path in faulty_paths.items()
                     ]
                 ),
             )
         ]
     return []