def import_legacy_record(data): ans = FavoriteItem() ans.ident = data['id'] ans.name = data.get('name', '??') if data.get('corpora', None): ans.corpora = data.get('corpora') else: ans.corpora = [dict(id=data['corpus_id'], name=data['name'])] ans.subcorpus_id = data.get('subcorpus_id', None) ans.size = data.get('size', None) ans.size_info = data.get('size_info', None) return ans
def insert_favitem(self, user_id: int, item: FavoriteItem): with self._db.cursor() as cursor: cursor.execute( 'INSERT INTO kontext_user_fav_item (name, subcorpus_id, subcorpus_orig_id, user_id) ' 'VALUES (%s, %s, %s, %s) ', (item.name, item.subcorpus_id, item.subcorpus_orig_id, user_id)) favitem_id: int = cursor.lastrowid cursor.executemany( 'INSERT INTO kontext_corpus_user_fav_item (user_fav_corpus_id, corpus_name) ' 'VALUES (%s, %s) ', [(favitem_id, corp['id']) for corp in item.corpora]) self._db.commit() item.ident = str(favitem_id) # need to update new id
def import_legacy_record(data): ans = FavoriteItem() ans.ident = data['id'] ans.name = data.get('name', '??') ans.corpora = [dict(id=data['corpus_id'], name=data['name'])] if data.get('corpora', None): for item in data.get('corpora', []): try: ans.corpora.append(dict(id=item['canonical_id'], name=item['name'])) except Exception as ex: logging.getLogger(__name__).warning( 'Failed to import legacy fav. item record component: {0}'.format(ex)) ans.subcorpus_id = data.get('subcorpus_id', None) ans.subcorpus_orig_id = data.get('subcorpus_orig_id', ans.subcorpus_id) ans.size = data.get('size', None) ans.size_info = data.get('size_info', None) return ans
def import_legacy_record(data): ans = FavoriteItem() ans.ident = data['id'] ans.name = data.get('name', '??') ans.corpora = [dict(id=data['corpus_id'], name=data['name'])] if data.get('corpora', None): for item in data.get('corpora', []): try: ans.corpora.append(dict(id=item['canonical_id'], name=item['name'])) except Exception as ex: logging.getLogger(__name__).warning( u'Failed to import legacy fav. item record component: {0}'.format(ex)) ans.subcorpus_id = data.get('subcorpus_id', None) ans.subcorpus_orig_id = data.get('subcorpus_orig_id', ans.subcorpus_id) ans.size = data.get('size', None) ans.size_info = data.get('size_info', None) return ans