Beispiel #1
0
 def getthing(name, create=False):
     if isinstance(name, tdb.Thing):
         return name
     try:
         return db.get_version(context.site, name)
     except:
         if create and create_dependents:
             thing = db.new_version(context.site, name, getthing("type/thing"), {})
             thing.save()
             return thing
         else:
             raise
Beispiel #2
0
 def thingify(data, getparent):
     """Converts data into thing or primitive value."""
     if isinstance(data, list):
         return [thingify(x, getparent) for x in data]
     elif isinstance(data, dict):
         name = data.name
         if data.get('child'):
             d = {k: thingify(v, getparent) for k, v in data.d.items()}
             type = thingify(data.type, getparent)
             thing = db.new_version(getparent(), name, type, d)
             thing.save()
             return thing
         else:
             return getthing(name, create=True)
     else:
         return data
Beispiel #3
0
def hash_passwords():
    from infogami.core import auth
    
    tuser = db.get_type(ctx.site, 'type/user')
    users = tdb.Things(parent=ctx.site, type=tuser).list()
    
    for u in users:
        try:
            preferences = u._c('preferences')
        except:
            # setup preferences for broken accounts, so that they can use forgot password.
            preferences = db.new_version(u, 'preferences', db.get_type(ctx.site,'type/thing'), dict(password=''))
            preferences.save()
        
        if preferences.password:
            auth.set_password(u, preferences.password)
Beispiel #4
0
 def thingify(data, getparent):
     """Converts data into thing or primitive value.
     """
     if isinstance(data, list):
         return [thingify(x, getparent) for x in data]
     elif isinstance(data, dict):
         name = data.name
         if data.get('child'):
             d = dict([(k, thingify(v, getparent)) for k, v in data.d.items()])
             type = thingify(data.type, getparent)
             thing = db.new_version(getparent(), name, type, d)
             thing.save()
             return thing
         else:
             return getthing(name, create=True)
     else:
         return data
Beispiel #5
0
def _savepage(page, create_dependents=True, comment=None):
    """Saves a page from dict."""
    def getthing(name, create=False):
        if isinstance(name, tdb.Thing):
            return name
        try:
            return db.get_version(context.site, name)
        except:
            if create and create_dependents:
                thing = db.new_version(context.site, name,
                                       getthing("type/thing"), {})
                thing.save()
                return thing
            else:
                raise

    def thingify(data, getparent):
        """Converts data into thing or primitive value.
        """
        if isinstance(data, list):
            return [thingify(x, getparent) for x in data]
        elif isinstance(data, dict):
            name = data.name
            if data.get('child'):
                d = dict([(k, thingify(v, getparent))
                          for k, v in data.d.items()])
                type = thingify(data.type, getparent)
                thing = db.new_version(getparent(), name, type, d)
                thing.save()
                return thing
            else:
                return getthing(name, create=True)
        else:
            return data

    name = page.name
    type = getthing(page.type.name, create=True)
    d = {}

    getself = lambda: getthing(name, create=True)
    for k, v in page.d.items():
        d[k] = thingify(v, getself)

    _page = db.new_version(context.site, name, type, d)
    _page.save(author=context.user, comment=comment, ip=web.ctx.ip)
    return _page
Beispiel #6
0
def hash_passwords():
    from infogami.core import auth

    tuser = db.get_type(ctx.site, 'type/user')
    users = tdb.Things(parent=ctx.site, type=tuser).list()

    for u in users:
        try:
            preferences = u._c('preferences')
        except:
            # setup preferences for broken accounts, so that they can use forgot password.
            preferences = db.new_version(u, 'preferences',
                                         db.get_type(ctx.site, 'type/thing'),
                                         dict(password=''))
            preferences.save()

        if preferences.password:
            auth.set_password(u, preferences.password)
Beispiel #7
0
def _savepage(page, create_dependents=True, comment=None):
    """Saves a page from dict."""
    def getthing(name, create=False):
        if isinstance(name, tdb.Thing):
            return name
        try:
            return db.get_version(context.site, name)
        except:
            if create and create_dependents:
                thing = db.new_version(context.site, name, getthing("type/thing"), {})
                thing.save()
                return thing
            else:
                raise

    def thingify(data, getparent):
        """Converts data into thing or primitive value.
        """
        if isinstance(data, list):
            return [thingify(x, getparent) for x in data]
        elif isinstance(data, dict):
            name = data.name
            if data.get('child'):
                d = dict([(k, thingify(v, getparent)) for k, v in data.d.items()])
                type = thingify(data.type, getparent)
                thing = db.new_version(getparent(), name, type, d)
                thing.save()
                return thing
            else:
                return getthing(name, create=True)
        else:
            return data

    name = page.name
    type = getthing(page.type.name, create=True)
    d = {}
    
    getself = lambda: getthing(name, create=True)
    for k, v in page.d.items():
        d[k] = thingify(v, getself)
            
    _page = db.new_version(context.site, name, type, d)
    _page.save(author=context.user, comment=comment, ip=web.ctx.ip)
    return _page
Beispiel #8
0
    def GET(self, path):
        i = web.input(v=None, t=None)

        if not web.ctx.site.can_write(path):
            return render.permission_denied(web.ctx.fullpath, "Permission denied to edit " + path + ".")

        if i.v is not None and safeint(i.v, None) is None:
            raise web.seeother(web.changequery(v=None))

        p = db.get_version(path, i.v) or db.new_version(path, types.guess_type(path))

        if i.t:
            type = db.get_type(i.t)
            if type is None:
                add_flash_message('error', 'Unknown type: ' + i.t)
            else:
                p.type = type

        return render.editpage(p)