Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 638-code-clean
Browse files Browse the repository at this point in the history
  • Loading branch information
johnglover committed Mar 19, 2013
2 parents dce07c1 + 0ce63ee commit 0716121
Show file tree
Hide file tree
Showing 25 changed files with 805 additions and 604 deletions.
5 changes: 4 additions & 1 deletion ckan/controllers/group.py
Expand Up @@ -196,7 +196,10 @@ def _read(self, id, limit):

q = c.q = request.params.get('q', '')
# Search within group
q += ' groups: "%s"' % c.group_dict.get('name')
if c.group_dict.get('is_organization'):
q += ' owner_org: "%s"' % c.group_dict.get('id')
else:
q += ' groups: "%s"' % c.group_dict.get('name')

try:
description_formatted = ckan.misc.MarkdownFormat().to_html(
Expand Down
8 changes: 7 additions & 1 deletion ckan/lib/app_globals.py
Expand Up @@ -109,9 +109,15 @@ def get_config_value(key, default=''):
value = model.get_system_info(key)
else:
value = None
config_value = config.get(key)
# sort encodeings if needed
if isinstance(config_value, str):
try:
config_value = config_value.decode('utf-8')
except UnicodeDecodeError:
config_value = config_value.decode('latin-1')
# we want to store the config the first time we get here so we can
# reset them if needed
config_value = config.get(key)
if key not in _CONFIG_CACHE:
_CONFIG_CACHE[key] = config_value
if value is not None:
Expand Down
12 changes: 9 additions & 3 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -23,7 +23,7 @@ def group_list_dictize(obj_list, context,
query = search.PackageSearchQuery()

q = {'q': '+capacity:public' if not with_private else '*:*',
'fl': 'groups', 'facet.field': ['groups'],
'fl': 'groups', 'facet.field': ['groups', 'owner_org'],
'facet.limit': -1, 'rows': 1}

query.run(q)
Expand All @@ -42,7 +42,10 @@ def group_list_dictize(obj_list, context,

group_dict['display_name'] = obj.display_name

group_dict['packages'] = query.facets['groups'].get(obj.name, 0)
if obj.is_organization:
group_dict['packages'] = query.facets['owner_org'].get(obj.id, 0)
else:
group_dict['packages'] = query.facets['groups'].get(obj.name, 0)

if context.get('for_view'):
if group_dict['is_organization']:
Expand Down Expand Up @@ -336,7 +339,10 @@ def group_dictize(group, context):
context)

query = search.PackageSearchQuery()
q = {'q': 'groups:"%s" +capacity:public' % group.name, 'rows': 1}
if group.is_organization:
q = {'q': 'owner_org:"%s" +capacity:public' % group.id, 'rows': 1}
else:
q = {'q': 'groups:"%s" +capacity:public' % group.name, 'rows': 1}
result_dict['package_count'] = query.run(q)['count']

result_dict['tags'] = tag_list_dictize(
Expand Down
127 changes: 60 additions & 67 deletions ckan/lib/plugins.py
Expand Up @@ -158,73 +158,43 @@ def register_group_plugins(map):


class DefaultDatasetForm(object):
"""
Provides a default implementation of the pluggable package
controller behaviour.
'''The default implementation of IDatasetForm.
This class has 2 purposes:
See ckan.plugins.interfaces.IDatasetForm.
- it provides a base class for IDatasetForm implementations to use
if only a subset of the 5 method hooks need to be customised.
This class has two purposes:
- it provides the fallback behaviour if no plugin is setup to
provide the fallback behaviour.
1. It provides a base class for IDatasetForm implementations to inherit
from.
2. It is used as the default fallback plugin, if no IDatasetForm plugin
registers itself as the fallback.
Note - this isn't a plugin implementation. This is deliberate, as we
don't want this being registered.
"""
def new_template(self):
"""
Returns a string representing the location of the template to be
rendered for the new page
"""
return 'package/new.html'
def edit_template(self):
"""
Returns a string representing the location of the template to be
rendered for the edit page
"""
return 'package/edit.html'

def comments_template(self):
"""
Returns a string representing the location of the template to be
rendered for the comments page
"""
return 'package/comments.html'
'''
def form_to_db_schema_options(self, options):
'''Return different form_to_db_schemas under different conditions.
def search_template(self):
"""
Returns a string representing the location of the template to be
rendered for the search page (if present)
"""
return 'package/search.html'
For example:
def read_template(self):
"""
Returns a string representing the location of the template to be
rendered for the read page
"""
return 'package/read.html'
- if a context is provided, and it contains a schema, return that
schema
- if a dataset is being created via the api then return
form_to_db_schema_api_create()
- if a dataset is being updated via the api then return
form_to_db_schema_api_update()
- if a dataset is being created via the web form then return
form_to_db_schema()
def history_template(self):
"""
Returns a string representing the location of the template to be
rendered for the history page
"""
return 'package/history.html'
The schemas are defined by the methods below.
def package_form(self):
return 'package/new_package_form.html'
Because of this method, if an IDatasetForm plugin inherits from this
class then its form_to_db_schema() method will only be called when a
dataset is being created or updated over the web interface, and not
when the api is being used.
def form_to_db_schema_options(self, options):
''' This allows us to select different schemas for different
purpose eg via the web interface or via the api or creation vs
updating. It is optional and if not available form_to_db_schema
should be used.
If a context is provided, and it contains a schema, it will be
returned.
'''
schema = options.get('context', {}).get('schema', None)
if schema:
Expand All @@ -248,26 +218,28 @@ def form_to_db_schema_api_create(self):
def form_to_db_schema_api_update(self):
return logic.schema.default_update_package_schema()

def db_to_form_schema(self):
'''This is an interface to manipulate data from the database
into a format suitable for the form (optional)'''
return logic.schema.db_to_form_package_schema()

def db_to_form_schema_options(self, options):
'''This allows the selectino of different schemas for different
purposes. It is optional and if not available, ``db_to_form_schema``
should be used.
If a context is provided, and it contains a schema, it will be
returned.
'''Return different db_to_form_schemas under different conditions.
For example:
- if a context is provided, and it contains a schema, return that
schema
- otherwise return db_to_form_schema()
The schemas are defined by the methods below.
'''
schema = options.get('context', {}).get('schema', None)
if schema:
return schema
return self.db_to_form_schema()

def db_to_form_schema(self):
return logic.schema.db_to_form_package_schema()

def check_data_dict(self, data_dict, schema=None):
'''Check if the return data is correct, mostly for checking out
if spammers are submitting only part of the form'''
'''Check for spammers submitting only part of the form.'''

# Resources might not exist yet (eg. Add Dataset)
surplus_keys_schema = ['__extras', '__junk', 'state', 'groups',
Expand Down Expand Up @@ -311,6 +283,27 @@ def setup_template_variables(self, context, data_dict):
except logic.NotAuthorized:
c.auth_for_change_state = False

def new_template(self):
return 'package/new.html'

def read_template(self):
return 'package/read.html'

def edit_template(self):
return 'package/edit.html'

def comments_template(self):
return 'package/comments.html'

def search_template(self):
return 'package/search.html'

def history_template(self):
return 'package/history.html'

def package_form(self):
return 'package/new_package_form.html'


class DefaultGroupForm(object):
"""
Expand Down
6 changes: 4 additions & 2 deletions ckan/lib/search/index.py
Expand Up @@ -157,8 +157,10 @@ def index_package(self, pkg_dict, defer_commit=False):

# if there is an owner_org we want to add this to groups for index
# purposes
if pkg_dict.get('organization'):
pkg_dict['groups'].append(pkg_dict['organization']['name'])
if pkg_dict['owner_org'] and pkg_dict.get('organization'):
pkg_dict['organization'] = pkg_dict['organization']['name']
else:
pkg_dict['organization'] = None


# tracking
Expand Down
2 changes: 1 addition & 1 deletion ckan/logic/action/get.py
Expand Up @@ -1323,7 +1323,7 @@ def package_search(context, data_dict):
for key_, value_ in value.items():
new_facet_dict = {}
new_facet_dict['name'] = key_
if key == 'groups':
if key in ('groups', 'organization'):
group = model.Group.get(key_)
if group:
new_facet_dict['display_name'] = group.display_name
Expand Down
2 changes: 2 additions & 0 deletions ckan/logic/auth/create.py
Expand Up @@ -106,6 +106,8 @@ def user_create(context, data_dict=None):


def _check_group_auth(context, data_dict):
# FIXME This code is shared amoung other logic.auth files and should be
# somewhere better
if not data_dict:
return True

Expand Down

0 comments on commit 0716121

Please sign in to comment.