Skip to content

Commit

Permalink
Title should be formatted - [ShortCollectionName] - [Sample Type] Sam…
Browse files Browse the repository at this point in the history
…ple [SampleNumber] #261
  • Loading branch information
NTaherifar committed Jul 22, 2024
1 parent 87ffe5c commit 41a1093
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
25 changes: 21 additions & 4 deletions ckan/src/ckanext-igsn-theme/ckanext/igsn_theme/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def package_create(next_action, context, data_dict):
for f in schema['owner_org']
]

data_dict['name'] = generate_sample_name(data_dict)
data_dict['name'] = generate_sample_name(data_dict)
data_dict['title'] = generate_sample_title(data_dict)

manage_parent_related_resource(data_dict)

if 'private' in data_dict and data_dict['private'] == 'False':
Expand Down Expand Up @@ -90,7 +92,9 @@ def package_update(next_action, context, data_dict):
# logger = logging.getLogger(__name__)
# logger.info("package_update data_dict: %s", pformat(data_dict))

data_dict['name'] = generate_sample_name(data_dict)
data_dict['name'] = generate_sample_name(data_dict)
data_dict['title'] = generate_sample_title(data_dict)

manage_parent_related_resource(data_dict)

package = get_package_object(context, {'id': data_dict['id']})
Expand Down Expand Up @@ -174,7 +178,7 @@ def manage_parent_related_resource(data_dict):
data_dict['related_resource'] = json.dumps(related_resources)

def generate_sample_name(data_dict):
owner_org=data_dict['owner_org']
owner_org = data_dict['owner_org']
sample_type = data_dict['sample_type']
sample_number = data_dict['sample_number']
org_name= tk.get_action('organization_show')({}, {'id': owner_org})['name']
Expand All @@ -184,8 +188,22 @@ def generate_sample_name(data_dict):

name = f"{org_name}-{sample_type}-Sample-{sample_number}"
name = re.sub(r'[^a-z0-9-_]', '', name.lower())

return name

def generate_sample_title(data_dict):
owner_org = data_dict['owner_org']
sample_type = data_dict['sample_type']
sample_number = data_dict['sample_number']
org_name= tk.get_action('organization_show')({}, {'id': owner_org})['name']
org_name = org_name
sample_type = sample_type
sample_number = sample_number

title= f"{org_name} - {sample_type} Sample {sample_number}"

return title

# We do not need user_create customization here.
# Users do not need to be a part of an organization by default.
@tk.chained_action
Expand Down Expand Up @@ -320,7 +338,6 @@ def organization_member_create(next_action, context, data_dict):
except Exception as e:
logger.error(f'Unexpected error during member addition: {e}')
raise tk.ValidationError({'error': ['Unexpected error during member addition. Please contact support.']})

if member is not None:
email_notifications.organization_member_create_notify_email(context, data_dict)
return member
Expand Down
15 changes: 13 additions & 2 deletions ckan/src/ckanext-igsn-theme/ckanext/igsn_theme/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ def generate_sample_name(self,org_id, sample_type, sample_number):
name = re.sub(r'[^a-z0-9-_]', '', name.lower())
return name

def generate_sample_title(self,org_id, sample_type, sample_number):

org_name= self.get_organization_name(org_id)
org_name = org_name
sample_type = sample_type
sample_number = sample_number

title= f"{org_name} - {sample_type} Sample {sample_number}"
return title

def get_organization_name(self , organization_id):
try:
organization = get_action('organization_show')({}, {'id': organization_id})
Expand Down Expand Up @@ -209,7 +219,10 @@ def prepare_samples_data(self, samples_df, authors_df, related_resources_df, fun
"resource_type": "PhysicalObject",
}
sample.update(defaults)

sample["name"] = self.generate_sample_name(org_id, sample['sample_type'], sample['sample_number'])
sample["title"] = self.generate_sample_title(org_id, sample['sample_type'], sample['sample_number'])

samples_data.append(sample)

return samples_data
Expand Down Expand Up @@ -781,8 +794,6 @@ def request_join_collection():
org_id = toolkit.request.args.get('org_id')
organization = get_action('organization_show')({}, {'id': org_id})
org_name = organization['name']
contact_email = organization['contact_email']
contact_name = organization['contact_name']

extra_vars = {
'data': {},
Expand Down

0 comments on commit 41a1093

Please sign in to comment.