Skip to content

Commit

Permalink
[#1163] Use ckan.model.core.State instead of ckan.model.State
Browse files Browse the repository at this point in the history
With this change, we're able to avoid having to load ckan.model inside methods,
to avoid circular dependencies.
  • Loading branch information
vitorbaptista committed Aug 9, 2013
1 parent 35112b2 commit f2615de
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions ckan/logic/action/get.py
Expand Up @@ -14,6 +14,7 @@
import ckan.logic.schema
import ckan.lib.dictization.model_dictize as model_dictize
import ckan.lib.navl.dictization_functions
import ckan.model.core as core
import ckan.model.misc as misc
import ckan.plugins as plugins
import ckan.lib.search as search
Expand Down Expand Up @@ -673,7 +674,7 @@ def user_list(context, data_dict):
)

# Filter deleted users
query = query.filter(model.User.state != model.State.DELETED)
query = query.filter(model.User.state != core.State.DELETED)

## hack for pagination
if context.get('return_query'):
Expand Down Expand Up @@ -1185,7 +1186,7 @@ def user_autocomplete(context, data_dict):
limit = data_dict.get('limit', 20)

query = model.User.search(q)
query = query.filter(model.User.state != model.State.DELETED)
query = query.filter(model.User.state != core.State.DELETED)
query = query.limit(limit)

user_list = []
Expand Down
4 changes: 2 additions & 2 deletions ckan/migration/versions/070_add_state_column_to_user_table.py
@@ -1,11 +1,11 @@
import ckan.model
import ckan.model.core


def upgrade(migrate_engine):
migrate_engine.execute(
'''
ALTER TABLE "user" ADD COLUMN "state" text NOT NULL DEFAULT '%s'
''' % ckan.model.State.ACTIVE
''' % ckan.model.core.State.ACTIVE
)


Expand Down
5 changes: 3 additions & 2 deletions ckan/model/follower.py
Expand Up @@ -3,6 +3,7 @@
import sqlalchemy
import vdm.sqlalchemy

import core
import ckan.model
import domain_object

Expand Down Expand Up @@ -80,8 +81,8 @@ def _get(cls, follower_id=None, object_id=None):
.filter(sqlalchemy.and_(follower_alias.id == follower_id,\
cls.follower_id == follower_alias.id,\
cls.object_id == object_alias.id,\
follower_alias.state != ckan.model.State.DELETED,\
object_alias.state != ckan.model.State.DELETED,\
follower_alias.state != core.State.DELETED,\
object_alias.state != core.State.DELETED,\
object_alias.id == object_id))

return query
Expand Down
4 changes: 2 additions & 2 deletions ckan/model/group.py
Expand Up @@ -195,8 +195,8 @@ def packages(self, with_private=False, limit=None,

query = meta.Session.query(_package.Package).\
filter(
or_(_package.Package.state == model.State.ACTIVE,
_package.Package.state == model.State.PENDING)). \
or_(_package.Package.state == core.State.ACTIVE,
_package.Package.state == core.State.PENDING)). \
filter(group_table.c.id == self.id).\
filter(member_table.c.state == 'active')

Expand Down
5 changes: 2 additions & 3 deletions ckan/model/user.py
Expand Up @@ -9,6 +9,7 @@
import vdm.sqlalchemy

import meta
import core
import types as _types
import domain_object

Expand Down Expand Up @@ -167,9 +168,7 @@ def number_administered_packages(self):
return q.count()

def is_deleted(self):
# have to import here to avoid circular imports
import ckan.model as model
return self.state == model.State.DELETED
return self.state == core.State.DELETED

def is_in_group(self, group):
return group in self.get_group_ids()
Expand Down

0 comments on commit f2615de

Please sign in to comment.