-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from specklesystems/bilal/cnx-892-replace-pla…
…ceholder-version-dialog Bilal/cnx 892 replace placeholder version dialog
- Loading branch information
Showing
5 changed files
with
105 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from specklepy.api.client import SpeckleClient | ||
from specklepy.api.credentials import get_local_accounts | ||
from typing import List, Tuple, Optional | ||
from .misc import format_relative_time | ||
from specklepy.core.api.inputs.model_inputs import ModelVersionsFilter | ||
|
||
def get_versions_for_model(account_id: str, project_id: str, model_id: str, search: Optional[str] = None) -> List[Tuple[str, str, str]]: | ||
""" | ||
Fetch versions for a given model from the Speckle server. | ||
Args: | ||
account_id: The ID of the Speckle account to fetch versions for | ||
project_id: The ID of the project containing the model | ||
model_id: The ID of the model to fetch versions from | ||
search: Optional search string to filter versions | ||
Returns: | ||
List of tuples containing (version_id, message, last_updated) | ||
Returns empty list if any error occurs | ||
""" | ||
try: | ||
# Validate inputs | ||
if not account_id or not project_id or not model_id: | ||
print(f"Error: Invalid inputs - account_id: {account_id}, project_id: {project_id}, model_id: {model_id}") | ||
return [] | ||
|
||
# Get the account info | ||
account = next((acc for acc in get_local_accounts() if acc.id == account_id), None) | ||
if not account: | ||
print(f"Error: Could not find account with ID: {account_id}") | ||
return [] | ||
|
||
# Initialize the client | ||
client = SpeckleClient(host=account.serverInfo.url) | ||
# Authenticate | ||
client.authenticate_with_account(account) | ||
|
||
filter = ModelVersionsFilter(search=search, priorityIds=[]) | ||
|
||
# Get versions | ||
versions = client.version.get_versions(project_id=project_id, model_id=model_id, limit=10, filter=filter).items | ||
|
||
return [(version.id, version.message or "No message", format_relative_time(version.createdAt)) for version in versions] | ||
|
||
except Exception as e: | ||
print(f"Error fetching versions: {str(e)}") | ||
return [] |