Skip to content

Commit

Permalink
Whitespace cleanup (ahem) and fixing issues with group members
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Feb 15, 2012
1 parent 59b4308 commit e301565
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
44 changes: 22 additions & 22 deletions ckan/lib/dictization/model_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def resource_dict_save(res_dict, context):
model = context["model"]
session = context["session"]
trigger_url_change = False

id = res_dict.get("id")
obj = None
if id:
Expand All @@ -21,7 +21,7 @@ def resource_dict_save(res_dict, context):

table = class_mapper(model.Resource).mapped_table
fields = [field.name for field in table.c]

for key, value in res_dict.iteritems():
if isinstance(value, list):
continue
Expand Down Expand Up @@ -68,7 +68,7 @@ def package_resource_list_save(res_dicts, package, context):
else:
resource.state = 'deleted'
resource_list.append(resource)
tag_package_tag = dict((package_tag.tag, package_tag)
tag_package_tag = dict((package_tag.tag, package_tag)
for package_tag in
package.package_tag_all)

Expand All @@ -89,7 +89,7 @@ def package_extras_save(extra_dicts, obj, context):
for extra_dict in extra_dicts:
if extra_dict.get("deleted"):
continue

if extra_dict['value'] is None:
pass
elif extras_as_string:
Expand Down Expand Up @@ -138,7 +138,7 @@ def group_extras_save(extras_dicts, context):
return result_dict

def package_tag_list_save(tag_dicts, package, context):

allow_partial_update = context.get("allow_partial_update", False)
if not tag_dicts and allow_partial_update:
return
Expand All @@ -147,10 +147,10 @@ def package_tag_list_save(tag_dicts, package, context):
session = context["session"]
pending = context.get('pending')

tag_package_tag = dict((package_tag.tag, package_tag)
tag_package_tag = dict((package_tag.tag, package_tag)
for package_tag in
package.package_tag_all)

tag_package_tag_inactive = dict(
[ (tag,pt) for tag,pt in tag_package_tag.items() if
pt.state in ['deleted', 'pending-deleted'] ]
Expand Down Expand Up @@ -200,7 +200,7 @@ def package_membership_list_save(group_dicts, package, context):

members = session.query(model.Member).filter_by(table_id = package.id)

group_member = dict((member.group, member)
group_member = dict((member.group, member)
for member in
members)
groups = set()
Expand Down Expand Up @@ -234,7 +234,7 @@ def package_membership_list_save(group_dicts, package, context):
member_obj.state = 'active'
session.add(member_obj)


def relationship_list_save(relationship_dicts, package, attr, context):

allow_partial_update = context.get("allow_partial_update", False)
Expand All @@ -249,7 +249,7 @@ def relationship_list_save(relationship_dicts, package, attr, context):

relationships = []
for relationship_dict in relationship_dicts:
obj = table_dict_save(relationship_dict,
obj = table_dict_save(relationship_dict,
model.PackageRelationship, context)
relationships.append(obj)

Expand All @@ -264,7 +264,7 @@ def relationship_list_save(relationship_dicts, package, attr, context):

def package_dict_save(pkg_dict, context):
import uuid

model = context["model"]
package = context.get("package")
allow_partial_update = context.get("allow_partial_update", False)
Expand Down Expand Up @@ -338,21 +338,21 @@ def group_member_save(context, group_dict, member_table_name):


def group_dict_save(group_dict, context):
import uuid
import uuid

model = context["model"]
session = context["session"]
group = context.get("group")
allow_partial_update = context.get("allow_partial_update", False)

Group = model.Group
if group:
group_dict["id"] = group.id
group_dict["id"] = group.id

group = table_dict_save(group_dict, Group, context)
if not group.id:
group.id = str(uuid.uuid4())

context['group'] = group

group_member_save(context, group_dict, 'packages')
Expand All @@ -367,7 +367,7 @@ def group_dict_save(group_dict, context):
for key in old_extras - new_extras:
del group.extras[key]
for key in new_extras:
group.extras[key] = extras[key]
group.extras[key] = extras[key]


return group
Expand All @@ -378,11 +378,11 @@ def user_dict_save(user_dict, context):
model = context['model']
session = context['session']
user = context.get('user_obj')

User = model.User
if user:
user_dict['id'] = user.id

if 'password' in user_dict and not len(user_dict['password']):
del user_dict['password']

Expand Down Expand Up @@ -410,7 +410,7 @@ def package_api_to_dict(api1_dict, context):
updated_extras.update(value)

new_value = []

for extras_key, extras_value in updated_extras.iteritems():
if extras_value is not None:
new_value.append({"key": extras_key,
Expand All @@ -431,7 +431,7 @@ def package_api_to_dict(api1_dict, context):
dictized["resources"] = [{'url': download_url}]

download_url = dictized.pop('download_url', None)

return dictized

def group_api_to_dict(api1_dict, context):
Expand All @@ -443,7 +443,7 @@ def group_api_to_dict(api1_dict, context):
if key == 'packages':
new_value = [{"id": item} for item in value]
if key == 'extras':
new_value = [{"key": extra_key, "value": value[extra_key]}
new_value = [{"key": extra_key, "value": value[extra_key]}
for extra_key in value]
dictized[key] = new_value

Expand All @@ -454,7 +454,7 @@ def task_status_dict_save(task_status_dict, context):
task_status = context.get("task_status")
allow_partial_update = context.get("allow_partial_update", False)
if task_status:
task_status_dict["id"] = task_status.id
task_status_dict["id"] = task_status.id

task_status = table_dict_save(task_status_dict, model.TaskStatus, context)
return task_status
Expand Down
7 changes: 4 additions & 3 deletions ckan/model/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,15 @@ def set_approval_status(self, status):
pass

def members_of_type(self, object_type, capacity=None):
from ckan import model
object_type_string = object_type.__name__.lower()
query = Session.query(object_type).\
filter(group_table.c.id == self.id).\
filter(member_table.c.state == 'active').\
filter(member_table.c.table_name == object_type_string)
filter(model.Member.state == 'active').\
filter(model.Member.table_name == object_type_string)

if capacity:
query = query.filter(member_table.c.capacity == capacity)
query = query.filter(model.Member.capacity == capacity)

query = query.join(member_table, member_table.c.table_id == getattr(object_type,'id') ).\
join(group_table, group_table.c.id == member_table.c.group_id)
Expand Down
26 changes: 13 additions & 13 deletions ckan/model/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
)

class User(DomainObject):

VALID_NAME = re.compile(r"^[a-zA-Z0-9_\-]{3,255}$")
DOUBLE_SLASH = re.compile(':\/([^/])')

@classmethod
def by_openid(cls, openid):
obj = Session.query(cls).autoflush(False)
return obj.filter_by(openid=openid).first()

@classmethod
def get(cls, user_reference):
# double slashes in an openid often get turned into single slashes
Expand All @@ -57,7 +57,7 @@ def email_hash(self):
if self.email:
e = self.email.strip().lower().encode('utf8')
return hashlib.md5(e).hexdigest()

def get_reference_preferred_for_uri(self):
'''Returns a reference (e.g. name, id, openid) for this user
suitable for the user\'s URI.
Expand All @@ -73,7 +73,7 @@ def get_reference_preferred_for_uri(self):
else:
ref = self.id
return ref

def _set_password(self, password):
"""Hash password on the fly."""
if isinstance(password, unicode):
Expand Down Expand Up @@ -104,7 +104,7 @@ def validate_password(self, password):
:return: Whether the password is valid.
:rtype: bool
"""
if not password or not self.password:
if not password or not self.password:
return False
if isinstance(password, unicode):
password_8bit = password.encode('ascii', 'ignore')
Expand All @@ -114,7 +114,7 @@ def validate_password(self, password):
return self.password[40:] == hashed_pass.hexdigest()

password = property(_get_password, _set_password)

@classmethod
def check_name_valid(cls, name):
if not name \
Expand Down Expand Up @@ -147,10 +147,10 @@ def number_administered_packages(self):

def is_in_group(self, group):
return group in self.get_groups()

def get_groups(self, group_type=None, capacity=None):
import ckan.model as model

q = model.Session.query(model.Group)\
.join(model.Member, model.Member.group_id == model.Group.id and \
model.Member.table_name == 'user' ).\
Expand All @@ -160,20 +160,20 @@ def get_groups(self, group_type=None, capacity=None):
if capacity:
q = q.filter( model.Member.capacity == capacity )
return q.all()

if '_groups' not in self.__dict__:
self._groups = q.all()

groups = self._groups
if group_type:
if group_type:
groups = [g for g in groups if g.type == group_type]
return groups


@classmethod
def search(cls, querystr, sqlalchemy_query=None):
'''Search name, fullname, email and openid.
'''
import ckan.model as model
if sqlalchemy_query is None:
Expand Down
3 changes: 1 addition & 2 deletions ckan/public/scripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,9 @@ CKAN.Utils = function($, my) {
input_box.attr('name', new_name)
input_box.attr('id', new_name)

var capacity = $("input:radio[name=add-user-capacity]:checked").val();
parent_dd.before(
'<input type="hidden" name="' + old_name + '" value="' + ui.item.value + '">' +
'<input type="hidden" name="' + old_name.replace('__name','__capacity') + '" value="' + capacity + '">' +
'<input type="hidden" name="' + old_name.replace('__name','__capacity') + '" value="editor">' +
'<dd>' + ui.item.label + '</dd>'
);

Expand Down

0 comments on commit e301565

Please sign in to comment.