<commit_before>import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
from ckan.logic.action import delete
from ckan.logic.action import update
from ckan.model.package import Package
from ckan.model.resource import Resource
import logging

log = logging.getLogger(__name__)


def package_delete(context, data_dict):
    model = context['model']
    delete.package_delete(context, data_dict)
    package = Package.get(data_dict['id'])
    package.purge()
    model.repo.commit_and_remove()
    return None


def resource_update(context, data_dict):
    resource = Resource.get(data_dict['id'])
    if resource is not None and 'url' not in data_dict:
        url = resource.url
        data_dict['url'] = url
        log.debug(url)
    log.debug(data_dict)
    package_dict = update.resource_update(context, data_dict)
    return package_dict


class Welive_UtilsPlugin(plugins.SingletonPlugin):
    plugins.implements(plugins.IConfigurer)
    plugins.implements(plugins.IActions)

    # IConfigurer

    def update_config(self, config_):
        toolkit.add_template_directory(config_, 'templates')
        toolkit.add_public_directory(config_, 'public')
        toolkit.add_resource('fanstatic', 'welive_utils')

    # IActions

    def get_actions(self):
        return {'package_delete': package_delete,
                'resource_update': resource_update}<commit_msg>Avoid the overwriting of extras when not especifying them in the payload<commit_after>import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
from ckan.logic.action import delete
from ckan.logic.action import update
from ckan.logic.action import create
from ckan.model.package import Package
from ckan.model.resource import Resource
import logging

log = logging.getLogger(__name__)


def package_delete(context, data_dict):
    model = context['model']
    delete.package_delete(context, data_dict)
    package = Package.get(data_dict['id'])
    package.purge()
    model.repo.commit_and_remove()
    return None


def resource_update(context, data_dict):
    model = context['model']
    resource = Resource.get(data_dict['id'])
    extras = resource.extras
    if resource is not None and 'url' not in data_dict:
        url = resource.url
        data_dict['url'] = url
    resource_dict = update.resource_update(context, data_dict)
    resource = Resource.get(data_dict['id'])
    if len(resource.extras) <= 0:
        resource.extras = extras
    model.repo.commit()
    for key in resource.extras:
        resource_dict[key] = resource.extras[key]
    return resource_dict


def resource_create(context, data_dict):
    url = ""
    data_dict['url'] = url
    package_dict = create.resource_create(context, data_dict)
    return package_dict


class Welive_UtilsPlugin(plugins.SingletonPlugin):
    plugins.implements(plugins.IConfigurer)
    plugins.implements(plugins.IActions)

    # IConfigurer

    def update_config(self, config_):
        toolkit.add_template_directory(config_, 'templates')
        toolkit.add_public_directory(config_, 'public')
        toolkit.add_resource('fanstatic', 'welive_utils')

    # IActions

    def get_actions(self):
        return {'package_delete': package_delete,
                'resource_update': resource_update,
                'resource_create': resource_create
                }
{'fraction_non_alphanumeric': 0.09303721488595439, 'fraction_numerical': 0.00030012004801920766, 'mean_word_length': 3.7682403433476397, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '99425', 'n_tokens_mistral': 989, 'n_tokens_neox': 960, 'n_words': 221}