示例#1
0
            lambda g,up,u: g.group_id == self.group_id ) ] )
    users = property( get_users )
    
    def get_permissions( self ):
        return set( [ i[2] for i in self.sandbox.recall(
            group_class + group_permission_class + permission_class,
            lambda g,gp,p: g.group_id == self.group_id ) ] )
    permissions = property( get_permissions )

def jsonify_group(obj):
    result = turbogears.database.so_to_dict( obj )
    result["users"] = [ u.user_name for u in obj.users ]
    result["permissions"] = [ p.permission_name for p in obj.permissions ]
    return result

jsonify_group = jsonify.when( "isinstance(obj, TG_Group)" )( jsonify_group )

class PasswordProperty( TriggerProperty ):
    def on_set( self, unit, old_value ):
        cleartext_password = unit.password
        "Runs cleartext_password through the hash algorithm before saving."
        try:
            hash = identity.current_provider.encrypt_password(cleartext_password)
        except identity.exceptions.IdentityManagementNotEnabledException:
            # Creating identity provider just to encrypt password
            # (so we don't reimplement the encryption step).
            ip = DejavuProvider()
            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.")
示例#2
0
    def __deepcopy__(self, memo):
        return self

def lazify(func):

    def newfunc(*args, **kw):

        lazystr = lazystring(func, *args, **kw)
        return lazystr

    return newfunc

def jsonify_lazystring(obj):
    return unicode(obj)
jsonify.when("isinstance(obj, lazystring)")(jsonify_lazystring)

lazy_gettext = lazify(plain_gettext)
lazy_ngettext = lazify(plain_ngettext)

def gettext(key, locale=None, domain=None):
    """Gets the gettext value for key. Added to builtins as '_'. Returns Unicode string.

    @param key: text to be translated
    @param locale: locale code to be used. If locale is None, gets the value provided by get_locale.
     """

    if request_available():
        return plain_gettext(key, locale, domain)
    else:
        return lazy_gettext(key, locale, domain)
示例#3
0
    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")
示例#4
0
    def __eq__(self, other):
        return self.eval() == other

    def __deepcopy__(self, memo):
        return self


def lazify(func):
    def newfunc(*args, **kw):
        lazystr = lazystring(func, *args, **kw)
        return lazystr

    return newfunc


[jsonify.when("isinstance(obj, lazystring)")]


def jsonify_lazystring(obj):
    return unicode(obj)


lazy_gettext = lazify(plain_gettext)
lazy_ngettext = lazify(plain_ngettext)


def gettext(key, locale=None, domain=None):
    """Get the gettext value for key.

    Added to builtins as '_'. Returns Unicode string.
示例#5
0
    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"
示例#6
0
from turbojson.jsonify import jsonify
from sqlalchemy.orm.query import Query

jsonify.when((Query, ))(lambda obj: obj.all())
示例#7
0
            i[2] for i in self.sandbox.recall(
                group_class + group_permission_class +
                permission_class, lambda g, gp, p: g.group_id == self.group_id)
        ])

    permissions = property(get_permissions)


def jsonify_group(obj):
    result = turbogears.database.so_to_dict(obj)
    result["users"] = [u.user_name for u in obj.users]
    result["permissions"] = [p.permission_name for p in obj.permissions]
    return result


jsonify_group = jsonify.when("isinstance(obj, TG_Group)")(jsonify_group)


class PasswordProperty(TriggerProperty):
    def on_set(self, unit, old_value):
        cleartext_password = unit.password
        "Runs cleartext_password through the hash algorithm before saving."
        try:
            hash = identity.current_provider.encrypt_password(
                cleartext_password)
        except identity.exceptions.IdentityManagementNotEnabledException:
            # Creating identity provider just to encrypt password
            # (so we don't reimplement the encryption step).
            ip = DejavuProvider()
            hash = ip.encrypt_password(cleartext_password)
            if hash == cleartext_password:
示例#8
0
            " , ".join(["%s=%r" % (k, v) for k, v in paginate.__dict__.items()])

    def assert_ok(body, key, value, raw=False):
        assert "ok: [paginate" in body
        if raw:
            expr = "%s=%s " % (key, value)
        else:
            expr = "%s=%r " % (key, value)
        # some simplejson versions escape forward slashes, so fix this
        body = body.replace('\\/', '/')
        if expr not in body:
            print body
        assert expr in body, "expected %s" % expr
    assert_ok = staticmethod(assert_ok)

[jsonify.when('isinstance(obj, Spy)')]
def jsonify_spy(obj):
    result = str(obj)
    return result


class TestSpy(unittest.TestCase):
    """Never trust a spy"""

    class MyRoot(RootController):

        [expose()]
        [paginate("data")]
        def spy(self):
            data = range(100)
            spy = Spy()