Source code for sacrud_deform.common

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
# Copyright © 2014 uralbash <>
# Distributed under terms of the MIT license.

import json
from gettext import gettext as _

from sacrud.common import pk_to_list

[docs]class HTMLText(object): def __init__(self, text): self.text = text def __html__(self): try: return unicode(self.text) except NameError: # pragma: no cover return str(self.text) # pragma: no cover
[docs]def get_pk(obj): return json.dumps(pk_to_list(obj))
def _sa_row_to_choises(rows): return [(get_pk(ch), ch.__repr__()) for ch in rows]
[docs]def get_column_param(col, name, translate=_): if 'colanderalchemy' in and name in['colanderalchemy']: name =['colanderalchemy'][name] elif name == 'title': name = getattr(col, 'name', col.key) else: name = '' return translate(name)
[docs]def get_column_description(col): if 'description' in return HTMLText(['description']) return None
  Read the Docs
v: stable  
Free document hosting provided by Read the Docs.