Skip to content

Commit

Permalink
create a primary name based on a passed in string template, re #997
Browse files Browse the repository at this point in the history
  • Loading branch information
apeters committed Oct 21, 2016
1 parent e6a0576 commit 8a722c9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
21 changes: 16 additions & 5 deletions arches/app/functions/resource_functions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import uuid, re
from arches.app.models import models
from arches.app.models.tile import Tile

def get_primary_name_from_nodes(resource, config):
# eventally use sort order
config['nodegroupid'] = ''
config['string_template'] = '{some_nodeid} ({some_other_nodeid})'
#tile = models.Tile.objects.filter(nodegroup_id=config['nodegroupid'])[0]
#config['string_template'] % ()
return 'this is an example primary name'
#uuid_regex = '(?P<nodeid>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})'
# x = {}
# for match in re.findall(uuid_regex, config['string_template']):
# x[match] = ''

for tile in models.Tile.objects.filter(nodegroup_id=uuid.UUID(config['nodegroup_id'])):
t = Tile(tile)
t.get_node_display_values()
for nodeid, nodevalue in t.data.iteritems():
#x[nodeid] = nodevalue
print nodevalue
config['string_template'] = config['string_template'].replace('{%s}' % nodeid, nodevalue)

return config['string_template']
6 changes: 5 additions & 1 deletion arches/app/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ def __init__(self, *args, **kwargs):
def primary_name(self):
module = importlib.import_module('arches.app.functions.resource_functions')
get_primary_name = getattr(module, 'get_primary_name_from_nodes')
return get_primary_name('resource', {})
#{"7a7dfaf5-971e-11e6-aec3-14109fd34195": "Alexei", "7a7e0211-971e-11e6-a67c-14109fd34195": "a55f219a-e126-4f80-a5fd-0282efd43339"}
config = {}
config['nodegroup_id'] = '7a7dfaf5-971e-11e6-aec3-14109fd34195'
config['string_template'] = '{7a7dfaf5-971e-11e6-aec3-14109fd34195} Type({7a7e0211-971e-11e6-a67c-14109fd34195})'
return get_primary_name(self, config)
8 changes: 8 additions & 0 deletions arches/app/models/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from django.forms.models import model_to_dict
from arches.app.utils.betterJSONSerializer import JSONSerializer, JSONDeserializer
import validations as validation_methods
from arches.app.views.concept import get_preflabel_from_valueid

class Tile(object):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -86,6 +87,13 @@ def validate(self):
functions[str(node.nodeid)] = {'results': results, 'is_valid': node_is_valid}
return functions

def get_node_display_values(self):
for nodeid, nodevalue in self.data.iteritems():
if models.Node.objects.get(pk=nodeid).datatype == 'concept':
self.data[nodeid] = get_preflabel_from_valueid(nodevalue, 'en-US')['value']

return self.data

def save(self):
self.tileid, created = uuid_get_or_create(self.tileid)
tile, created = models.Tile.objects.update_or_create(
Expand Down

0 comments on commit 8a722c9

Please sign in to comment.