Ejemplo n.º 1
0
def get_snippet_dataset(activity, detail):
    data = activity['data']
    pkg_dict = data.get('package') or data.get('dataset')
    link = h.dataset_link(pkg_dict) if pkg_dict else ''
    return literal('''<span>%s</span>'''
        % (link)
        )
Ejemplo n.º 2
0
def get_snippet_dataset(activity, detail):
    data = activity["data"]
    link = h.dataset_link(data.get("package") or data.get("dataset"))
    return literal(
        """<span data-module="popover-context" data-module-type="dataset" data-module-id="%s">%s</span>"""
        % (activity["object_id"], link)
    )
Ejemplo n.º 3
0
    def result(self):

        context = {
            'model': ckan.model,
            'session': ckan.model.Session,
            'user': pylons.c.user or pylons.c.author
        }

        #check for POST data
        if ckan.plugins.toolkit.request.method == 'POST':
            data = ckan.plugins.toolkit.request.POST
            dataset = data['dataset']
            resources = data['resources'].split(';')

            try:
                package = plugins.toolkit.get_action('package_show')(
                    context, {
                        'id': dataset
                    })
            except Exception:
                flash_error('error: update unsuccessful')

            #list of resources
            target_resources = package['resources']

            reorder_list = []

            for res in resources:
                index = map(itemgetter('name'), target_resources).index(res)
                reorder_list.append(target_resources[index])

            package['resources'] = reorder_list

            try:
                package = plugins.toolkit.get_action('package_update')(context,
                                                                       package)
                flash_success('resources in ' + dataset_display_name(package) +
                              ' have been updated')
            except:
                #something went wrong with the update
                flash_error('error: update unsuccessful')
            plugins.toolkit.c.resources = [
                item['name'] for item in package['resources']
            ]
            plugins.toolkit.c.name = package['name']
            plugins.toolkit.c.link = dataset_link(package)
        #no POST data - redirect to home page
        else:
            ckan.plugins.toolkit.redirect_to(controller="home", action="index")

        return plugins.toolkit.render('result.html')
Ejemplo n.º 4
0
def render_new_dataset(template, activity):
    """Return the HTML snippet describing a user creating a new dataset"""
    
    # Provide a html link to the user's page
    actor = link_to_user(activity['user_id'])
    actor = '%s' % actor
    
    # Provide a html link to the new group
    object = h.dataset_link(activity['data']['package'])
    if object:
        object = '%s' % object       
         
    # Build the entire message and return the html. 
    date = '%s' % h.render_datetime(activity['timestamp'])
    template = template.format(actor=actor, date=date, object=object)
    template = '%s %s' % (template, date)
    
    # It is important to return it as a literal or it will be converted to text
    return html.literal(template)
Ejemplo n.º 5
0
def render_new_dataset(template, activity):
    """Return the HTML snippet describing a user creating a new dataset"""

    # Provide a html link to the user's page
    actor = link_to_user(activity['user_id'])
    actor = '%s' % actor

    # Provide a html link to the new group
    object = h.dataset_link(activity['data']['package'])
    if object:
        object = '%s' % object

    # Build the entire message and return the html.
    date = '%s' % h.render_datetime(activity['timestamp'])
    template = template.format(actor=actor, date=date, object=object)
    template = '%s %s' % (template, date)

    # It is important to return it as a literal or it will be converted to text
    return html.literal(template)
Ejemplo n.º 6
0
    def result(self):

        context = {'model': ckan.model,
                   'session': ckan.model.Session,
                   'user': pylons.c.user or pylons.c.author}

        #check for POST data
        if ckan.plugins.toolkit.request.method == 'POST':
            data = ckan.plugins.toolkit.request.POST
            dataset = data['dataset']
            resources = data['resources'].split(';')

            try:
                package = plugins.toolkit.get_action('package_show')(context, {'id': dataset})
            except Exception:
                flash_error('error: update unsuccessful')

            #list of resources
            target_resources = package['resources']

            reorder_list = []

            for res in resources:
                index = map(itemgetter('name'), target_resources).index(res)
                reorder_list.append(target_resources[index])

            package['resources'] = reorder_list

            try:
                package = plugins.toolkit.get_action('package_update')(context, package)
                flash_success('resources in ' + dataset_display_name(package) + ' have been updated')
            except:
                #something went wrong with the update
                flash_error('error: update unsuccessful')
            plugins.toolkit.c.resources = [item['name'] for item in package['resources']]
            plugins.toolkit.c.name = package['name']
            plugins.toolkit.c.link = dataset_link(package)
        #no POST data - redirect to home page
        else:
            ckan.plugins.toolkit.redirect_to(controller="home", action="index")

        return plugins.toolkit.render('result.html')
Ejemplo n.º 7
0
def get_snippet_dataset(activity, detail):
    data = activity['data']
    link = h.dataset_link(data.get('package') or data.get('dataset'))
    return literal('''<span data-module="popover-context" data-module-type="dataset" data-module-id="%s">%s</span>'''
        % (activity['object_id'], link)
        )
Ejemplo n.º 8
0
def get_snippet_dataset(activity, detail):
    data = activity['data']
    link = h.dataset_link(data.get('package') or data.get('dataset'))
    return literal('''<span>%s</span>'''
        % (link)
        )
Ejemplo n.º 9
0
def get_snippet_dataset(activity, detail):
    data = activity['data']
    link = h.dataset_link(data.get('package') or data.get('dataset'))
    return literal('''<span>%s</span>''' % (link))
Ejemplo n.º 10
0
def get_snippet_dataset(activity, detail):
    data = activity["data"]
    link = h.dataset_link(data.get("package") or data.get("dataset"))
    return literal("""<span>%s</span>""" % (link))
Ejemplo n.º 11
0
def get_snippet_dataset(activity, detail):
    data = activity['data']
    return h.dataset_link(data.get('package') or data.get('dataset'))
Ejemplo n.º 12
0
def get_snippet_dataset(activity, detail):
    data = activity['data']
    return h.dataset_link(data.get('package') or data.get('dataset'))
Ejemplo n.º 13
0
def get_snippet_dataset(activity, detail):
    data = activity['data']
    link = h.dataset_link(data.get('package') or data.get('dataset'))
    return literal(
        '''<span data-module="popover-context" data-module-type="dataset" data-module-id="%s">%s</span>'''
        % (activity['object_id'], link))