Esempio n. 1
0
    def dump(predicate=None):
        things = {}
        # get in chunks of 10000 to limit the load on db.
        N = 10000
        offset = 0

        while True:
            things = tdb.Things(parent=context.site, offset=offset, limit=N, orderby='thing.id')
            offset += N
            if not things:
                break
            for t in things:
                if predicate and not predicate(t):
                    continue
                data = thing2dict(t)
                f.write(str(data))
                f.write('\n')
Esempio n. 2
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)
Esempio n. 3
0
def upgrade_types():
    from infogami.core.db import _create_type, tdbsetup

    tdbsetup()
    type = db.get_type(ctx.site, "type/type")
    types = tdb.Things(parent=ctx.site, type=type)
    types = [
        t for t in types
        if 'properties' not in t.d and 'is_primitive' not in t.d
    ]
    primitives = dict(int='type/int',
                      integer='type/int',
                      string='type/string',
                      text='type/text')

    newtypes = {}
    for t in types:
        properties = []
        backreferences = []
        print(t, t.d, file=web.debug)
        if t.name == 'type/site':
            continue
        for name, value in t.d.items():
            p = web.storage(name=name)
            typename = web.lstrips(value, "thing ")

            if typename.startswith('#'):
                typename, property_name = typename.lstrip('#').split('.')
                p.type = db.get_type(ctx.site, typename)
                p.property_name = property_name
                backreferences.append(p)
                continue

            if typename.endswith('*'):
                typename = typename[:-1]
                p.unique = False
            else:
                p.unique = True
            if typename in primitives:
                typename = primitives[typename]
            p.type = db.get_type(ctx.site, typename)
            properties.append(p)
        _create_type(ctx.site, t.name, properties, backreferences)
Esempio n. 4
0
def list_latest_reviews():
    for review in tdb.Things(type=db.get_type('type/bookreview'), limit=40):
        print('[%s] %s (%s)' % (review.author, review.book, review.source))
Esempio n. 5
0
def get_links(site, path):
    return tdb.Things(type=get_links_type(), site=site, links=path)