Skip to content

Commit

Permalink
Merge pull request #42 from atlanhq/fix-readme
Browse files Browse the repository at this point in the history
Update create method of Readme asset
  • Loading branch information
ErnestoLoma authored May 2, 2023
2 parents 0b1c9c4 + e45f556 commit e94ed3f
Show file tree
Hide file tree
Showing 6 changed files with 833 additions and 21 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.25 (May 2, 2023)

* Update create method for Readme asset

## 0.0.24 (Apr 27, 2023)

* Fix broken link in README.md
Expand Down
53 changes: 46 additions & 7 deletions pyatlan/generator/templates/entity.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ from pyatlan.model.structs import (
PopularityInsights,
)
from pyatlan.utils import next_id
from urllib.parse import quote, unquote

def validate_single_required_field(field_names: list[str], values: list[Any]):
indexes = [idx for idx, value in enumerate(values) if value is not None]
Expand Down Expand Up @@ -231,7 +232,7 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes

ba_id = CustomMetadataCache.get_id_for_name(name)
if ba_id is None:
raise ValueError(f"No business attributes with the name: {name} exist")
raise ValueError(f"No custom metadata with the name: {name} exist")
for a_type in CustomMetadataCache.types_by_asset[self.type_name]:
if (
hasattr(a_type, "_meta_data_type_name")
Expand Down Expand Up @@ -343,15 +344,29 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
{%- if entity_def.name == "Readme" %}
@classmethod
# @validate_arguments()
def create(cls, asset: Asset) -> Readme:
def create(
cls, *, asset: Asset, content: str, asset_name: Optional[str] = None
) -> Readme:
return Readme(
attributes=Readme.Attributes(
qualified_name=f"{asset.guid}/readme",
name=f"{asset.attributes.name} Readme",
),
attributes=Readme.Attributes.create(
asset=asset, content=content, asset_name=asset_name
)
)

@property
def description(self) -> Optional[str]:
ret_value = self.attributes.description
return unquote(ret_value) if ret_value is not None else ret_value

@description.setter
def description(self, description: Optional[str]):
if self.attributes is None:
self.attributes = self.Attributes()
self.attributes.description = (
quote(description) if description is not None else description
)
{%- endif %}
{%- if entity_def.attribute_defs %}
{%- if entity_def.attribute_defs or entity_def.relationship_attribute_defs %}
class Attributes({{super_classes[0]}}.Attributes):
{%- for attribute_def in entity_def.attribute_defs %}
{%- set type = attribute_def.typeName | get_type %}
Expand Down Expand Up @@ -424,6 +439,30 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
raise ValueError(
"One of admin_user, admin_groups or admin_roles is required"
)
{%- elif entity_def.name == "Readme" %}
@classmethod
# @validate_arguments()
def create(
cls, *, asset: Asset, content: str, asset_name: Optional[str] = None
) -> Readme.Attributes:
validate_required_fields(["asset", "content"], [asset, content])
if not asset.name:
if not asset_name:
raise ValueError(
"asset_name is required when name is not available from asset"
)
elif asset_name:
raise ValueError(
"asset_name can not be given when name is available from asset"
)
else:
asset_name = asset.name
return Readme.Attributes(
qualified_name=f"{asset.guid}/readme",
name=f"{asset_name} Readme",
asset=asset,
description=quote(content),
)
{%- elif entity_def.name == "Database" %}
@classmethod
# @validate_arguments()
Expand Down
Loading

0 comments on commit e94ed3f

Please sign in to comment.