from ckan.common import _
import ckan.lib.navl.dictization_functions as df


def lower_if_exists(s):
    return s.lower() if s else s


def upper_if_exists(s):
    return s.upper() if s else s


def valid_resources(private, context):
    package = context.get('package')
    if not private or private == u'False':
        for resource in package.resources:
            if resource.extras.get('valid_content') == 'no':
                raise df.Invalid(_("Package contains invalid resources"))
    return private

from ckan.common import _
import ckan.lib.navl.dictization_functions as df


def lower_if_exists(s):
    return s.lower() if s else s


def upper_if_exists(s):
    return s.upper() if s else s


def valid_resources(private, context):
    package = context.get('package')
    if package and (not private or private == u'False'):
        for resource in package.resources:
            if resource.extras.get('valid_content') == 'no':
                raise df.Invalid(_("Package contains invalid resources"))
    return private

Fix package resource validator for new packages
LK-271: Fix package resource validator for new packages

  from ckan.common import _
  import ckan.lib.navl.dictization_functions as df
  
  
  def lower_if_exists(s):
      return s.lower() if s else s
  
  
  def upper_if_exists(s):
      return s.upper() if s else s
  
  
  def valid_resources(private, context):
      package = context.get('package')
-     if not private or private == u'False':
+     if package and (not private or private == u'False'):
          for resource in package.resources:
              if resource.extras.get('valid_content') == 'no':
                  raise df.Invalid(_("Package contains invalid resources"))
      return private
  
Fix package resource validator for new packages
## Code Before:
from ckan.common import _
import ckan.lib.navl.dictization_functions as df


def lower_if_exists(s):
    return s.lower() if s else s


def upper_if_exists(s):
    return s.upper() if s else s


def valid_resources(private, context):
    package = context.get('package')
    if not private or private == u'False':
        for resource in package.resources:
            if resource.extras.get('valid_content') == 'no':
                raise df.Invalid(_("Package contains invalid resources"))
    return private

## Instruction:
Fix package resource validator for new packages
## Code After:
from ckan.common import _
import ckan.lib.navl.dictization_functions as df


def lower_if_exists(s):
    return s.lower() if s else s


def upper_if_exists(s):
    return s.upper() if s else s


def valid_resources(private, context):
    package = context.get('package')
    if package and (not private or private == u'False'):
        for resource in package.resources:
            if resource.extras.get('valid_content') == 'no':
                raise df.Invalid(_("Package contains invalid resources"))
    return private
