Skip to content

Commit

Permalink
Merge pull request #178 from shubham-mahajan/feature/preview
Browse files Browse the repository at this point in the history
Feature/preview
  • Loading branch information
boukepieter authored Feb 12, 2024
2 parents 87be488 + a7f757d commit 3539f6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def fetch_forecast_details(self, request_type, search_string):
engine = create_engine(self.db_uri)
query = None
if request_type == 'project':
query = f"SELECT * FROM [ckan].[projects]('%{search_string}%') ORDER BY name"
query = f"SELECT name FROM [Forecast].[projects] WHERE UPPER(name) LIKE '%{search_string}%' ORDER BY name"
elif request_type == 'product':
query = f"SELECT name FROM [dbo].[products] WHERE UPPER(name) LIKE '%{search_string.upper()}%' ORDER BY name"
# query = "SELECT * FROM [dbo].[products]"
Expand Down
19 changes: 11 additions & 8 deletions src/ckanext-data-catalog-510/ckanext/data_catalog_510/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def fetch_data_for_datapusher(self, context, data):
"resource_id": data.get("id"),
"force": True,
"records": data.get("preview_data"),
"fields": [
{"id": key, "type": "text"} for key in data.get("preview_data")[0]
],
}
try:
delete = toolkit.get_action("datastore_delete")(
Expand All @@ -182,7 +185,9 @@ def fetch_data_for_datapusher(self, context, data):
log.error(e)
try:
datastore_create = toolkit.get_action("datastore_create")(context, request)
resource_view_list = toolkit.get_action("resource_view_list")(context, {"id":data.get('id')})
resource_view_list = toolkit.get_action("resource_view_list")(
context, {"id": data.get("id")}
)
if len(resource_view_list) == 0:
resource_view_create = toolkit.get_action("resource_view_create")(
context,
Expand All @@ -204,14 +209,12 @@ def before_resource_create(self, context, current):
except Exception as e:
log.error(e)
return current

def after_resource_create(self, context, current):
try:

self.current_resource_with_preview['id'] = current.get('id')
self.fetch_data_for_datapusher(
context, self.current_resource_with_preview
)

self.current_resource_with_preview["id"] = current.get("id")
self.fetch_data_for_datapusher(context, self.current_resource_with_preview)
except Exception as e:
log.error(e)
return current
Expand All @@ -220,7 +223,7 @@ def before_resource_update(self, context, current, data_dict):
try:
self.fetch_data_for_datapusher(context, data_dict)
data_dict["datastore_active"] = True
if 'preview_data' in data_dict:
if "preview_data" in data_dict:
del data_dict["preview_data"]
except Exception as e:
log.error(e)
Expand Down

0 comments on commit 3539f6c

Please sign in to comment.