Skip to content

Commit

Permalink
feat(merge attributes): update replace_uri_in_template_string util func
Browse files Browse the repository at this point in the history
Signed-off-by: David Wallace <[email protected]>
  • Loading branch information
MyPyDavid committed Jun 18, 2024
1 parent 9c1cafb commit 13506f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion rdmo/management/management/commands/merge_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def replace_attribute_in_view_template(source=None, target=None, save_changes=Fa
replacement_results = []
for instance in qs:

template_target = replace_uri_in_template_string(instance.template, source, target)
template_target = replace_uri_in_template_string(instance.template, source.uri, target.uri)
instance.template = template_target

if save_changes and update_views:
Expand Down
19 changes: 6 additions & 13 deletions rdmo/management/utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
from rdmo.domain.models import Attribute

def replace_uri_in_template_string(template: str, source_uri: str, target_uri: str) -> str:
patterns = [f"'{source_uri}'", f'"{source_uri}"']
replacements = [f"'{target_uri}'", f'"{target_uri}"']

def replace_uri_in_template_string(template: str, source: Attribute, target: Attribute) -> str:
new_lines = []
path_changed = source.path != target.path
for line in template.splitlines():
new_line = line
if source.uri in line:
new_line = new_line.replace(source.uri, target.uri)
if path_changed:
if source.path in new_line:
new_line = new_line.replace(source.path, target.path)
new_lines.append(new_line)
new_template = "\n".join(new_lines)
new_template = template
for pattern, replacement in zip(patterns, replacements):
new_template = new_template.replace(pattern, replacement)
return new_template

0 comments on commit 13506f7

Please sign in to comment.