Skip to content

Commit

Permalink
Merge branch 'master' into coding-standards-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Apr 24, 2013
2 parents b33185a + aa89102 commit be2ed32
Show file tree
Hide file tree
Showing 45 changed files with 934 additions and 1,291 deletions.
3 changes: 2 additions & 1 deletion ckan/controllers/group.py
Expand Up @@ -331,7 +331,8 @@ def pager_url(q=None, page=None):
c.search_facets = query['search_facets']
c.search_facets_limits = {}
for facet in c.facets.keys():
limit = int(request.params.get('_%s_limit' % facet, 10))
limit = int(request.params.get('_%s_limit' % facet,
g.facets_default_number))
c.search_facets_limits[facet] = limit
c.page.items = query['results']

Expand Down
3 changes: 2 additions & 1 deletion ckan/controllers/package.py
Expand Up @@ -267,7 +267,8 @@ def pager_url(q=None, page=None):
c.page = h.Page(collection=[])
c.search_facets_limits = {}
for facet in c.search_facets.keys():
limit = int(request.params.get('_%s_limit' % facet, 10))
limit = int(request.params.get('_%s_limit' % facet,
g.facets_default_number))
c.search_facets_limits[facet] = limit

maintain.deprecate_context_item(
Expand Down
2 changes: 2 additions & 0 deletions ckan/i18n/check_po_files.py
Expand Up @@ -106,6 +106,8 @@ def command(self):
print u'Checking file {}'.format(path)
po = polib.pofile(path)
for entry in po.translated_entries():
if not entry.msgstr:
continue
for function in (simple_conv_specs, mapping_keys,
replacement_fields):
if not function(entry.msgid) == function(entry.msgstr):
Expand Down
2 changes: 2 additions & 0 deletions ckan/lib/app_globals.py
Expand Up @@ -63,6 +63,8 @@
# int
'ckan.datasets_per_page': {'default': '20', 'type': 'int'},
'ckan.activity_list_limit': {'default': '30', 'type': 'int'},
'search.facets.default': {'default': '10', 'type': 'int',
'name': 'facets_default_number'},
}


Expand Down
44 changes: 24 additions & 20 deletions ckan/lib/cli.py
Expand Up @@ -1851,35 +1851,39 @@ def command(self):

custom_css = {
'fuchsia': '''
@layoutLinkColor: #b509b5;
@mastheadBackgroundColorStart: #dc0bdc;
@mastheadBackgroundColorEnd: #f31df3;
@btnPrimaryBackground: #f544f5;
@btnPrimaryBackgroundHighlight: #f76bf7;
@layoutLinkColor: #E73892;
@footerTextColor: mix(#FFF, @layoutLinkColor, 60%);
@footerLinkColor: @footerTextColor;
@mastheadBackgroundColor: @layoutLinkColor;
@btnPrimaryBackground: lighten(@layoutLinkColor, 10%);
@btnPrimaryBackgroundHighlight: @layoutLinkColor;
''',

'green': '''
@layoutLinkColor: #045b04;
@mastheadBackgroundColorStart: #068106;
@mastheadBackgroundColorEnd: #08a808;
@btnPrimaryBackground: #0acf0a;
@btnPrimaryBackgroundHighlight: #10f210
@layoutLinkColor: #2F9B45;
@footerTextColor: mix(#FFF, @layoutLinkColor, 60%);
@footerLinkColor: @footerTextColor;
@mastheadBackgroundColor: @layoutLinkColor;
@btnPrimaryBackground: lighten(@layoutLinkColor, 10%);
@btnPrimaryBackgroundHighlight: @layoutLinkColor;
''',

'red': '''
@layoutLinkColor: #b50909;
@mastheadBackgroundColorStart: #dc0b0b;
@mastheadBackgroundColorEnd: #f31d1d;
@btnPrimaryBackground: #f54444;
@btnPrimaryBackgroundHighlight: #f76b6b;
@layoutLinkColor: #C14531;
@footerTextColor: mix(#FFF, @layoutLinkColor, 60%);
@footerLinkColor: @footerTextColor;
@mastheadBackgroundColor: @layoutLinkColor;
@btnPrimaryBackground: lighten(@layoutLinkColor, 10%);
@btnPrimaryBackgroundHighlight: @layoutLinkColor;
''',

'maroon': '''
@layoutLinkColor: #5b0404;
@mastheadBackgroundColorStart: #810606;
@mastheadBackgroundColorEnd: #a80808;
@btnPrimaryBackground: #cf0a0a;
@btnPrimaryBackgroundHighlight: #f21010;
@layoutLinkColor: #810606;
@footerTextColor: mix(#FFF, @layoutLinkColor, 60%);
@footerLinkColor: @footerTextColor;
@mastheadBackgroundColor: @layoutLinkColor;
@btnPrimaryBackground: lighten(@layoutLinkColor, 10%);
@btnPrimaryBackgroundHighlight: @layoutLinkColor;
''',
}
def less(self):
Expand Down
11 changes: 11 additions & 0 deletions ckan/logic/__init__.py
Expand Up @@ -437,6 +437,17 @@ def get_converter(converter):
raise UnknownConverter('Converter `%s` does not exist' % converter)


def model_name_to_class(model_module, model_name):
'''Return the class in model_module that has the same name as the received string.
Raises AttributeError if there's no model in model_module named model_name.
'''
try:
model_class_name = model_name.title()
return getattr(model_module, model_class_name)
except AttributeError:
raise ValidationError("%s isn't a valid model" % model_class_name)

def _import_module_functions(module_path):
'''Import a module and get the functions and return them in a dict'''
functions_dict = {}
Expand Down
29 changes: 18 additions & 11 deletions ckan/logic/action/create.py
Expand Up @@ -418,28 +418,35 @@ def member_create(context, data_dict=None):
if 'message' in context:
rev.message = context['message']
else:
rev.message = _(u'REST API: Create member object %s') % data_dict.get("name", "")
rev.message = _(u'REST API: Create member object %s') % data_dict.get('name', '')

group = model.Group.get(data_dict.get('id', ''))
obj_id, obj_type, capacity = _get_or_bust(data_dict, ['object', 'object_type', 'capacity'])
group_id, obj_id, obj_type, capacity = _get_or_bust(data_dict, ['id', 'object', 'object_type', 'capacity'])

group = model.Group.get(group_id)
if not group:
raise NotFound('Group was not found.')

obj_class = ckan.logic.model_name_to_class(model, obj_type)
obj = obj_class.get(obj_id)
if not obj:
raise NotFound('%s was not found.' % obj_type.title())

# User must be able to update the group to add a member to it
_check_access('group_update', context, data_dict)

# Look up existing, in case it exists
member = model.Session.query(model.Member).\
filter(model.Member.table_name == obj_type).\
filter(model.Member.table_id == obj_id).\
filter(model.Member.table_id == obj.id).\
filter(model.Member.group_id == group.id).\
filter(model.Member.state == "active").first()
if member:
member.capacity = capacity
else:
filter(model.Member.state == 'active').first()
if not member:
member = model.Member(table_name = obj_type,
table_id = obj_id,
table_id = obj.id,
group_id = group.id,
state = 'active',
capacity=capacity)
state = 'active')

member.capacity = capacity

model.Session.add(member)
model.repo.commit()
Expand Down
18 changes: 13 additions & 5 deletions ckan/logic/action/delete.py
Expand Up @@ -168,7 +168,7 @@ def member_delete(context, data_dict=None):
:param id: the id of the group
:type id: string
:param object: the id of the object to be removed
:param object: the id or name of the object to be removed
:type object: string
:param object_type: the type of the object to be removed, e.g. ``package``
or ``user``
Expand All @@ -177,17 +177,25 @@ def member_delete(context, data_dict=None):
'''
model = context['model']

group = model.Group.get(_get_or_bust(data_dict, 'id'))
obj_id, obj_type = _get_or_bust(data_dict, ['object', 'object_type'])
group_id, obj_id, obj_type = _get_or_bust(data_dict, ['id', 'object', 'object_type'])

group = model.Group.get(group_id)
if not group:
raise NotFound('Group was not found.')

obj_class = ckan.logic.model_name_to_class(model, obj_type)
obj = obj_class.get(obj_id)
if not obj:
raise NotFound('%s was not found.' % obj_type.title())

# User must be able to update the group to remove a member from it
_check_access('group_update', context, data_dict)

member = model.Session.query(model.Member).\
filter(model.Member.table_name == obj_type).\
filter(model.Member.table_id == obj_id).\
filter(model.Member.table_id == obj.id).\
filter(model.Member.group_id == group.id).\
filter(model.Member.state == "active").first()
filter(model.Member.state == 'active').first()
if member:
rev = model.repo.new_revision()
rev.author = context.get('user')
Expand Down
13 changes: 1 addition & 12 deletions ckan/new_authz.py
Expand Up @@ -208,8 +208,7 @@ def get_user_id_for_username(user_name, allow_none=False):
return None
raise Exception('Not logged in user')

def _get_auth_function(action, profile=None):
from pylons import config
def _get_auth_function(action):

if action in AuthFunctions._functions:
return AuthFunctions._functions.get(action)
Expand All @@ -220,17 +219,7 @@ def _get_auth_function(action, profile=None):
# to load anything from ckan.auth that looks like it might
# be an authorisation function

# We will load the auth profile from settings
module_root = 'ckan.logic.auth'
if profile is not None:
auth_profile = profile
else:
auth_profile = config.get('ckan.auth.profile', '')

if auth_profile:
module_root = '%s.%s' % (module_root, auth_profile)

log.debug('Using auth profile at %s' % module_root)

for auth_module_name in ['get', 'create', 'update','delete']:
module_path = '%s.%s' % (module_root, auth_module_name,)
Expand Down

0 comments on commit be2ed32

Please sign in to comment.