attachment backend use
This commit is contained in:
@@ -211,16 +211,29 @@ def _base_path_by_path(config: CampaignConfig, rendered_base_dir: str) -> Attach
|
||||
return None
|
||||
|
||||
|
||||
def _base_path_by_id(config: CampaignConfig, base_path_id: str | None) -> AttachmentBasePathConfig | None:
|
||||
if not base_path_id:
|
||||
return None
|
||||
return next((base_path for base_path in config.attachments.base_paths if base_path.id == base_path_id), None)
|
||||
|
||||
|
||||
def _default_base_path(config: CampaignConfig) -> AttachmentBasePathConfig:
|
||||
return config.attachments.base_paths[0]
|
||||
|
||||
|
||||
def _selected_base_path(config: CampaignConfig, rendered_base_dir: str) -> AttachmentBasePathConfig | None:
|
||||
if config.attachments.base_paths:
|
||||
if rendered_base_dir in {"", "."}:
|
||||
return _default_base_path(config)
|
||||
return _base_path_by_path(config, rendered_base_dir)
|
||||
return None
|
||||
def _selected_base_path(
|
||||
config: CampaignConfig,
|
||||
attachment_config: AttachmentConfig,
|
||||
rendered_base_dir: str,
|
||||
) -> AttachmentBasePathConfig | None:
|
||||
if not config.attachments.base_paths:
|
||||
return None
|
||||
selected_by_id = _base_path_by_id(config, attachment_config.base_path_id)
|
||||
if selected_by_id is not None:
|
||||
return selected_by_id
|
||||
if rendered_base_dir in {"", "."}:
|
||||
return _default_base_path(config)
|
||||
return _base_path_by_path(config, rendered_base_dir)
|
||||
|
||||
|
||||
def _rule_allows_multiple(config: AttachmentConfig, rendered_file_filter: str) -> bool:
|
||||
@@ -248,9 +261,9 @@ def _ambiguous_behavior(campaign_config: CampaignConfig, config: AttachmentConfi
|
||||
|
||||
def _entry_attachment_allowed(config: CampaignConfig, attachment_config: AttachmentConfig, values: dict[str, Any]) -> bool:
|
||||
rendered_base_dir = _rendered_base_dir(attachment_config, values)
|
||||
individual_paths = config.attachments.individual_base_path_values
|
||||
if individual_paths:
|
||||
return rendered_base_dir in individual_paths
|
||||
selected = _selected_base_path(config, attachment_config, rendered_base_dir)
|
||||
if config.attachments.base_paths:
|
||||
return bool(selected and selected.allow_individual)
|
||||
return config.attachments.allow_individual
|
||||
|
||||
|
||||
@@ -271,6 +284,7 @@ def _resolve_attachment_directory(
|
||||
*,
|
||||
campaign_file: str | Path,
|
||||
campaign_config: CampaignConfig,
|
||||
attachment_config: AttachmentConfig,
|
||||
rendered_base_dir: str,
|
||||
) -> tuple[Path, AttachmentBasePathConfig | None]:
|
||||
"""Resolve the directory for an attachment rule.
|
||||
@@ -281,7 +295,7 @@ def _resolve_attachment_directory(
|
||||
e.g. attachments/base_path + base_dir twice.
|
||||
"""
|
||||
|
||||
selected_base_path = _selected_base_path(campaign_config, rendered_base_dir)
|
||||
selected_base_path = _selected_base_path(campaign_config, attachment_config, rendered_base_dir)
|
||||
if selected_base_path is not None:
|
||||
return _resolve_path(campaign_file, selected_base_path.path), selected_base_path
|
||||
|
||||
@@ -337,6 +351,7 @@ def _resolve_one_config(
|
||||
directory, selected_base_path = _resolve_attachment_directory(
|
||||
campaign_file=campaign_file,
|
||||
campaign_config=campaign_config,
|
||||
attachment_config=config,
|
||||
rendered_base_dir=rendered_base_dir,
|
||||
)
|
||||
matches = _match_files(directory, rendered_file_filter, config.include_subdirs)
|
||||
|
||||
Reference in New Issue
Block a user