How to use the turbojson.jsonify.jsonify function in TurboJson

To help you get started, we’ve selected a few TurboJson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github obeattie / pylons / tests / test_units / test_decorated_controller.py View on Github external
@jsonify.when('isinstance(obj, MyClass)')
def jsonify_myclass(obj):
    return {'result':'wo-hoo!'}
github Pylons / pylons / tests / test_units / test_decorated_controller.py View on Github external
@jsonify.when('isinstance(obj, MyClass)')
def jsonify_myclass(obj):
    return {'result':'wo-hoo!'}
github fedora-infra / python-fedora / fedora / tg / identity / soprovidercsrf.py View on Github external
created = DateTimeCol(default=datetime.now)

    # Old names
    groupId = DeprecatedAttr("groupId", "group_name")
    displayName = DeprecatedAttr("displayName", "display_name")

    # collection of all users belonging to this group
    users = RelatedJoin("TG_User", intermediateTable="tg_user_group",
        joinColumn="group_id", otherColumn="user_id")

    # collection of all permissions for this group
    permissions = RelatedJoin("TG_Permission", joinColumn="group_id",
        intermediateTable="tg_group_permission",
        otherColumn="permission_id")

[jsonify.when('isinstance(obj, TG_Group)')]
def jsonify_group(obj):
    """Convert group to JSON."""
    result = jsonify_sqlobject(obj)
    result["users"] = [u.user_name for u in obj.users]
    result["permissions"] = [p.permission_name for p in obj.permissions]
    return result


class TG_User(InheritableSQLObject):
    """Reasonably basic User definition."""
    class sqlmeta:
        table = "tg_user"

    user_name = UnicodeCol(length=16, alternateID=True,
        alternateMethodName="by_user_name")
    email_address = UnicodeCol(length=255, alternateID=True,
github fedora-infra / python-fedora / fedora / tg / json.py View on Github external
@jsonify.when('''(
        isinstance(obj, sqlalchemy.orm.collections.InstrumentedList) or
        isinstance(obj, sqlalchemy.orm.attributes.InstrumentedAttribute) or
        isinstance(obj, sqlalchemy.ext.associationproxy._AssociationList))''')
def jsonify_salist(obj):
    '''Transform SQLAlchemy InstrumentedLists into json.

    The one special thing is that we bind the special json_props into each
    descendent.  This allows us to specify a json_props on the toplevel
    query result and it will pass to all of its children.

    :arg obj: One of the sqlalchemy list types to jsonify
    :Returns: list of jsonified elements
    '''
    if 'json_props' in obj.__dict__:
        for element in obj:
            element.json_props = obj.json_props
github fedora-infra / python-fedora / fedora / tg / identity / soprovidercsrf.py View on Github external
except identity.exceptions.IdentityManagementNotEnabledException:
            # Creating identity provider just to encrypt password
            # (so we don't reimplement the encryption step).
            ip = SqlObjectCsrfIdentityProvider()
            hash = ip.encrypt_password(cleartext_password)
            if hash == cleartext_password:
                log.info("Identity provider not enabled,"
                    " and no encryption algorithm specified in config."
                    " Setting password as plaintext.")
        self._SO_set_password(hash)

    def set_password_raw(self, password):
        """Save the password as-is to the database."""
        self._SO_set_password(password)

[jsonify.when('isinstance(obj, TG_User)')]
def jsonify_user(obj):
    """Convert user to JSON."""
    result = jsonify_sqlobject(obj)
    del result['password']
    result["groups"] = [g.group_name for g in obj.groups]
    result["permissions"] = [p.permission_name for p in obj.permissions]
    return result


class TG_Permission(InheritableSQLObject):
    """Permissions for a given group."""
    class sqlmeta:
        table = "tg_permission"

    permission_name = UnicodeCol(length=16, alternateID=True,
        alternateMethodName="by_permission_name")
github fedora-infra / fas / fas / json.py View on Github external
@jsonify.when("isinstance(obj, sqlalchemy.orm.attributes.InstrumentedAttribute) or isinstance(obj, sqlalchemy.ext.associationproxy._AssociationList)")
def jsonify_salist(obj):
    '''Transform SQLAlchemy InstrumentedLists into json.
    
    The one special thing is that we bind the special jsonProps into each
    descendent.  This allows us to specify a jsonProps on the toplevel
    query result and it will pass to all of its children.
    '''
    if 'jsonProps' in obj.__dict__:
        for element in obj:
            element.jsonProps = obj.jsonProps
    return [jsonify(element) for element in  obj]
github fedora-infra / bodhi / bodhi / json.py View on Github external
@jsonify.when('isinstance(obj, User)')
def jsonify_user(obj):
    result = jsonify_sqlobject(obj)
    del result['password']
    result["groups"] = [g.group_name for g in obj.groups]
    result["permissions"] = [p.permission_name for p in obj.permissions]
    return result
github wesnoth / wesnoth / website / stats.wesnoth.org / wesstats / json.py View on Github external
@jsonify.when('isinstance(obj, Permission)')
def jsonify_permission(obj):
    result = jsonify_sqlobject( obj )
    result["groups"] = [g.group_name for g in obj.groups]
    return result
github fedora-infra / python-fedora / fedora / tg / json.py View on Github external
def jsonify_salist(obj):
    '''Transform SQLAlchemy InstrumentedLists into json.

    The one special thing is that we bind the special json_props into each
    descendent.  This allows us to specify a json_props on the toplevel
    query result and it will pass to all of its children.

    :arg obj: One of the sqlalchemy list types to jsonify
    :Returns: list of jsonified elements
    '''
    if 'json_props' in obj.__dict__:
        for element in obj:
            element.json_props = obj.json_props
    return [jsonify(element) for element in obj]
github fedora-infra / fas / fas / json.py View on Github external
def jsonify_salist(obj):
    '''Transform SQLAlchemy InstrumentedLists into json.
    
    The one special thing is that we bind the special jsonProps into each
    descendent.  This allows us to specify a jsonProps on the toplevel
    query result and it will pass to all of its children.
    '''
    if 'jsonProps' in obj.__dict__:
        for element in obj:
            element.jsonProps = obj.jsonProps
    return [jsonify(element) for element in  obj]

TurboJson

Python template plugin that supports JSON

MIT
Latest version published 13 years ago

Package Health Score

42 / 100
Full package analysis

Similar packages