def new(self, data=None, errors=None, error_summary=None): package_type = self._guess_package_type(True) context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj, 'save': 'save' in request.params} # Package needs to have a organization group in the call to # check_access and also to save it try: check_access('package_create', context) except NotAuthorized: abort(401, _('Unauthorized to create a package')) if context['save'] and not data: return self._save_new(context, package_type=package_type) data = data or clean_dict(dict_fns.unflatten(tuplize_dict(parse_params( request.params, ignore_keys=CACHE_PARAMETERS)))) c.resources_json = h.json.dumps(data.get('resources', [])) # convert tags if not supplied in data if data and not data.get('tag_string'): data['tag_string'] = ', '.join( h.dict_list_reduce(data.get('tags', {}), 'name')) errors = errors or {} error_summary = error_summary or {} # in the phased add dataset we need to know that # we have already completed stage 1 stage = ['active'] if data.get('state') == 'draft': stage = ['active', 'complete'] elif data.get('state') == 'draft-complete': stage = ['active', 'complete', 'complete'] # if we are creating from a group then this allows the group to be # set automatically data['group_id'] = request.params.get('group') or \ request.params.get('groups__0__id') vars = {'data': data, 'errors': errors, 'error_summary': error_summary, 'action': 'new', 'stage': stage} c.errors_json = h.json.dumps(errors) self._setup_template_variables(context, {}, package_type=package_type) # TODO: This check is to maintain backwards compatibility with the # old way of creating custom forms. This behaviour is now deprecated. if hasattr(self, 'package_form'): c.form = render(self.package_form, extra_vars=vars) else: c.form = render(self._package_form(package_type=package_type), extra_vars=vars) return render(self._new_template(package_type), extra_vars={'stage': stage})
def edit_relation(self, id, data=None, errors=None): try: c.link = str("/dataset/relationship/new_relationship/" + id) """context = { "model": model, "session": model.Session, "user": c.user or c.author, "for_view": True, "auth_user_obj": c.userobj, "use_cache": False, }""" c.pkg_dict = get_action("package_show")({ "model": model, "session": model.Session, "user": c.user or c.author, "for_view": True, "auth_user_obj": c.userobj, "use_cache": False, }, {"id": id}) # c.pkg = context["package"] except NotFound: abort(404, _("Dataset not found")) except NotAuthorized: abort(401, _("Unauthorized to read dataset %s") % id) return render("package/edit_data_relation.html", extra_vars={"package_id": id})
def resource_delete(self, id, resource_id): if 'cancel' in request.params: h.redirect_to(controller='package', action='resource_edit', resource_id=resource_id, id=id) context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj} try: check_access('package_delete', context, {'id': id}) except NotAuthorized: abort(401, _('Unauthorized to delete package %s') % '') try: if request.method == 'POST': #check against csrf attacks custom_base.csrf_check(self) get_action('resource_delete')(context, {'id': resource_id}) h.flash_notice(_('Resource has been deleted.')) h.redirect_to(controller='package', action='read', id=id) c.resource_dict = get_action('resource_show')( context, {'id': resource_id}) c.pkg_id = id except NotAuthorized: abort(401, _('Unauthorized to delete resource %s') % '') except NotFound: abort(404, _('Resource not found')) return render('package/confirm_delete_resource.html', {'dataset_type': self._get_package_type(id)})
def resource_read(self, id, resource_id): context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj} try: c.resource = get_action('resource_show')(context, {'id': resource_id}) c.package = get_action('package_show')(context, {'id': id}) # required for nav menu c.pkg = context['package'] c.pkg_dict = c.package except NotFound: abort(404, _('Resource not found')) except NotAuthorized: abort(401, _('Unauthorized to read resource %s') % id) # get package license info license_id = c.package.get('license_id') try: c.package['isopen'] = model.Package.\ get_license_register()[license_id].isopen() except KeyError: c.package['isopen'] = False # TODO: find a nicer way of doing this c.datastore_api = '%s/api/action' % config.get('ckan.site_url', '').rstrip('/') c.related_count = c.pkg.related_count c.resource['can_be_previewed'] = self._resource_preview( {'resource': c.resource, 'package': c.package}) return render('package/resource_read.html')
def new_parcel(self, id): new_parcel = True ctype, format = self._content_type_from_accept() response.headers['Content-Type'] = ctype context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj} data_dict = {'id': id, 'include_tracking': True} # check if package exists try: c.pkg_dict = get_action('package_show')(context, data_dict) c.pkg = context['package'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read package %s') % id) package_type = c.pkg_dict['type'] or 'dataset' self._setup_template_variables(context, {'id': id}, package_type=package_type) return render('package/edit_parcel_details.html', extra_vars={'dataset_type': package_type, 'new_parcel': new_parcel})
def read_resources(self, id): ctype, format = self._content_type_from_accept() response.headers["Content-Type"] = ctype context = { "model": model, "session": model.Session, "user": c.user or c.author, "for_view": True, "auth_user_obj": c.userobj, } data_dict = {"id": id, "include_tracking": True} # check if package exists try: c.pkg_dict = get_action("package_show")(context, data_dict) c.pkg = context["package"] except NotFound: abort(404, _("Dataset not found")) except NotAuthorized: abort(401, _("Unauthorized to read package %s") % id) package_type = c.pkg_dict["type"] or "dataset" self._setup_template_variables(context, {"id": id}, package_type=package_type) return render("package/resources.html", extra_vars={"dataset_type": package_type})
def resources(self, id): context = {'model': model, 'session': model.Session, 'user': c.user, 'for_view': True, 'auth_user_obj': c.userobj} data_dict = {'id': id, 'include_tracking': True} try: check_access('package_update', context, data_dict) except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(403, _('User %r not authorized to edit %s') % (c.user, id)) # check if package exists try: c.pkg_dict = get_action('package_show')(context, data_dict) c.pkg = context['package'] except (NotFound, NotAuthorized): abort(404, _('Dataset not found')) package_type = c.pkg_dict['type'] or 'dataset' self._setup_template_variables(context, {'id': id}, package_type=package_type) return render('package/resources.html', extra_vars={'dataset_type': package_type})
def resource_filters_create(self, name, resource_id): context = self._get_ctx() if t.request.method.lower() == 'post': filters = t.request.POST.getall('filters') l.get_action('resource_filters_create')(context, { 'resource_id': resource_id, 'filters': filters }) h.flash_success(_('Resource filters created successfully!')) redirect( t.url_for('resource_filters_edit', name=name, resource_id=resource_id)) pkg = l.get_action('package_show')(context, {'id': name}) resource = l.get_action('resource_show')(context, {'id': resource_id}) available_filters = l.get_action('resource_filters')( context, { 'resource_id': resource_id }) vars = { 'pkg_dict': pkg, 'res': resource, 'dataset_type': 'dataset', 'available_filters': available_filters } return render('package/resource_filters_create.html', extra_vars=vars)
def resource_delete(self, id, resource_id): if 'cancel' in request.params: h.redirect_to(controller='package', action='resource_edit', resource_id=resource_id, id=id) context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj} try: check_access('package_delete', context, {'id': id}) except NotAuthorized: abort(401, _('Unauthorized to delete package %s') % '') try: if request.method == 'POST': # check against csrf attacks custom_base.csrf_check(self) get_action('resource_delete')(context, {'id': resource_id}) h.flash_notice(_('Resource has been deleted.')) h.redirect_to(controller='package', action='read', id=id) c.resource_dict = get_action('resource_show')( context, {'id': resource_id}) c.pkg_id = id except NotAuthorized: abort(401, _('Unauthorized to delete resource %s') % '') except NotFound: abort(404, _('Resource not found')) return render('package/confirm_delete_resource.html', {'dataset_type': self._get_package_type(id)})
def callback(self): user = model.User.get('admin') context = { 'model': model, 'user': '******', 'session': model.Session, 'for_view': True } cid = request.params.get('comment_id') comment = request.params.get('comment') id = request.params.get('pkg_id') if id != "": data_dict = {} data_dict["id"] = id pkg = logic.get_action('package_show')(context, data_dict) callback_field = config.get('disqus.callback.field', "None") mail_sent = 0 if callback_field in pkg and pkg.get(callback_field) <> None: url = request.host_url + toolkit.url_for( controller='package', action='read', id=id) msg = u'Zum Datensatz mit der ID %s - "%s"\r\n wurde ein neuer Kommentar mit folgendem Inhalt abgegeben:\r\n\r\n"%s"\r\n\r\nLink zum Datensatz: %s\r\n\r\nHinweis: Sie erhalten diese Email, weil Ihre Email-Adresse beim Datensatz "%s" als Kontaktmöglichkeit angegeben wurde. Wenn Sie dies ändern möchten, kontaktieren Sie bitte Ihre Open-Data-Koordinierungsstelle. ' % ( id, pkg["title"], comment, url, pkg["title"]) mailer.mail_recipient('Datenverantwortliche/r', pkg.get(callback_field, ""), 'Neuer Kommentar zum Datensatz', msg) mail_sent = 1 data = {'comment_id': cid, 'pkg_id': id, 'mail_sent': mail_sent} return render('disqus_callback.html', data)
def finaldict(self, id, data=None, errors=None): if request.method == 'POST': print("!!!!!!!!!!!!!!!!!!1 POsted FROM EXTENSION!!!!!!!!!!!1") #print(request.params.get()) c.link = str("/dataset/dictionary/new_dict/" + id) return render("package/new_data_dict.html", extra_vars={'package_id': id})
def dataset_doi_admin_form(self, dataset_url, dataset): xml = build_xml(dataset) template = 'package/doi_admin.html' return render(template, extra_vars={ 'xml': xml, 'dataset_url': dataset_url })
def notify(self): prev_lang = i18n.get_lang() i18n.set_lang(config.get('ckan.locale_default', 'en')) comment_id = request.params.get('comment_id') comment = request.params.get('comment') pkg_id = request.params.get('pkg_id') recipient_name_field = config.get('disqus.notify.name_field') recipient_email_field = config.get('disqus.notify.email_field') mail_sent = False if pkg_id is not None: pkg = logic.get_action('package_show')({ 'ignore_auth': True }, { 'id': pkg_id }) if recipient_email_field in pkg and pkg.get( recipient_email_field, '') != '': url_path = toolkit.url_for(controller='package', action='read', id=pkg_id) url = '%s%s' % (request.host_url, url_path) msg_fields = { 'url': url, 'title': pkg["title"], 'comment': comment } title = _(u'New comment for dataset "%(title)s"') % msg_fields msg = _( u'The dataset "%(title)s" has received a new comment:\n\n%(comment)s\n\n<%(url)s>' ) % msg_fields recipient_name = pkg.get(recipient_name_field, _(u'Dataset maintainer')) recipient_email = pkg.get(recipient_email_field) try: mailer.mail_recipient(recipient_name, recipient_email, title, msg) mail_sent = True except mailer.MailerException as e: log.error('Could not send disqus notification mail: %s' % e) data = { 'comment_id': comment_id, 'pkg_id': pkg_id, 'mail_sent': mail_sent } result = render('disqus_callback.html', data) i18n.set_lang(prev_lang) return result
def read_parcel_details(self, id, parcel_id): parcel_geom = cadasta_model.get_parcel_geom(id) relationship_list = cadasta_model.list_relationships(id) parcel_details = cadasta_model.get_parcel_details(parcel_id) if parcel_details: reformatted_date = parse(parcel_details['features'][0]['properties']['time_created']) reformatted_date = reformatted_date.strftime("%m/%d/%y") parcel_details['features'][0]['properties']['time_created'] = reformatted_date reformatted_time_updated = parse(parcel_details['features'][0]['properties']['time_updated']) reformatted_time_updated = reformatted_time_updated.strftime("%m/%d/%y") parcel_details['features'][0]['properties']['time_updated'] = reformatted_time_updated for relationship in parcel_details['features'][0]['properties']['relationships']: reformatted_date = parse(relationship['time_created']) reformatted_date = reformatted_date.strftime("%m/%d/%y") relationship['time_created'] = reformatted_date reformatted_date = parse(relationship['time_updated']) reformatted_date = reformatted_date.strftime("%m/%d/%y") relationship['time_updated'] = reformatted_date ctype, format = self._content_type_from_accept() response.headers['Content-Type'] = ctype context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj} data_dict = {'id': id, 'include_tracking': True} # check if package exists try: c.pkg_dict = get_action('package_show')(context, data_dict) c.pkg = context['package'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read package %s') % id) package_type = c.pkg_dict['type'] or 'dataset' self._setup_template_variables(context, {'id': id, 'parcel_id' : parcel_id}, package_type=package_type) return render('package/parcel_details.html', extra_vars={'dataset_type': package_type, 'parcel_geom': parcel_geom, 'relationship_list':relationship_list, 'parcel_details': parcel_details})
def read_parcels(self, id): # todo this is uniocde, what format does this need to be in to push it back to db # geom = request.params.get('parcel_geom') #get filter params filterArg = request.params.get('filter') #get sort params sortArg = request.params.get('sort') #if filters exist, ask API to filter parcels and respond parcel_list = cadasta_model.list_parcels(id, filter=filterArg, sort=sortArg) if parcel_list is not None and parcel_list.get("features", None) is not None: for parcel in parcel_list['features']: reformatted_date = parse(parcel['properties']['time_created']) reformatted_date = reformatted_date.strftime("%m/%d/%y") parcel['properties']['time_created'] = reformatted_date ctype, format = self._content_type_from_accept() response.headers['Content-Type'] = ctype context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj} data_dict = {'id': id, 'include_tracking': True} # check if package exists try: c.pkg_dict = get_action('package_show')(context, data_dict) c.pkg = context['package'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read package %s') % id) package_type = c.pkg_dict['type'] or 'dataset' self._setup_template_variables(context, {'id': id}, package_type=package_type) return render('package/parcels.html', extra_vars={'dataset_type': package_type, 'parcel_list': parcel_list, 'filter': request.params.get('filter'), 'sort': request.params.get('sort')})
def resource_embedded_dataviewer(self, id, resource_id, width=500, height=500): """ Embedded page for a read-only resource dataview. Allows for width and height to be specified as part of the querystring (as well as accepting them via routes). """ context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj} try: c.resource = get_action('resource_show')(context, {'id': resource_id}) if config.get('ckan.upload_file_url'): url = c.resource['url'] if config.get('ckan.upload_file_url') in url: url = url.split(config.get('ckan.upload_file_url')) c.resource['url'] = url[1] c.package = get_action('package_show')(context, {'id': id}) c.resource_json = h.json.dumps(c.resource) # double check that the resource belongs to the specified package if not c.resource['id'] in [r['id'] for r in c.package['resources']]: raise NotFound dataset_type = c.package['type'] or 'dataset' except NotFound: abort(404, _('Resource not found')) except NotAuthorized: abort(401, _('Unauthorized to read resource %s') % id) # Construct the recline state state_version = int(request.params.get('state_version', '1')) recline_state = self._parse_recline_state(request.params) if recline_state is None: abort(400, ('"state" parameter must be a valid recline ' 'state (version %d)' % state_version)) c.recline_state = h.json.dumps(recline_state) c.width = max(int(request.params.get('width', width)), 100) c.height = max(int(request.params.get('height', height)), 100) c.embedded = True return render('package/resource_embedded_dataviewer.html', extra_vars={'dataset_type': dataset_type})
def resource_filters_edit(self, name, resource_id): context = self._get_ctx() pkg = l.get_action('package_show')(context, {'id': name}) resource = l.get_action('resource_show')(context, {'id': resource_id}) active_filters = l.get_action('active_resource_filters')( context, { 'resource_id': resource_id }) vars = { 'pkg_dict': pkg, 'res': resource, 'dataset_type': 'dataset', 'active_filters': active_filters } return render('package/resource_filters_edit.html', extra_vars=vars)
def resource_datapreview(self, id, resource_id): ''' Embedded page for a resource data-preview. Depending on the type, different previews are loaded. This could be an img tag where the image is loaded directly or an iframe that embeds a webpage, or a recline preview. ''' context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj } try: c.resource = get_action('resource_show')(context, {'id': resource_id}) # removes the host to make it relative if config.get('ckan.upload_file_url'): url = c.resource['url'] if config.get('ckan.upload_file_url') in url: url = url.split(config.get('ckan.upload_file_url')) c.resource['url'] = url[1] c.package = get_action('package_show')(context, {'id': id}) data_dict = {'resource': c.resource, 'package': c.package} preview_plugin = datapreview.get_preview_plugin(data_dict) if preview_plugin is None: abort(409, _('No preview has been defined.')) preview_plugin.setup_template_variables(context, data_dict) c.resource_json = json.dumps(c.resource) dataset_type = c.package['type'] or 'dataset' except NotFound: abort(404, _('Resource not found')) except NotAuthorized: abort(401, _('Unauthorized to read resource %s') % id) else: return render(preview_plugin.preview_template(context, data_dict), extra_vars={'dataset_type': dataset_type})
def resource_mapping_delete(self, id, resource_id): """Delete mapping table.""" if 'cancel' in request.params: h.redirect_to( controller='ckanext.column_mapper.controller:CMController', action='resource_mapping', resource_id=resource_id, id=id) context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj } try: check_access('package_delete', context, {'id': id}) except NotAuthorized: abort(403, _('Unauthorized to delete package %s') % '') try: if request.method == 'POST': mapping_id = resource_id + '_mapping' get_action('datastore_delete')(context, { 'resource_id': mapping_id, 'force': True }) h.flash_notice(_('Mapping has been deleted.')) h.redirect_to( controller= 'ckanext.datapusher.plugin:ResourceDataController', action='resource_data', id=id, resource_id=resource_id) c.resource_dict = get_action('resource_show')(context, { 'id': resource_id }) c.pkg_id = id except NotAuthorized: abort(403, _('Unauthorized to delete column mapping %s') % '') except NotFound: abort(404, _('Column Mapping not found for resource')) return render('package/confirm_delete_resource_mapping.html', {'dataset_type': self._get_package_type(id)})
def read(self, id): all_parcels = cadasta_model.get_all_parcels(id) activity_list = cadasta_model.get_cadasta_activity(id) if activity_list: for activity in activity_list["features"]: reformatted_date = parse(activity["properties"]["time_created"]) reformatted_date = reformatted_date.strftime("%m/%d/%y") activity["properties"]["time_created"] = reformatted_date ctype, format = self._content_type_from_accept() response.headers["Content-Type"] = ctype context = { "model": model, "session": model.Session, "user": c.user or c.author, "for_view": True, "auth_user_obj": c.userobj, } data_dict = {"id": id, "include_tracking": True} # check if package exists try: c.pkg_dict = get_action("package_show")(context, data_dict) c.pkg = context["package"] except NotFound: abort(404, _("Dataset not found")) except NotAuthorized: abort(401, _("Unauthorized to read package %s") % id) package_type = c.pkg_dict["type"] or "dataset" self._setup_template_variables(context, {"id": id}, package_type=package_type) return render( "package/read.html", extra_vars={"dataset_type": package_type, "all_parcels": all_parcels, "activity_list": activity_list}, )
def get_relationship_history(self, id, parcel_id): #get relationship_type param relationship_type = request.params.get('relationship_type') #get status param active = request.params.get('active') relationship_list = cadasta_model.get_relationship_history(parcel_id, relationship_type, active) if relationship_list and relationship_list['features'] is not None: for relationship in relationship_list['features']: reformatted_date = parse(relationship['properties']['time_created']) reformatted_date = reformatted_date.strftime("%m/%d/%y") relationship['properties']['time_created'] = reformatted_date ctype, format = self._content_type_from_accept() response.headers['Content-Type'] = ctype context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj} data_dict = {'id': id, 'include_tracking': True} # check if package exists try: c.pkg_dict = get_action('package_show')(context, data_dict) c.pkg = context['package'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read package %s') % id) package_type = c.pkg_dict['type'] or 'dataset' self._setup_template_variables(context, {'id': id, 'parcel_id': parcel_id}, package_type=package_type) return render('package/relationship_history.html', extra_vars={'dataset_type': package_type, 'relationship_list':relationship_list, 'relationship_type': relationship_type, 'active': active})
def resource_views(self, id, resource_id): package_type = self._get_package_type(id.split('@')[0]) context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj} data_dict = {'id': id} try: check_access('package_update', context, data_dict) except NotAuthorized: abort(401, _('User %r not authorized to edit %s') % (c.user, id)) # check if package exists try: c.pkg_dict = get_action('package_show')(context, data_dict) c.pkg = context['package'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id) try: c.resource = get_action('resource_show')(context, {'id': resource_id}) if config.get('ckan.upload_file_url'): url = c.resource['url'] if config.get('ckan.upload_file_url') in url: url = url.split(config.get('ckan.upload_file_url')) c.resource['url'] = url[1] c.views = get_action('resource_view_list')(context, {'id': resource_id}) except NotFound: abort(404, _('Resource not found')) except NotAuthorized: abort(401, _('Unauthorized to read resource %s') % id) self._setup_template_variables(context, {'id': id}, package_type=package_type) return render('package/resource_views.html')
def resource_read(self, id, resource_id): context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj } try: c.resource = get_action('resource_show')(context, { 'id': resource_id }) c.package = get_action('package_show')(context, {'id': id}) # required for nav menu c.pkg = context['package'] c.pkg_dict = c.package except NotFound: abort(404, _('Resource not found')) except NotAuthorized: abort(401, _('Unauthorized to read resource %s') % id) # get package license info license_id = c.package.get('license_id') try: c.package['isopen'] = model.Package.\ get_license_register()[license_id].isopen() except KeyError: c.package['isopen'] = False # TODO: find a nicer way of doing this c.datastore_api = '%s/api/action' % config.get('ckan.site_url', '').rstrip('/') c.related_count = c.pkg.related_count c.resource['can_be_previewed'] = self._resource_preview({ 'resource': c.resource, 'package': c.package }) return render('package/resource_read.html')
def resource_embedded_dataviewer(self, id, resource_id, width=500, height=500): """ Embedded page for a read-only resource dataview. Allows for width and height to be specified as part of the querystring (as well as accepting them via routes). """ context = {'model': model, 'session': model.Session, 'user': c.user, 'auth_user_obj': c.userobj} try: c.resource = get_action('resource_show')(context, {'id': resource_id}) c.package = get_action('package_show')(context, {'id': id}) c.resource_json = h.json.dumps(c.resource) # double check that the resource belongs to the specified package if not c.resource['id'] in [r['id'] for r in c.package['resources']]: raise NotFound dataset_type = c.package['type'] or 'dataset' except (NotFound, NotAuthorized): abort(404, _('Resource not found')) # Construct the recline state state_version = int(request.params.get('state_version', '1')) recline_state = self._parse_recline_state(request.params) if recline_state is None: abort(400, ('"state" parameter must be a valid recline ' 'state (version %d)' % state_version)) c.recline_state = h.json.dumps(recline_state) c.width = max(int(request.params.get('width', width)), 100) c.height = max(int(request.params.get('height', height)), 100) c.embedded = True return render('package/resource_embedded_dataviewer.html', extra_vars={'dataset_type': dataset_type})
def edit_dictionary(self, id, data=None, errors=None): context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj, 'use_cache': False} resource_ids = None try: meta_dict = {'resource_id': '_table_metadata'} tables = get_action('datastore_search')(context,meta_dict) for t in tables['records']: print(t['name']) if t['name'] == "data_dict": resource_ids = t['alias_of'] except: resource_ids == None if resource_ids == None: create = {'resource':{'package_id':id},'aliases':'data_dict','fields':[{'id':'package_id', 'type':'text'},{'id':'id','type':'int4'},{'id':'title','type':'text'},{'id':'field_name','type':'text'},{'id':'format','type':'text'},{'id':'description','type':'text'}],'primary_key':['id']} get_action('datastore_create')(context,create) print("CREATE TABLE !!!!!!!!!!!!!!!!!!!!!!!IDID") meta_dict = {'resource_id': '_table_metadata'} tables = get_action('datastore_search')(context,meta_dict) for t in tables['records']: print(t['name']) if t['name'] == "data_dict": resource_ids = t['alias_of'] data_dict_dict = {'resource_id': resource_ids,'filters': {'package_id':id},'sort':['id']} try: print("EXTENSION LOCALLLLLLLLLLLLLLLLLLLLLLLL") pkg_data_dictionary = get_action('datastore_search')(context, data_dict_dict) #print(pkg_data_dictionary['records']) c.pkg_data_dictionary = pkg_data_dictionary['records'] c.link = str("/dataset/dictionary/new_dict/" + id) c.pkg_dict = get_action('package_show')(context, {'id':id}) c.pkg = context['package'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id) return render("package/edit_data_dict.html",extra_vars={'package_id':id})
def callback(self): user = model.User.get('admin') context = { 'model':model,'user': '******','session':model.Session, 'for_view': True } cid = request.params.get('comment_id') comment = request.params.get('comment') id = request.params.get('pkg_id') if id != "": data_dict = {} data_dict["id"] = id pkg = logic.get_action('package_show')(context, data_dict) callback_field = config.get('disqus.callback.field', "None") mail_sent = 0 if callback_field in pkg and pkg.get(callback_field) <> None: url = request.host_url + toolkit.url_for(controller='package', action='read', id=id) msg = u'Zum Datensatz mit der ID %s - "%s"\r\n wurde ein neuer Kommentar mit folgendem Inhalt abgegeben:\r\n\r\n"%s"\r\n\r\nLink zum Datensatz: %s\r\n\r\nHinweis: Sie erhalten diese Email, weil Ihre Email-Adresse beim Datensatz "%s" als Kontaktmöglichkeit angegeben wurde. Wenn Sie dies ändern möchten, kontaktieren Sie bitte Ihre Open-Data-Koordinierungsstelle. ' % (id, pkg["title"], comment, url, pkg["title"]) mailer.mail_recipient('Datenverantwortliche/r', pkg.get(callback_field, ""), 'Neuer Kommentar zum Datensatz', msg) mail_sent = 1 data = {'comment_id' : cid, 'pkg_id': id, 'mail_sent': mail_sent} return render('disqus_callback.html', data)
def delete(self, id): if 'cancel' in request.params: h.redirect_to(controller='package', action='edit', id=id) context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj} try: if request.method == 'POST': #check against csrf attacks custom_base.csrf_check(self) get_action('package_delete')(context, {'id': id}) h.flash_notice(_('Dataset has been deleted.')) h.redirect_to(controller='package', action='search') c.pkg_dict = get_action('package_show')(context, {'id': id}) dataset_type = c.pkg_dict['type'] or 'dataset' except NotAuthorized: abort(401, _('Unauthorized to delete package %s') % '') except NotFound: abort(404, _('Dataset not found')) return render('package/confirm_delete.html', extra_vars={'dataset_type': dataset_type})
def delete(self, id): if 'cancel' in request.params: h.redirect_to(controller='package', action='edit', id=id) context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj} try: if request.method == 'POST': # check against csrf attacks custom_base.csrf_check(self) get_action('package_delete')(context, {'id': id}) h.flash_notice(_('Dataset has been deleted.')) h.redirect_to(controller='package', action='search') c.pkg_dict = get_action('package_show')(context, {'id': id}) dataset_type = c.pkg_dict['type'] or 'dataset' except NotAuthorized: abort(401, _('Unauthorized to delete package %s') % '') except NotFound: abort(404, _('Dataset not found')) return render('package/confirm_delete.html', extra_vars={'dataset_type': dataset_type})
def doi_form(self, id): # Mostly copied from PackageController:read context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj } data_dict = {'id': id} dataset_url = toolkit.url_for(controller='package', action='read', id=id, qualified=True) # check if package exists try: c.pkg_dict = get_action('package_show')(context, data_dict) c.pkg = context['package'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read package %s') % id) self.fail_if_private(c.pkg_dict, dataset_url) # used by disqus plugin c.current_package_id = c.pkg.id c.related_count = c.pkg.related_count package_type = c.pkg_dict['type'] or 'dataset' self._setup_template_variables(context, {'id': id}, package_type=package_type) ########################## ADD DOI STUFF ########################### template = 'package/doi.html' fields = dict( (field.lower().replace(' ', '_').translate(None, '()'), field) for field in doi_request_fields) q = Session.query(DoiRequest).filter_by(package_id=c.pkg_dict['id'], user_id=c.userobj.id) ((request_exists, ), ) = Session.query(q.exists()) if request_exists: h.flash_notice("You've already requested a DOI for this dataset. " "You'll be emailed if it is approved.") return toolkit.redirect_to(dataset_url) try: return render( template, extra_vars={ 'dataset_type': package_type, # TODO 'data': {}, 'errors': None, 'fields': fields }) except ckan.lib.render.TemplateNotFound: msg = _("Viewing {package_type} datasets in {format} format is " "not supported (template file {file} not found).".format( package_type=package_type, format=format, file=template)) abort(404, msg)
c.search_facets_limits[facet] = limit self._setup_template_variables(context, {}, package_type=package_type) # return render(self._search_template(package_type), # extra_vars={'dataset_type': package_type}) # variable='' # if request.method== 'POST': # print("!!!!!!!!!!!!!!!!!!1 POsted FROM EXTENSION!!!!!!!!!!!1") # variable = request.params.get('sel') # c.link = str("/dataset/dictionary/new_dict/"+"prueba") # return render("package/new_data_dict.html",extra_vars={'package_id':variable}) return render("package/new_data_dict.html") ################################################################ #Agregando para pruebas ####################################################################### def new_dataset(self): if request.method == 'POST': save_action = request.params.get('save') sel = "" sel = request.params.get('selecting_schemas') if save_action == 'go-dataset-new': package_type = pkggg._get_package_type(sel)
c.page = h.Page(collection=[]) c.search_facets_limits = {} for facet in c.search_facets.keys(): try: limit = int(request.params.get('_%s_limit' % facet, int(config.get('search.facets.default', 10)))) except ValueError: abort(400, _('Parameter "{parameter_name}" is not ' 'an integer').format( parameter_name='_%s_limit' % facet)) c.search_facets_limits[facet] = limit self._setup_template_variables(context, {}, package_type=package_type) return render('scheming/'+package_type+'/search.html', extra_vars={'dataset_type': package_type}) def resources(self, id): context = {'model': model, 'session': model.Session, 'user': c.user, 'for_view': True, 'auth_user_obj': c.userobj} data_dict = {'id': id, 'include_tracking': True} try: check_access('package_update', context, data_dict) except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(403, _('User %r not authorized to edit %s') % (c.user, id))
def search(self): from ckan.lib.search import SearchError, SearchQueryError package_type = self._guess_package_type() try: context = { 'model': model, 'user': c.user, 'auth_user_obj': c.userobj } check_access('site_read', context) except NotAuthorized: abort(403, _('Not authorized to see this page')) # unicode format (decoded from utf8) q = c.q = request.params.get('q', u'') org = request.params.get('organization', None) c.query_error = False page = h.get_page_number(request.params) try: limit = int(config.get('ckan.datasets_per_page', 20)) except: limit = 20 # most search operations should reset the page counter: params_nopage = [(k, v) for k, v in request.params.items() if k != 'page'] def drill_down_url(alternative_url=None, **by): return h.add_url_param(alternative_url=alternative_url, controller='package', action='search', new_params=by) c.drill_down_url = drill_down_url def remove_field(key, value=None, replace=None): return h.remove_url_param(key, value=value, replace=replace, controller='package', action='search', alternative_url=package_type) c.remove_field = remove_field sort_by = request.params.get('sort', None) params_nosort = [(k, v) for k, v in params_nopage if k != 'sort'] def _sort_by(fields): """ Sort by the given list of fields. Each entry in the list is a 2-tuple: (fieldname, sort_order) eg - [('metadata_modified', 'desc'), ('name', 'asc')] If fields is empty, then the default ordering is used. """ params = params_nosort[:] if fields: sort_string = ', '.join('%s %s' % f for f in fields) params.append(('sort', sort_string)) return search_url(params, package_type) c.sort_by = _sort_by if not sort_by: c.sort_by_fields = [] else: c.sort_by_fields = [ field.split()[0] for field in sort_by.split(',') ] def pager_url(q=None, page=None): params = list(params_nopage) params.append(('page', page)) return search_url(params, package_type) c.search_url_params = urlencode(_encode_params(params_nopage)) try: c.fields = [] # c.fields_grouped will contain a dict of params containing # a list of values eg {'tags':['tag1', 'tag2']} c.fields_grouped = {} search_extras = {} fq = '' for (param, value) in request.params.items(): if param not in ['q', 'page', 'sort'] \ and len(value) and not param.startswith('_'): if not param.startswith('ext_'): c.fields.append((param, value)) fq += ' %s:"%s"' % (param, value) if param not in c.fields_grouped: c.fields_grouped[param] = [value] else: c.fields_grouped[param].append(value) else: search_extras[param] = value context = { 'model': model, 'session': model.Session, 'user': c.user, 'for_view': True, 'auth_user_obj': c.userobj } # Unless changed via config options, don't show other dataset # types any search page. Potential alternatives are do show them # on the default search page (dataset) or on one other search page search_all_type = config.get('ckan.search.show_all_types', 'dataset') search_all = False map_results = None try: # If the "type" is set to True or False, convert to bool # and we know that no type was specified, so use traditional # behaviour of applying this only to dataset type search_all = asbool(search_all_type) search_all_type = 'dataset' # Otherwise we treat as a string representing a type except ValueError: search_all = True if not package_type: package_type = 'dataset' if not search_all or package_type != search_all_type: # Only show datasets of this particular type fq += ' +dataset_type:{type}'.format(type=package_type) facets = OrderedDict() default_facet_titles = { 'organization': _('Organizations'), 'groups': _('Groups'), 'tags': _('Tags'), 'res_format': _('Formats'), 'license_id': _('Licenses'), } for facet in h.facets(): if facet in default_facet_titles: facets[facet] = default_facet_titles[facet] else: facets[facet] = facet # Facet titles for plugin in p.PluginImplementations(p.IFacets): facets = plugin.dataset_facets(facets, package_type) c.facet_titles = facets data_dict = { 'q': q, 'fq': fq.strip(), 'facet.field': facets.keys(), 'rows': limit, 'start': (page - 1) * limit, 'sort': sort_by, 'extras': search_extras, 'include_private': asbool(config.get('ckan.search.default_include_private', True)), } query = get_action('package_search')(context, data_dict) # loop the search query and get all the results # this workaround the 1000 rows solr hard limit HARD_LIMIT = 1000 conn = get_connection_redis() pager = 0 # crank up the pager limit high as using points cluster for better performance PAGER_LIMIT = 10000 data_dict_full_result = { 'q': q, 'fq': fq.strip(), 'facet.field': facets.keys(), 'rows': HARD_LIMIT, 'start': 0, 'sort': sort_by, 'extras': search_extras, 'include_private': asbool(config.get('ckan.search.default_include_private', True)), } if not org: # if no q, it is an init load or direct visit on / dataset log.info('### Not org ###') if not q: log.info('### Not q ###') if not conn.exists('redis_full_results'): log.info('### generating full results ###') # get full results and add to redis when there is not full results in redis full_results = self.get_full_results( context, data_dict_full_result, pager, PAGER_LIMIT, q, fq, facets, HARD_LIMIT, sort_by, search_extras) map_results = self.get_map_result(full_results) # adding to redis log.info('adding full results to redis') conn.set('redis_full_results', json.dumps(map_results)) # log.info(c.full_results) else: log.info('### using cached full results ###') map_results = json.loads( conn.get('redis_full_results')) # log.info(c.full_results) else: log.info('### With q ###') full_results = self.get_full_results( context, data_dict_full_result, pager, PAGER_LIMIT, q, fq, facets, HARD_LIMIT, sort_by, search_extras) map_results = self.get_map_result(full_results) else: log.info('### With org ###') if not q: log.info('### Not q ###') if not conn.exists('redis_full_results_%s' % org): log.info('### generating %s results ###' % org) # get full results and add to redis when there is not full results in redis full_results = self.get_full_results( context, data_dict_full_result, pager, PAGER_LIMIT, q, fq, facets, HARD_LIMIT, sort_by, search_extras) map_results = self.get_map_result(full_results) # adding to redis log.info('adding %s results to redis' % org) conn.set('redis_full_results_%s' % org, json.dumps(map_results)) # log.info(c.full_results) else: log.info('### using cached %s results ###' % org) map_results = json.loads( conn.get('redis_full_results_%s' % org)) # log.info(c.full_results) else: log.info('### With q ###') full_results = self.get_full_results( context, data_dict_full_result, pager, PAGER_LIMIT, q, fq, facets, HARD_LIMIT, sort_by, search_extras) map_results = self.get_map_result(full_results) # log.info(c.full_results) c.sort_by_selected = query['sort'] c.page = h.Page(collection=query['results'], page=page, url=pager_url, item_count=query['count'], items_per_page=limit) c.search_facets = query['search_facets'] c.page.items = query['results'] except SearchQueryError as se: # User's search parameters are invalid, in such a way that is not # achievable with the web interface, so return a proper error to # discourage spiders which are the main cause of this. log.info('Dataset search query rejected: %r', se.args) abort( 400, _('Invalid search query: {error_message}').format( error_message=str(se))) except SearchError as se: # May be bad input from the user, but may also be more serious like # bad code causing a SOLR syntax error, or a problem connecting to # SOLR log.error('Dataset search error: %r', se.args) c.query_error = True c.search_facets = {} c.page = h.Page(collection=[]) except NotAuthorized: abort(403, _('Not authorized to see this page')) c.search_facets_limits = {} for facet in c.search_facets.keys(): try: limit = int( request.params.get( '_%s_limit' % facet, int(config.get('search.facets.default', 10)))) except ValueError: abort( 400, _('Parameter "{parameter_name}" is not ' 'an integer').format(parameter_name='_%s_limit' % facet)) c.search_facets_limits[facet] = limit self._setup_template_variables(context, {}, package_type=package_type) return render(self._search_template(package_type), extra_vars={ 'dataset_type': package_type, 'map_results': map_results })
def new(self, data=None, errors=None, error_summary=None): package_type = self._guess_package_type(True) context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj, 'save': 'save' in request.params } # Package needs to have a organization group in the call to # check_access and also to save it try: check_access('package_create', context) except NotAuthorized: abort(401, _('Unauthorized to create a package')) if context['save'] and not data: return self._save_new(context, package_type=package_type) data = data or clean_dict( dict_fns.unflatten( tuplize_dict( parse_params(request.params, ignore_keys=CACHE_PARAMETERS)))) c.resources_json = h.json.dumps(data.get('resources', [])) # convert tags if not supplied in data if data and not data.get('tag_string'): data['tag_string'] = ', '.join( h.dict_list_reduce(data.get('tags', {}), 'name')) errors = errors or {} error_summary = error_summary or {} # in the phased add dataset we need to know that # we have already completed stage 1 stage = ['active'] if data.get('state') == 'draft': stage = ['active', 'complete'] elif data.get('state') == 'draft-complete': stage = ['active', 'complete', 'complete'] # if we are creating from a group then this allows the group to be # set automatically data['group_id'] = request.params.get('group') or \ request.params.get('groups__0__id') vars = { 'data': data, 'errors': errors, 'error_summary': error_summary, 'action': 'new', 'stage': stage } c.errors_json = h.json.dumps(errors) self._setup_template_variables(context, {}, package_type=package_type) # TODO: This check is to maintain backwards compatibility with the # old way of creating custom forms. This behaviour is now deprecated. if hasattr(self, 'package_form'): c.form = render(self.package_form, extra_vars=vars) else: c.form = render(self._package_form(package_type=package_type), extra_vars=vars) return render(self._new_template(package_type), extra_vars={'stage': stage})
feedback_form = FeedbackController.get_form_items() feedback_form += [ { 'name': 'source_type', 'control': 'hidden' }, { 'name': 'source_id', 'control': 'hidden' }, ] try: return render(template, extra_vars={ 'dataset_type': package_type, 'feedback_form_items': feedback_form }) except ckan.lib.render.TemplateNotFound: msg = _("Viewing {package_type} datasets in {format} format is " "not supported (template file {file} not found).".format( package_type=package_type, format=format, file=template)) abort(404, msg) assert False, "We should never get here" def _resource_tag_string_to_list(self, tag_string): ''' This is used to change tags from a sting to a list of dicts ''' out = []
def dictionary(self, id): context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj, 'use_cache': False} data_dict = {'id': id} try: print("here!!!!!!!!1") #tem = get_action('package_show')(context, data_dict) #print(tem) c.pkg_dict = get_action('package_show')(context, data_dict) dataset_type = c.pkg_dict['type'] or 'dataset' except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id) #if request.method == 'POST': #new_group = request.POST.get('group_added') #if new_group: #data_dict = {"id": new_group, #"object": id, #"object_type": 'package', #"capacity": 'public'} #try: #get_action('member_create')(context, data_dict) #except NotFound: #abort(404, _('Group not found')) #removed_group = None #for param in request.POST: #if param.startswith('group_remove'): #removed_group = param.split('.')[-1] #break #if removed_group: #data_dict = {"id": removed_group, #"object": id, #"object_type": 'package'} #try: #get_action('member_delete')(context, data_dict) #except NotFound: #abort(404, _('Group not found')) #redirect(h.url_for(controller='package', #action='groups', id=id)) #context['is_member'] = True #users_groups = get_action('group_list_authz')(context, data_dict) #pkg_group_ids = set(group['id'] for group #in c.pkg_dict.get('groups', [])) #user_group_ids = set(group['id'] for group #in users_groups) #c.group_dropdown = [[group['id'], group['display_name']] #for group in users_groups if #group['id'] not in pkg_group_ids] #for group in c.pkg_dict.get('groups', []): #group['user_member'] = (group['id'] in user_group_ids) context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj, 'use_cache': False} resource_ids = None try: meta_dict = {'resource_id': '_table_metadata'} tables = get_action('datastore_search')(context,meta_dict) for t in tables['records']: print(t['name']) if t['name'] == "data_dict": resource_ids = t['alias_of'] except: resource_ids = None if resource_ids == None: create = {'resource':{'package_id':id},'aliases':'data_dict','fields':[{'id':'package_id','type':'text'},{'id':'id','type':'int4'},{'id':'title','type':'text'},{'id':'field_name','type':'text'},{'id':'format','type':'text'},{'id':'description','type':'text'}],'primary_key':['id']} get_action('datastore_create')(context,create) print("CREATE TABLE !!!!!!!!!!!!!!!!!!!!!!!") meta_dict = {'resource_id': '_table_metadata'} tables = get_action('datastore_search')(context,meta_dict) for t in tables['records']: print(t['name']) if t['name'] == "data_dict": resource_ids = t['alias_of'] data_dict_dict = {'resource_id': resource_ids,'filters': {'package_id':id},'sort':['id']} try: pkg_data_dictionary = get_action('datastore_search')(context, data_dict_dict) print(pkg_data_dictionary['records']) c.pkg_data_dictionary = pkg_data_dictionary['records'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id) return render('package/dictionary_display.html',{'dataset_type': dataset_type})
def resource_read(self, id, resource_id): # custom_base.g_analitics() context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj, 'for_view': True} try: c.package = get_action('package_show')(context, {'id': id}) except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id) c.upload_file_url = config.get('ckan.upload_file_url') c.upload_file_url_sec = config.get('ckan.upload_file_url_sec') for resource in c.package.get('resources', []): if resource['id'] == resource_id: url = resource['url'] # check if the resource is local and can be previewed if 'dataset' in url: resource['is_local_resource'] = True else: resource['is_local_resource'] = False # removes the host to make it relative if config.get('ckan.upload_file_url'): if config.get('ckan.upload_file_url') in url: url = url.split(config.get('ckan.upload_file_url')) resource['url'] = url[1] if config.get('ckan.upload_file_url_sec') in url: url = url.split(config.get('ckan.upload_file_url_sec')) resource['url'] = url[1] # resource['url'] = url[1] c.resource = resource break if not c.resource: abort(404, _('Resource not found')) # required for nav menu c.pkg = context['package'] c.pkg_dict = c.package dataset_type = c.pkg.type or 'dataset' # get package license info license_id = c.package.get('license_id') try: c.package['isopen'] = model.Package. \ get_license_register()[license_id].isopen() except KeyError: c.package['isopen'] = False # TODO: find a nicer way of doing this c.datastore_api = '%s/api/action' % \ config.get('ckan.site_url', '').rstrip('/') # deprecated # c.related_count = c.pkg.related_count c.resource['can_be_previewed'] = self._resource_preview( {'resource': c.resource, 'package': c.package}) resource_views = get_action('resource_view_list')( context, {'id': resource_id}) c.resource['has_views'] = len(resource_views) > 0 current_resource_view = None view_id = request.GET.get('view_id') if c.resource['can_be_previewed'] and not view_id: current_resource_view = None elif c.resource['has_views']: if view_id: current_resource_view = [rv for rv in resource_views if rv['id'] == view_id] if len(current_resource_view) == 1: current_resource_view = current_resource_view[0] else: abort(404, _('Resource view not found')) else: current_resource_view = resource_views[0] vars = {'resource_views': resource_views, 'current_resource_view': current_resource_view, 'dataset_type': dataset_type} analytics_helpers.update_analytics_code_by_organization(c.pkg_dict['organization']['id']) template = self._resource_template(dataset_type) return render(template, extra_vars=vars)
c.page = h.Page(collection=[]) c.search_facets_limits = {} for facet in c.search_facets.keys(): try: limit = int(request.params.get('_%s_limit' % facet, int(config.get('search.facets.default', 10)))) except ValueError: abort(400, _('Parameter "{parameter_name}" is not ' 'an integer').format( parameter_name='_%s_limit' % facet)) c.search_facets_limits[facet] = limit self._setup_template_variables(context, {}, package_type=package_type) return render(self._search_template(package_type), extra_vars={'dataset_type': package_type}) def read(self, id): # custom_base.g_analitics() context = {'model': model, 'session': model.Session, 'user': c.user, 'for_view': True, 'auth_user_obj': c.userobj} data_dict = {'id': id, 'include_tracking': True} # interpret @<revision_id> or @<date> suffix split = id.split('@') if len(split) == 2: data_dict['id'], revision_ref = split if model.is_id(revision_ref): context['revision_id'] = revision_ref else:
def dictionary(self, id): context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj, 'use_cache': False } data_dict = {'id': id} try: print("here!!!!!!!!1") #tem = get_action('package_show')(context, data_dict) #print(tem) c.pkg_dict = get_action('package_show')(context, data_dict) dataset_type = c.pkg_dict['type'] or 'dataset' except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id) #if request.method == 'POST': #new_group = request.POST.get('group_added') #if new_group: #data_dict = {"id": new_group, #"object": id, #"object_type": 'package', #"capacity": 'public'} #try: #get_action('member_create')(context, data_dict) #except NotFound: #abort(404, _('Group not found')) #removed_group = None #for param in request.POST: #if param.startswith('group_remove'): #removed_group = param.split('.')[-1] #break #if removed_group: #data_dict = {"id": removed_group, #"object": id, #"object_type": 'package'} #try: #get_action('member_delete')(context, data_dict) #except NotFound: #abort(404, _('Group not found')) #redirect(h.url_for(controller='package', #action='groups', id=id)) #context['is_member'] = True #users_groups = get_action('group_list_authz')(context, data_dict) #pkg_group_ids = set(group['id'] for group #in c.pkg_dict.get('groups', [])) #user_group_ids = set(group['id'] for group #in users_groups) #c.group_dropdown = [[group['id'], group['display_name']] #for group in users_groups if #group['id'] not in pkg_group_ids] #for group in c.pkg_dict.get('groups', []): #group['user_member'] = (group['id'] in user_group_ids) context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj, 'use_cache': False } resource_ids = None try: meta_dict = {'resource_id': '_table_metadata'} tables = get_action('datastore_search')(context, meta_dict) for t in tables['records']: print(t['name']) if t['name'] == "data_dict": resource_ids = t['alias_of'] except: resource_ids = None if resource_ids == None: create = { 'resource': { 'package_id': id }, 'aliases': 'data_dict', 'fields': [{ 'id': 'package_id', 'type': 'text' }, { 'id': 'id', 'type': 'int4' }, { 'id': 'title', 'type': 'text' }, { 'id': 'field_name', 'type': 'text' }, { 'id': 'format', 'type': 'text' }, { 'id': 'description', 'type': 'text' }], 'primary_key': ['id'] } get_action('datastore_create')(context, create) print("CREATE TABLE !!!!!!!!!!!!!!!!!!!!!!!") meta_dict = {'resource_id': '_table_metadata'} tables = get_action('datastore_search')(context, meta_dict) for t in tables['records']: print(t['name']) if t['name'] == "data_dict": resource_ids = t['alias_of'] data_dict_dict = { 'resource_id': resource_ids, 'filters': { 'package_id': id }, 'sort': ['id'] } try: pkg_data_dictionary = get_action('datastore_search')( context, data_dict_dict) print(pkg_data_dictionary['records']) c.pkg_data_dictionary = pkg_data_dictionary['records'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id) return render('package/dictionary_display.html', {'dataset_type': dataset_type})
action='edit', id=id)) redirect(h.url_for(controller='package', action='read', id=id)) if not data: data = get_action('package_show')(context, {'id': id}) errors = errors or {} error_summary = error_summary or {} vars = {'data': data, 'errors': errors, 'error_summary': error_summary} vars['pkg_name'] = id package_type = self._get_package_type(id) self._setup_template_variables(context, {}, package_type=package_type) return render('package/new_package_metadata.html', extra_vars=vars) def read(self, id, format='html'): if not format == 'html': ctype, extension, loader = \ self._content_type_from_extension(format) if not ctype: # An unknown format, we'll carry on in case it is a # revision specifier and re-constitute the original id id = "%s.%s" % (id, format) ctype, format, loader = "text/html; charset=utf-8", "html", \ MarkupTemplate else: ctype, format, loader = self._content_type_from_accept() response.headers['Content-Type'] = ctype
def resource_read(self, id, resource_id): custom_base.g_analitics() context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj, 'for_view': True} try: c.package = get_action('package_show')(context, {'id': id}) except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id) c.upload_file_url = config.get('ckan.upload_file_url') c.upload_file_url_sec = config.get('ckan.upload_file_url_sec') for resource in c.package.get('resources', []): if resource['id'] == resource_id: url = resource['url'] # check if the resource is local and can be previewed if 'dataset' in url: resource['is_local_resource'] = True else: resource['is_local_resource'] = False # removes the host to make it relative if config.get('ckan.upload_file_url'): if config.get('ckan.upload_file_url') in url: url = url.split(config.get('ckan.upload_file_url')) resource['url'] = url[1] if config.get('ckan.upload_file_url_sec') in url: url = url.split(config.get('ckan.upload_file_url_sec')) resource['url'] = url[1] # resource['url'] = url[1] c.resource = resource break if not c.resource: abort(404, _('Resource not found')) # required for nav menu c.pkg = context['package'] c.pkg_dict = c.package dataset_type = c.pkg.type or 'dataset' # get package license info license_id = c.package.get('license_id') try: c.package['isopen'] = model.Package.\ get_license_register()[license_id].isopen() except KeyError: c.package['isopen'] = False # TODO: find a nicer way of doing this c.datastore_api = '%s/api/action' % \ config.get('ckan.site_url', '').rstrip('/') #deprecated #c.related_count = c.pkg.related_count c.resource['can_be_previewed'] = self._resource_preview( {'resource': c.resource, 'package': c.package}) resource_views = get_action('resource_view_list')( context, {'id': resource_id}) c.resource['has_views'] = len(resource_views) > 0 current_resource_view = None view_id = request.GET.get('view_id') if c.resource['can_be_previewed'] and not view_id: current_resource_view = None elif c.resource['has_views']: if view_id: current_resource_view = [rv for rv in resource_views if rv['id'] == view_id] if len(current_resource_view) == 1: current_resource_view = current_resource_view[0] else: abort(404, _('Resource view not found')) else: current_resource_view = resource_views[0] vars = {'resource_views': resource_views, 'current_resource_view': current_resource_view, 'dataset_type': dataset_type} template = self._resource_template(dataset_type) return render(template, extra_vars=vars)
def dictionary(self, id): """Render logic for displaying the dictionary for a given package.""" context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj, 'use_cache': False } data_dict = {'id': id} try: log.info("dictionary: trying to get the data_dict") c.pkg_dict = get_action('package_show')(context, data_dict) dataset_type = c.pkg_dict['type'] or 'dataset' except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id) context = self.get_context() resource_ids = None try: meta_dict = {'resource_id': '_table_metadata'} tables = get_action('datastore_search')(context, meta_dict) for t in tables['records']: print(t['name']) if t['name'] == "data_dict": resource_ids = t['alias_of'] except: resource_ids = None if resource_ids == None: create = { 'resource': { 'package_id': id }, 'aliases': 'data_dict', 'fields': [{ 'id': 'package_id', 'type': 'text' }, { 'id': 'id', 'type': 'int4' }, { 'id': 'title', 'type': 'text' }, { 'id': 'field_name', 'type': 'text' }, { 'id': 'format', 'type': 'text' }, { 'id': 'description', 'type': 'text' }] } log.info( "dictionary: creating the data_dict table in the datastore" ) get_action('datastore_create')(context, create) meta_dict = {'resource_id': '_table_metadata'} tables = get_action('datastore_search')(context, meta_dict) for t in tables['records']: print(t['name']) if t['name'] == "data_dict": resource_ids = t['alias_of'] data_dict_dict = { 'resource_id': resource_ids, 'filters': { 'package_id': id }, 'sort': ['id'] } try: pkg_data_dictionary = get_action('datastore_search')( context, data_dict_dict) print(pkg_data_dictionary['records']) c.pkg_data_dictionary = pkg_data_dictionary['records'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id) return render('package/dictionary_display.html', {'dataset_type': dataset_type})
def edit_dictionary(self, id, data=None, errors=None): """Edit dictionary.""" context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj, 'use_cache': False } resource_ids = None meta_dict = {'resource_id': '_table_metadata'} tables = get_action('datastore_search')(context, meta_dict) for t in tables['records']: if t['name'] == "data_dict": resource_ids = t['alias_of'] if resource_ids is None: create = { 'resource': { 'package_id': id }, 'aliases': 'data_dict', 'fields': [{ 'id': 'package_id', 'type': 'text' }, { 'id': 'id', 'type': 'int4' }, { 'id': 'title', 'type': 'text' }, { 'id': 'field_name', 'type': 'text' }, { 'id': 'format', 'type': 'text' }, { 'id': 'description', 'type': 'text' }] } get_action('datastore_create')(context, create) meta_dict = {'resource_id': '_table_metadata'} tables = get_action('datastore_search')(context, meta_dict) for t in tables['records']: print(t['name']) if t['name'] == "data_dict": resource_ids = t['alias_of'] data_dict_dict = { 'resource_id': resource_ids, 'filters': { 'package_id': id }, 'sort': ['id'] } try: pkg_data_dictionary = get_action('datastore_search')( context, data_dict_dict) c.pkg_data_dictionary = pkg_data_dictionary['records'] c.link = str("/dataset/dictionary/new_dict/" + id) c.pkg_dict = get_action('package_show')(context, {'id': id}) c.pkg = context['package'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id) return render("package/edit_data_dict.html", extra_vars={'package_id': id})
package_type = pkg_dict['type'] or 'dataset' errors = errors or {} error_summary = error_summary or {} vars = {'data': data, 'errors': errors, 'error_summary': error_summary, 'action': 'new', 'resource_form_snippet': self._resource_form(package_type), 'dataset_type': package_type} vars['pkg_name'] = id # required for nav menu vars['pkg_dict'] = pkg_dict template = 'package/new_resource_not_draft.html' if pkg_dict['state'].startswith('draft'): vars['stage'] = ['complete', 'active'] template = 'package/new_resource.html' return render(template, extra_vars=vars) def dictionary(self, id): context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj, 'use_cache': False} data_dict = {'id': id} try: print("here!!!!!!!!1") #tem = get_action('package_show')(context, data_dict) #print(tem) c.pkg_dict = get_action('package_show')(context, data_dict) dataset_type = c.pkg_dict['type'] or 'dataset' except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read dataset %s') % id)
def redirectSecond(self, id, data=None, errors=None): return render("package/new_resource.html")
def finaldict(self, id, data=None, errors=None): if request.method== 'POST': print("!!!!!!!!!!!!!!!!!!1 POsted FROM EXTENSION!!!!!!!!!!!1") #print(request.params.get()) c.link = str("/dataset/dictionary/new_dict/"+id) return render("package/new_data_dict.html",extra_vars={'package_id':id})
def edit(self, id, data=None, errors=None, error_summary=None): # custom_base.g_analitics() package_type = self._get_package_type(id) context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj, 'save': 'save' in request.params} if context['save'] and not data: # check against csrf attacks custom_base.csrf_check(self) return self._save_edit(id, context, package_type=package_type) try: c.pkg_dict = get_action('package_show')(context, {'id': id}) context['for_edit'] = True old_data = get_action('package_show')(context, {'id': id}) # old data is from the database and data is passed from the # user if there is a validation error. Use users data if there. if data: old_data.update(data) data = old_data except NotAuthorized: abort(401, _('Unauthorized to read package %s') % '') except NotFound: abort(404, _('Dataset not found')) analytics_helpers.update_analytics_code_by_organization(c.pkg_dict['organization']['id']) # are we doing a multiphase add? if data.get('state', '').startswith('draft'): c.form_action = h.url_for(controller='package', action='new') c.form_style = 'new' return self.new(data=data, errors=errors, error_summary=error_summary) c.pkg = context.get("package") c.resources_json = h.json.dumps(data.get('resources', [])) try: check_access('package_update', context) except NotAuthorized: abort(401, _('User %r not authorized to edit %s') % (c.user, id)) # convert tags if not supplied in data if data and not data.get('tag_string'): data['tag_string'] = ', '.join(h.dict_list_reduce( c.pkg_dict.get('tags', {}), 'name')) errors = errors or {} form_snippet = self._package_form(package_type=package_type) form_vars = {'data': data, 'errors': errors, 'error_summary': error_summary, 'action': 'edit', 'dataset_type': package_type, } c.errors_json = h.json.dumps(errors) self._setup_template_variables(context, {'id': id}, package_type=package_type) # deprecated # c.related_count = c.pkg.related_count # we have already completed stage 1 form_vars['stage'] = ['active'] if data.get('state', '').startswith('draft'): form_vars['stage'] = ['active', 'complete'] edit_template = self._edit_template(package_type) # c.form = ckan.lib.render.deprecated_lazy_render( # edit_template, # form_snippet, # lambda: render(form_snippet, extra_vars=form_vars), # 'use of c.form is deprecated. please see ' # 'ckan/templates/package/edit.html for an example ' # 'of the new way to include the form snippet' # ) return render(edit_template, extra_vars={'form_vars': form_vars, 'form_snippet': form_snippet, 'dataset_type': package_type})
class OdpatPackageController(ckan.controllers.package.PackageController): p.implements(p.IPackageController) log.info("Enter: OdpatPackageController") def edit(self, id, data=None, errors=None, error_summary=None): package_type = self._get_package_type(id) context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj, 'save': 'save' in request.params, 'moderated': config.get('moderated'), 'pending': True } if context['save'] and not data: return self._save_edit(id, context, package_type=package_type) try: c.pkg_dict = get_action('package_show')(context, {'id': id}) context['for_edit'] = True old_data = get_action('package_show')(context, {'id': id}) # old data is from the database and data is passed from the # user if there is a validation error. Use users data if there. if data: old_data.update(data) data = old_data except NotAuthorized: abort(401, _('Unauthorized to read package %s') % '') except NotFound: abort(404, _('Dataset not found')) # are we doing a multiphase add? if data.get('state', '').startswith('draft'): c.form_action = h.url_for(controller='package', action='new') c.form_style = 'new' return self.new(data=data, errors=errors, error_summary=error_summary) c.pkg = context.get("package") c.resources_json = h.json.dumps(data.get('resources', [])) try: check_access('package_update', context) except NotAuthorized, e: abort(401, _('User %r not authorized to edit %s') % (c.user, id)) # convert tags if not supplied in data if data and not data.get('tag_string'): data['tag_string'] = ', '.join( h.dict_list_reduce(c.pkg_dict.get('tags', {}), 'name')) # Extract extra values to main structure for simple access if data and data['extras']: for extra in data['extras']: data[extra['key']] = extra['value'] errors = errors or {} vars = { 'data': data, 'errors': errors, 'error_summary': error_summary, 'action': 'edit' } c.errors_json = h.json.dumps(errors) self._setup_template_variables(context, {'id': id}, package_type=package_type) c.related_count = c.pkg.related_count # we have already completed stage 1 vars['stage'] = ['active'] if data.get('state') == 'draft': vars['stage'] = ['active', 'complete'] elif data.get('state') == 'draft-complete': vars['stage'] = ['active', 'complete', 'complete'] # TODO: This check is to maintain backwards compatibility with the # old way of creating custom forms. This behaviour is now deprecated. if hasattr(self, 'package_form'): c.form = render(self.package_form, extra_vars=vars) else: c.form = render(self._package_form(package_type=package_type), extra_vars=vars) return render(self._edit_template(package_type), extra_vars={'stage': vars['stage']})
package_type = c.pkg_dict['type'] or 'dataset' self._setup_template_variables(context, {'id': id}, package_type=package_type) template = self._read_template(package_type) template = template[:template.index('.') + 1] + format feedback_form = FeedbackController.get_form_items() feedback_form += [ {'name': 'source_type', 'control': 'hidden'}, {'name': 'source_id', 'control': 'hidden'}, ] try: return render(template, extra_vars={'dataset_type': package_type, 'feedback_form_items': feedback_form}) except ckan.lib.render.TemplateNotFound: msg = _("Viewing {package_type} datasets in {format} format is " "not supported (template file {file} not found).".format( package_type=package_type, format=format, file=template)) abort(404, msg) assert False, "We should never get here" def _resource_tag_string_to_list(self, tag_string): ''' This is used to change tags from a sting to a list of dicts ''' out = [] for tag in tag_string.split(','): tag = tag.strip() if tag: out.append({'name': tag,
def dataset_doi_admin_form(self, dataset_url, dataset): xml = build_xml(dataset) template = 'package/doi_admin.html' return render(template, extra_vars={'xml': xml, 'dataset_url': dataset_url})
def edit(self, id, data=None, errors=None, error_summary=None): custom_base.g_analitics() package_type = self._get_package_type(id) context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj, 'save': 'save' in request.params} if context['save'] and not data: #check against csrf attacks custom_base.csrf_check(self) return self._save_edit(id, context, package_type=package_type) try: c.pkg_dict = get_action('package_show')(context, {'id': id}) context['for_edit'] = True old_data = get_action('package_show')(context, {'id': id}) # old data is from the database and data is passed from the # user if there is a validation error. Use users data if there. if data: old_data.update(data) data = old_data except NotAuthorized: abort(401, _('Unauthorized to read package %s') % '') except NotFound: abort(404, _('Dataset not found')) # are we doing a multiphase add? if data.get('state', '').startswith('draft'): c.form_action = h.url_for(controller='package', action='new') c.form_style = 'new' return self.new(data=data, errors=errors, error_summary=error_summary) c.pkg = context.get("package") c.resources_json = h.json.dumps(data.get('resources', [])) try: check_access('package_update', context) except NotAuthorized: abort(401, _('User %r not authorized to edit %s') % (c.user, id)) # convert tags if not supplied in data if data and not data.get('tag_string'): data['tag_string'] = ', '.join(h.dict_list_reduce( c.pkg_dict.get('tags', {}), 'name')) errors = errors or {} form_snippet = self._package_form(package_type=package_type) form_vars = {'data': data, 'errors': errors, 'error_summary': error_summary, 'action': 'edit', 'dataset_type': package_type, } c.errors_json = h.json.dumps(errors) self._setup_template_variables(context, {'id': id}, package_type=package_type) #deprecated #c.related_count = c.pkg.related_count # we have already completed stage 1 form_vars['stage'] = ['active'] if data.get('state', '').startswith('draft'): form_vars['stage'] = ['active', 'complete'] edit_template = self._edit_template(package_type) #c.form = ckan.lib.render.deprecated_lazy_render( # edit_template, # form_snippet, # lambda: render(form_snippet, extra_vars=form_vars), # 'use of c.form is deprecated. please see ' # 'ckan/templates/package/edit.html for an example ' # 'of the new way to include the form snippet' # ) return render(edit_template, extra_vars={'form_vars': form_vars, 'form_snippet': form_snippet, 'dataset_type': package_type})
vars = { "data": data, "errors": errors, "error_summary": error_summary, "action": "new", "resource_form_snippet": self._resource_form(package_type), "dataset_type": package_type, } vars["pkg_name"] = id # required for nav menu vars["pkg_dict"] = pkg_dict template = "package/new_resource_not_draft.html" if pkg_dict["state"].startswith("draft"): vars["stage"] = ["complete", "active"] template = "package/new_resource.html" return render(template, extra_vars=vars) """ def delete_ext(self, id): # c.linkResource = str("/dataset/edit/" + id) print("here is delete ext") if "cancel" in request.params: h.redirect_to(controller="package", action="edit", id=id) context = { "model": model, "session": model.Session, "user": c.user, "auth_user_obj": c.userobj, }
def new(self, data=None, errors=None, error_summary=None): if data and 'type' in data: package_type = data['type'] else: package_type = self._guess_package_type(True) context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj, 'save': 'save' in request.params} # Package needs to have a organization group in the call to # check_access and also to save it try: check_access('package_create', context) except NotAuthorized: abort(401, _('Unauthorized to create a package')) if context['save'] and not data: #check against csrf attacks custom_base.csrf_check(self) return self._save_new(context, package_type=package_type) data = data or clean_dict(dict_fns.unflatten(tuplize_dict(parse_params( request.params, ignore_keys=CACHE_PARAMETERS)))) c.resources_json = h.json.dumps(data.get('resources', [])) # convert tags if not supplied in data if data and not data.get('tag_string'): data['tag_string'] = ', '.join( h.dict_list_reduce(data.get('tags', {}), 'name')) errors = errors or {} error_summary = error_summary or {} # in the phased add dataset we need to know that # we have already completed stage 1 stage = ['active'] if data.get('state', '').startswith('draft'): stage = ['active', 'complete'] # if we are creating from a group then this allows the group to be # set automatically data['group_id'] = request.params.get('group') or \ request.params.get('groups__0__id') form_snippet = self._package_form(package_type=package_type) form_vars = {'data': data, 'errors': errors, 'error_summary': error_summary, 'action': 'new', 'stage': stage, 'dataset_type': package_type, } c.errors_json = h.json.dumps(errors) self._setup_template_variables(context, {}, package_type=package_type) new_template = self._new_template(package_type) #c.form = ckan.lib.render.deprecated_lazy_render( # new_template, # form_snippet, # lambda: render(form_snippet, extra_vars=form_vars), # 'use of c.form is deprecated. please see ' # 'ckan/templates/package/base_form_page.html for an example ' # 'of the new way to include the form snippet' # ) return render(new_template, extra_vars={'form_vars': form_vars, 'form_snippet': form_snippet, 'dataset_type': package_type})
def import_form(self, data=None, errors=None, error_summary=None): package_type = self._guess_package_type(True) context = { 'model': model, 'session': model.Session, 'user': c.user or c.author, 'auth_user_obj': c.userobj, 'save': 'save' in request.params } # Package needs to have a organization group in the call to # check_access and also to save it try: check_access('package_create', context) except NotAuthorized: abort(401, _('Unauthorized to create a package')) if context['save'] and not data: return self._save_new(context, package_type=package_type) data = data or clean_dict( dict_fns.unflatten( tuplize_dict( parse_params(request.params, ignore_keys=CACHE_PARAMETERS)))) c.resources_json = h.json.dumps(data.get('resources', [])) # convert tags if not supplied in data if data and not data.get('tag_string'): data['tag_string'] = ', '.join( h.dict_list_reduce(data.get('tags', {}), 'name')) errors = errors or {} error_summary = error_summary or {} # if we are creating from a group then this allows the group to be # set automatically data['group_id'] = request.params.get('group') or \ request.params.get('groups__0__id') form_snippet = self.package_form form_vars = { 'data': data, 'errors': errors, 'error_summary': error_summary, 'action': 'new', 'dataset_type': package_type, } c.errors_json = h.json.dumps(errors) self._setup_template_variables(context, {}, package_type=package_type) new_template = self._new_template(package_type) c.form = ckan.lib.render.deprecated_lazy_render( new_template, form_snippet, lambda: render(form_snippet, extra_vars=form_vars), 'use of c.form is deprecated. please see ' 'ckan/templates/package/base_form_page.html for an example ' 'of the new way to include the form snippet') return render(new_template, extra_vars={ 'form_vars': form_vars, 'form_snippet': form_snippet, 'dataset_type': package_type })
def finalrel(self, id, data=None, errors=None): if request.method == "POST": pass c.link = str("/dataset/relationship/edit/" + id) return render("package/new_data_relation.html", extra_vars={"package_id": id})
def doi_form(self, id): # Mostly copied from PackageController:read context = {'model': model, 'session': model.Session, 'user': c.user or c.author, 'for_view': True, 'auth_user_obj': c.userobj} data_dict = {'id': id} dataset_url = toolkit.url_for( controller='package', action='read', id=id, qualified=True ) # check if package exists try: c.pkg_dict = get_action('package_show')(context, data_dict) c.pkg = context['package'] except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(401, _('Unauthorized to read package %s') % id) self.fail_if_private(c.pkg_dict, dataset_url) # used by disqus plugin c.current_package_id = c.pkg.id c.related_count = c.pkg.related_count package_type = c.pkg_dict['type'] or 'dataset' self._setup_template_variables(context, {'id': id}, package_type=package_type) ########################## ADD DOI STUFF ########################### template = 'package/doi.html' fields = dict( (field.lower().replace(' ', '_').translate(None, '()'), field) for field in doi_request_fields ) q = Session.query(DoiRequest).filter_by(package_id=c.pkg_dict['id'], user_id=c.userobj.id) ((request_exists, ),) = Session.query(q.exists()) if request_exists: h.flash_notice("You've already requested a DOI for this dataset. " "You'll be emailed if it is approved.") return toolkit.redirect_to(dataset_url) try: return render(template, extra_vars={ 'dataset_type': package_type, # TODO 'data': {}, 'errors': None, 'fields': fields }) except ckan.lib.render.TemplateNotFound: msg = _("Viewing {package_type} datasets in {format} format is " "not supported (template file {file} not found).".format( package_type=package_type, format=format, file=template)) abort(404, msg)
c.page = h.Page(collection=[]) c.search_facets_limits = {} for facet in c.search_facets.keys(): try: limit = int(request.params.get('_%s_limit' % facet, int(config.get('search.facets.default', 10)))) except ValueError: abort(400, _('Parameter "{parameter_name}" is not ' 'an integer').format( parameter_name='_%s_limit' % facet)) c.search_facets_limits[facet] = limit self._setup_template_variables(context, {}, package_type=package_type) return render(self._search_template(package_type), extra_vars={'dataset_type': package_type}) def read(self, id): custom_base.g_analitics() context = {'model': model, 'session': model.Session, 'user': c.user, 'for_view': True, 'auth_user_obj': c.userobj} data_dict = {'id': id, 'include_tracking': True} # interpret @<revision_id> or @<date> suffix split = id.split('@') if len(split) == 2: data_dict['id'], revision_ref = split if model.is_id(revision_ref): context['revision_id'] = revision_ref else: