Skip to content

Commit

Permalink
Make primary descriptor fn aware of which description it's calculating
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored Dec 1, 2023
1 parent 4513ca1 commit bdb36dc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions arches/app/functions/primary_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,30 @@


class AbstractPrimaryDescriptorsFunction(BaseFunction):
def get_primary_descriptor_from_nodes(self, resource, config, context=None):
def get_primary_descriptor_from_nodes(self, resource, config, context=None, descriptor=None):
"""
Arguments:
resource -- the resource instance to which the primary decriptor will be assigned
config -- the descriptor config which indicates how and what will define the descriptor
Keyword Arguments:
context -- string such as "copy" to indicate conditions under which a resource participates in a function.
descriptor -- type of descriptor, e.g. "name", "map_popup", or "description"
"""

pass


class PrimaryDescriptorsFunction(AbstractPrimaryDescriptorsFunction):
def get_primary_descriptor_from_nodes(self, resource, config, context=None):
def get_primary_descriptor_from_nodes(self, resource, config, context=None, descriptor=None):
"""
Arguments:
resource -- the resource instance to which the primary decriptor will be assigned
config -- the descriptor config which indicates how and what will define the descriptor
Keyword Arguments:
context -- string such as "copy" to indicate conditions under which a resource participates in a function.
descriptor -- type of descriptor, e.g. "name", "map_popup", or "description"
"""

datatype_factory = None
Expand Down
2 changes: 1 addition & 1 deletion arches/app/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def calculate_descriptors(self, descriptors=("name", "description", "map_popup")
if len(self.descriptor_function) == 1:
module = self.descriptor_function[0].function.get_class_module()()
self.descriptors[language][descriptor] = module.get_primary_descriptor_from_nodes(
self, self.descriptor_function[0].config["descriptor_types"][descriptor], context
self, self.descriptor_function[0].config["descriptor_types"][descriptor], context, descriptor
)
if descriptor == "name" and self.descriptors[language][descriptor] is not None:
self.name[language] = self.descriptors[language][descriptor]
Expand Down
2 changes: 1 addition & 1 deletion arches/app/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def get_name(self, resource):
).select_related("function")
if len(graph_function) == 1:
module = graph_function[0].function.get_class_module()()
return module.get_primary_descriptor_from_nodes(self, graph_function[0].config["descriptor_types"]["name"])
return module.get_primary_descriptor_from_nodes(self, graph_function[0].config["descriptor_types"]["name"], descriptor="name")
else:
return _("Unnamed Resource")

Expand Down

0 comments on commit bdb36dc

Please sign in to comment.