Skip to content

Commit

Permalink
more model import cleans vocab and core
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Mar 28, 2012
1 parent 204d807 commit 62113e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
23 changes: 12 additions & 11 deletions ckan/model/core.py
@@ -1,40 +1,41 @@
import datetime
from meta import metadata, mapper

from sqlalchemy import Column, DateTime, Text, Boolean
import vdm.sqlalchemy

import meta
import domain_object

## VDM-specific tables
revision_table = vdm.sqlalchemy.make_revision_table(metadata)
revision_table = vdm.sqlalchemy.make_revision_table(meta.metadata)
revision_table.append_column(Column('approved_timestamp', DateTime))

class System(domain_object.DomainObject):

name = 'system'

def __unicode__(self):
return u'<%s>' % self.__class__.__name__

def purge(self):
pass

@classmethod
def by_name(cls, name):
return System()
def by_name(cls, name):
return System()

# VDM-specific domain objects
State = vdm.sqlalchemy.State
State.all = [ State.ACTIVE, State.DELETED ]
Revision = vdm.sqlalchemy.make_Revision(mapper, revision_table)
Revision = vdm.sqlalchemy.make_Revision(meta.mapper, revision_table)


def make_revisioned_table(table):
revision_table = vdm.sqlalchemy.make_revisioned_table(table)
revision_table.append_column(Column('expired_id',
revision_table.append_column(Column('expired_id',
Text))
revision_table.append_column(Column('revision_timestamp', DateTime))
revision_table.append_column(Column('expired_timestamp', DateTime,
revision_table.append_column(Column('expired_timestamp', DateTime,
default=datetime.datetime(9999, 12, 31)))
revision_table.append_column(Column('current', Boolean))
return revision_table
Expand Down
26 changes: 14 additions & 12 deletions ckan/model/vocabulary.py
@@ -1,39 +1,41 @@
from meta import Table, types, Session
from core import metadata, Column, mapper
from types import make_uuid
## IMPORTS FIXED
import sqlalchemy as sa

import meta
import types
import tag
import domain_object

VOCABULARY_NAME_MIN_LENGTH = 2
VOCABULARY_NAME_MAX_LENGTH = 100

vocabulary_table = Table(
'vocabulary', metadata,
Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
Column('name', types.Unicode(VOCABULARY_NAME_MAX_LENGTH), nullable=False,
vocabulary_table = meta.Table(
'vocabulary', meta.metadata,
sa.Column('id', sa.types.UnicodeText, primary_key=True, default=types.make_uuid),
sa.Column('name', sa.types.Unicode(VOCABULARY_NAME_MAX_LENGTH), nullable=False,
unique=True),
)

class Vocabulary(domain_object.DomainObject):

def __init__(self, name):
self.id = make_uuid()
self.id = types.make_uuid()
self.name = name

@classmethod
def get(cls, id_or_name):
"""Return a Vocabulary object referenced by its id or name, or None if
there is no vocabulary with the given id or name.
"""
query = Session.query(Vocabulary).filter(Vocabulary.id==id_or_name)
query = meta.Session.query(Vocabulary).filter(Vocabulary.id==id_or_name)
vocab = query.first()
if vocab is None:
vocab = Vocabulary.by_name(id_or_name)
return vocab

@property
def tags(self):
return Session.query(tag.Tag).filter(tag.Tag.vocabulary_id==self.id)
return meta.Session.query(tag.Tag).filter(tag.Tag.vocabulary_id==self.id)

mapper(Vocabulary, vocabulary_table)
meta.mapper(Vocabulary, vocabulary_table)

0 comments on commit 62113e1

Please sign in to comment.