예제 #1
0
def update_lang(lang, **kw):
    """
    store original name in hname

    .. notes::

        We don't update the alternative names (for name search) here, instead, the script
        to update these names in bulk must be run after this function.
    """
    name = kw.pop('name', None)
    if name and name != lang.name:
        if 'hname' not in lang.jsondata:
            lang.update_jsondata(hname=lang.name)
        print 'renamed', lang.name, 'to', name
        lang.name = name
        print lang.jsondata

    for k, v in kw.items():
        if k not in lang.datadict():
            DBSession.add(Language_data(key=k, value=v, object_pk=lang.pk))
        else:
            for d in lang.data:
                if d.key == k and d.value != v:
                    print 'updated', k
                    d.value = v
                    break
예제 #2
0
    def test_Data(self):
        from clld.db.models.common import Language, Language_data

        l = Language(id='abc', name='Name')
        l.data.append(Language_data(key='abstract', value='c'))
        DBSession.add(l)
        DBSession.flush()
        DBSession.refresh(l)
        self.assertEqual(l.datadict()['abstract'], 'c')
예제 #3
0
def test_Versioning(db):
    from clld.db.models.common import Language, Language_data
    from clld.db.meta import VersionedDBSession

    l = Language(id='abc', name='Old Name', jsondata={'i': 2})
    VersionedDBSession.add(l)
    VersionedDBSession.flush()
    assert l.version == 1

    l.name = 'New Name'
    l.description = 'New Description'
    VersionedDBSession.flush()
    assert l.version == 2

    History = l.__history_mapper__.class_
    res = VersionedDBSession.query(History).filter(History.pk == l.pk).all()
    assert res[0].name == 'Old Name'

    l.data.append(Language_data(key='k', value='v'))
    VersionedDBSession.flush()
    assert l.datadict()
    VersionedDBSession.delete(l)
    VersionedDBSession.flush()