Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more model import cleans vocab and core
- Loading branch information
Showing
2 changed files
with
26 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |