-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from c-3lab/improve_integration_in_download_m…
…odule downloadモジュールの外部プラグイン連携強化
- Loading branch information
Showing
4 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
from ckan.views.resource import download | ||
import logging | ||
|
||
import ckan.views.resource as resource | ||
from flask import request | ||
|
||
from ckanext.feedback.services.common import config as feedback_config | ||
from ckanext.feedback.services.download.summary import increment_resource_downloads | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class DownloadController: | ||
# extend default download function to count when a resource is downloaded | ||
@staticmethod | ||
def extended_download(package_type, id, resource_id, filename=None): | ||
if request.headers.get('Sec-Fetch-Dest') == 'document': | ||
increment_resource_downloads(resource_id) | ||
return download(package_type, id, resource_id, filename=filename) | ||
|
||
handler = feedback_config.download_handler() | ||
if not handler: | ||
log.debug('Use default CKAN callback for resource.download') | ||
handler = resource.download | ||
return handler( | ||
package_type=package_type, | ||
id=id, | ||
resource_id=resource_id, | ||
filename=filename, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
import logging | ||
|
||
from ckan.model.group import Group | ||
from ckan.plugins import toolkit | ||
from werkzeug.utils import import_string | ||
|
||
from ckanext.feedback.models.session import session | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
CONFIG_HANDLER_PATH = 'ckan.feedback.download_handler' | ||
|
||
|
||
def get_organization(org_id=None): | ||
return session.query(Group.name.label('name')).filter(Group.id == org_id).first() | ||
|
||
|
||
def download_handler(): | ||
handler_path = toolkit.config.get(CONFIG_HANDLER_PATH) | ||
if handler_path: | ||
handler = import_string(handler_path, silent=True) | ||
else: | ||
handler = None | ||
log.warning(f'Missing {CONFIG_HANDLER_PATH} config option.') | ||
|
||
return handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters