Skip to content

Commit

Permalink
Merge pull request #163 from c-3lab/add-organization-name-to-template…
Browse files Browse the repository at this point in the history
…-vars

組織名が特定可能な場合にテンプレートで取得できるようにする
  • Loading branch information
ryo-ma committed May 16, 2024
2 parents 3b6a430 + da971ed commit 7b87958
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ckanext/feedback/controllers/management.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ckan.common import _, current_user, request
from ckan.common import _, current_user, g, request
from ckan.lib import helpers
from ckan.plugins import toolkit
from flask import redirect, url_for
Expand Down Expand Up @@ -32,6 +32,11 @@ def comments():
utilization_comments = utilization_detail_service.get_utilization_comments(
owner_orgs=ids
)
g.pkg_dict = {
'organization': {
'name': current_user.get_groups(group_type='organization')[0].name,
}
}
else:
resource_comments = resource_comment_service.get_resource_comments()
utilization_comments = utilization_detail_service.get_utilization_comments()
Expand Down
7 changes: 6 additions & 1 deletion ckanext/feedback/controllers/resource.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ckan.model as model
from ckan.common import _, current_user, request
from ckan.common import _, current_user, g, request
from ckan.lib import helpers
from ckan.logic import get_action
from ckan.plugins import toolkit
Expand Down Expand Up @@ -36,6 +36,11 @@ def comment(resource_id):
cookie = comment_service.get_cookie(resource_id)
context = {'model': model, 'session': session, 'for_view': True}
package = get_action('package_show')(context, {'id': resource.package_id})
g.pkg_dict = {
'organization': {
'name': resource.package.get_groups(group_type='organization')[0].name
}
}

return toolkit.render(
'resource/comment.html',
Expand Down
40 changes: 39 additions & 1 deletion ckanext/feedback/controllers/utilization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ckan.model as model
from ckan.common import _, current_user, request
from ckan.common import _, current_user, g, request
from ckan.lib import helpers
from ckan.logic import get_action
from ckan.plugins import toolkit
Expand Down Expand Up @@ -48,6 +48,23 @@ def search():
id, keyword, approval, admin_owner_orgs, org_name
)

# If the organization name can be identified,
# set it as a global variable accessible from templates.
if id and not org_name:
resource = registration_service.get_resource(id)
if resource:
package = resource.package
else:
package = model.Package.get(id)
if package:
org_name = package.get_groups(group_type='organization')[0].name
if org_name:
g.pkg_dict = {
'organization': {
'name': org_name,
},
}

return toolkit.render(
'utilization/search.html',
{
Expand All @@ -65,6 +82,11 @@ def new():
resource = registration_service.get_resource(resource_id)
context = {'model': model, 'session': session, 'for_view': True}
package = get_action('package_show')(context, {'id': resource.package.id})
g.pkg_dict = {
'organization': {
'name': resource.package.get_groups(group_type='organization')[0].name
}
}

return toolkit.render(
'utilization/new.html',
Expand Down Expand Up @@ -120,6 +142,13 @@ def details(utilization_id):
comments = detail_service.get_utilization_comments(utilization_id, approval)
categories = detail_service.get_utilization_comment_categories()
issue_resolutions = detail_service.get_issue_resolutions(utilization_id)
g.pkg_dict = {
'organization': {
'name': registration_service.get_resource(utilization.resource_id)
.package.get_groups(group_type='organization')[0]
.name
}
}

return toolkit.render(
'utilization/details.html',
Expand Down Expand Up @@ -185,6 +214,15 @@ def edit(utilization_id):
resource_details = edit_service.get_resource_details(
utilization_details.resource_id
)
g.pkg_dict = {
'organization': {
'name': registration_service.get_resource(
utilization_details.resource_id
)
.package.get_groups(group_type='organization')[0]
.name
}
}

return toolkit.render(
'utilization/edit.html',
Expand Down

0 comments on commit 7b87958

Please sign in to comment.