Skip to content

Commit

Permalink
Merge pull request #661 from xchem/m2ms-1508-tag-format
Browse files Browse the repository at this point in the history
Updated tag name format (issue 1508)
  • Loading branch information
kaliif authored Sep 11, 2024
2 parents 65de5c0 + 13b0da4 commit a7c5345
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions viewer/target_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
XtalformQuatAssembly,
XtalformSite,
)
from viewer.utils import alphanumerator, sanitize_directory_name
from viewer.utils import alphanumerator, clean_object_id, sanitize_directory_name

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -407,7 +407,6 @@ def wrapper_create_objects(
# index data here probs
result[instance_data.versioned_key] = m

result = {}
if result:
msg = "{} {} objects processed, {} created, {} fetched from database".format(
created + existing + failed,
Expand Down Expand Up @@ -2157,6 +2156,10 @@ def _tag_observations(
tag = tag if short_tag is None else short_tag
short_name = name if short_tag is None else f"{prefix} - {short_tag}"

tag = clean_object_id(tag)
name = clean_object_id(name)
short_name = clean_object_id(short_name)

try:
so_tag = SiteObservationTag.objects.get(
upload_name=name, target=self.target
Expand Down
9 changes: 9 additions & 0 deletions viewer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,12 @@ def sanitize_directory_name(name: str, path: Path | None = None) -> str:
sanitized_name = new_name

return sanitized_name


def clean_object_id(name: str) -> str:
"""Replace '/' and '+' with '/' in XCA object identifiers"""
splits = name.split('-x')
if len(splits) > 1:
return f"{splits[0]}-x{splits[1].replace('+', '/').replace('_', '/')}"
else:
return name.replace('+', '/').replace('_', '/')

0 comments on commit a7c5345

Please sign in to comment.