Skip to content

Commit

Permalink
Deferred composite column and bool() support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Apr 5, 2014
1 parent e78dc43 commit 301d67b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions coaster/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sqlalchemy import Column, Integer, DateTime, Unicode, UnicodeText
from sqlalchemy.sql import select, func
from sqlalchemy.types import UserDefinedType, TypeDecorator, TEXT
from sqlalchemy.orm import composite
from sqlalchemy.orm import composite, deferred
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.ext.mutable import Mutable, MutableComposite
Expand Down Expand Up @@ -455,16 +455,20 @@ def __setstate__(self, state):
object.__setattr__(self, '_html', state[1])
self.changed()

def __nonzero__(self):
return bool(self.text)

# Allow a composite column to be assigned a string value
@classmethod
def coerce(cls, key, value):
return cls(value)


def MarkdownColumn(name, **kwargs):
def MarkdownColumn(name, deferred=False, group=None, **kwargs):
return composite(MarkdownComposite,
Column(name + '_text', UnicodeText, **kwargs),
Column(name + '_html', UnicodeText, **kwargs)
Column(name + '_html', UnicodeText, **kwargs),
deferred=deferred, group=group or name
)


Expand Down

0 comments on commit 301d67b

Please sign in to comment.