def details(short_name): app, n_tasks, n_task_runs, overall_progress, last_activity = app_by_shortname(short_name) try: require.app.read(app) template = '/applications/app.html' except HTTPException: if app.hidden: raise abort(403) else: raise title = app_title(app, None) template_args = {"app": app, "title": title, "n_tasks": n_tasks, "overall_progress": overall_progress, "last_activity": last_activity} try: if current_app.config.get('CKAN_URL'): template_args['ckan_name'] = current_app.config.get('CKAN_NAME') ckan = Ckan(url=current_app.config['CKAN_URL']) pkg, e = ckan.package_exists(name=short_name) if e: raise e if pkg: template_args['ckan_pkg_url'] = ( "%s/dataset/%s" % (current_app.config['CKAN_URL'], short_name)) template_args['ckan_pkg'] = pkg except requests.exceptions.ConnectionError: current_app.logger.error("CKAN server down or there is a typo in the URL") except Exception as e: current_app.logger.error(e) return render_template(template, **template_args)
def details(short_name): app = app_by_shortname(short_name) try: require.app.read(app) template = '/applications/app.html' except HTTPException: if app.hidden: raise abort(403) else: raise title = app_title(app, None) template_args = {"app": app, "title": title} try: if current_app.config.get('CKAN_URL'): template_args['ckan_name'] = current_app.config.get('CKAN_NAME') ckan = Ckan(url=current_app.config['CKAN_URL']) pkg, e = ckan.package_exists(name=short_name) if e: raise e if pkg: template_args['ckan_pkg_url'] = ( "%s/dataset/%s" % (current_app.config['CKAN_URL'], short_name)) template_args['ckan_pkg'] = pkg except requests.exceptions.ConnectionError: current_app.logger.error("CKAN server down or there is a typo in the URL") except Exception as e: current_app.logger.error(e) return render_template(template, **template_args)
def respond_ckan(ty): # First check if there is a package (dataset) in CKAN tables = {"task": model.Task, "task_run": model.TaskRun} msg_1 = gettext("Data exported to ") msg = msg_1 + "%s ..." % current_app.config['CKAN_URL'] ckan = Ckan(url=current_app.config['CKAN_URL'], api_key=current_user.ckan_api) app_url = url_for('.details', short_name=app.short_name, _external=True) try: package, e = ckan.package_exists(name=app.short_name) if e: raise e if package: # Update the package owner = User.query.get(app.owner_id) package = ckan.package_update(app=app, user=owner, url=app_url, resources=package['resources']) ckan.package = package resource_found = False # print len(package['resources']) for r in package['resources']: if r['name'] == ty: ckan.datastore_delete(name=ty, resource_id=r['id']) ckan.datastore_create(name=ty, resource_id=r['id']) ckan.datastore_upsert(name=ty, records=gen_json(tables[ty]), resource_id=r['id']) resource_found = True break if not resource_found: create_ckan_datastore(ckan, ty, package['id']) else: owner = User.query.get(app.owner_id) package = ckan.package_create(app=app, user=owner, url=app_url) create_ckan_datastore(ckan, ty, package['id']) #new_resource = ckan.resource_create(name=ty, # package_id=package['id']) #ckan.datastore_create(name=ty, # resource_id=new_resource['result']['id']) #ckan.datastore_upsert(name=ty, # records=gen_json(tables[ty]), # resource_id=new_resource['result']['id']) flash(msg, 'success') return respond() except requests.exceptions.ConnectionError: msg = "CKAN server seems to be down, try again layer or contact the CKAN admins" current_app.logger.error(msg) flash(msg, 'danger') except Exception as inst: if len(inst.args) == 3: t, msg, status_code = inst.args msg = ("Error: %s with status code: %s" % (t, status_code)) else: # pragma: no cover msg = ("Error: %s" % inst.args[0]) current_app.logger.error(msg) flash(msg, 'danger') finally: return respond()
def respond_ckan(ty): # First check if there is a package (dataset) in CKAN tables = {"task": model.Task, "task_run": model.TaskRun} msg_1 = lazy_gettext("Data exported to ") msg = msg_1 + "%s ..." % current_app.config['CKAN_URL'] ckan = Ckan(url=current_app.config['CKAN_URL'], api_key=current_user.ckan_api) app_url = url_for('.details', short_name=app.short_name, _external=True) try: package = ckan.package_exists(name=app.short_name) if package: # Update the package ckan.package_update(app=app, user=app.owner, url=app_url) if len(package['resources']) == 0: resources = create_ckan_datastores(ckan) ckan.datastore_upsert(name=ty, records=gen_json(tables[ty]), resource_id=resources[ty]['id']) flash(msg, 'success') return render_template('/applications/export.html', title=title, app=app) else: ckan.datastore_delete(name=ty) ckan.datastore_create(name=ty) ckan.datastore_upsert(name=ty, records=gen_json(tables[ty])) flash(msg, 'success') return render_template('/applications/export.html', title=title, app=app) else: ckan.package_create(app=app, user=app.owner, url=app_url, tags=current_app.config['BRAND']) resources = create_ckan_datastores(ckan) ckan.datastore_upsert(name=ty, records=gen_json(tables[ty]), resource_id=resources[ty]['id']) flash(msg, 'success') return render_template('/applications/export.html', title=title, app=app) except Exception as inst: print inst if len(inst.args) == 3: type, msg, status_code = inst.args msg = ("Error: %s with status code: %s" % (type, status_code)) else: msg = ("Error: %s" % inst.args[0]) flash(msg, 'danger') return render_template('/applications/export.html', title=title, app=app)
def respond_ckan(ty): # First check if there is a package (dataset) in CKAN tables = {"task": model.Task, "task_run": model.TaskRun} msg_1 = lazy_gettext("Data exported to ") msg = msg_1 + "%s ..." % current_app.config['CKAN_URL'] ckan = Ckan(url=current_app.config['CKAN_URL'], api_key=current_user.ckan_api) app_url = url_for('.details', short_name=app.short_name, _external=True) try: package, e = ckan.package_exists(name=app.short_name) if e: raise e if package: # Update the package ckan.package_update(app=app, user=app.owner, url=app_url) if len(package['resources']) == 0: resources = create_ckan_datastores(ckan) ckan.datastore_upsert(name=ty, records=gen_json(tables[ty]), resource_id=resources[ty]['id']) else: ckan.datastore_delete(name=ty) ckan.datastore_create(name=ty) ckan.datastore_upsert(name=ty, records=gen_json(tables[ty])) else: ckan.package_create(app=app, user=app.owner, url=app_url, tags=current_app.config['BRAND']) resources = create_ckan_datastores(ckan) ckan.datastore_upsert(name=ty, records=gen_json(tables[ty]), resource_id=resources[ty]['id']) flash(msg, 'success') return respond() except requests.exceptions.ConnectionError: msg = "CKAN server seems to be down, try again layer or contact the CKAN admins" current_app.logger.error(msg) flash(msg, 'danger') except Exception as inst: if len(inst.args) == 3: type, msg, status_code = inst.args msg = ("Error: %s with status code: %s" % (type, status_code)) else: msg = ("Error: %s" % inst.args[0]) current_app.logger.error(msg) flash(msg, 'danger') finally: return respond()
def details(short_name): app = app_by_shortname(short_name) try: require.app.read(app) require.app.update(app) template = '/applications/actions.html' except HTTPException: if app.hidden: app = None template = '/applications/app.html' title = app_title(app, None) template_args = {"app": app, "title": title} if current_app.config.get('CKAN_URL'): template_args['ckan_name'] = current_app.config.get('CKAN_NAME') ckan = Ckan(url=current_app.config['CKAN_URL']) pkg = ckan.package_exists(name=short_name) if pkg: template_args['ckan_pkg_url'] = ( "%s/dataset/%s" % (current_app.config['CKAN_URL'], short_name)) template_args['ckan_pkg'] = pkg return render_template(template, **template_args)