Beispiel #1
0
def set_favorite_item(ctrl, request):
    """
    """
    corpora = []
    main_size = None
    for i, c_id in enumerate(request.form.getlist('corpora')):
        corp = ctrl.cm.get_corpus(
            c_id, subcname=request.form['subcorpus_id'] if i == 0 else None)
        if i == 0:
            main_size = corp.search_size
        corpora.append(dict(id=c_id, name=corp.get_conf('NAME')))
    subcorpus_id = request.form['subcorpus_id']
    subcorpus_orig_id = request.form['subcorpus_orig_id']
    item = FavoriteItem(
        dict(
            id=None,  # will be updated after database insert (autoincrement)
            name=' || '.join(c['name'] for c in corpora) +
            (' / ' + subcorpus_orig_id if subcorpus_orig_id else ''),
            corpora=corpora,
            subcorpus_id=subcorpus_id,
            subcorpus_orig_id=subcorpus_orig_id,
            size=main_size))
    with plugins.runtime.USER_ITEMS as uit:
        uit.add_user_item(ctrl._plugin_ctx, item)
        return item.to_dict()
Beispiel #2
0
def set_favorite_item(ctrl, request):
    """
    """
    corpora = []
    main_size = None
    for i, c_id in enumerate(request.form.getlist('corpora')):
        corp = ctrl.cm.get_Corpus(c_id, subcname=request.form['subcorpus_id'] if i == 0 else None)
        if i == 0:
            main_size = corp.search_size()
        corpora.append(dict(id=c_id, name=l10n.import_string(
            corp.get_conf('NAME'), corp.get_conf('ENCODING'))))
    subcorpus_id = request.form['subcorpus_id']
    subcorpus_orig_id = request.form['subcorpus_orig_id']
    item = FavoriteItem(dict(
        name=u' || '.join(c['name'] for c in corpora) +
        (u' / ' + subcorpus_orig_id if subcorpus_orig_id else u''),
        corpora=corpora,
        subcorpus_id=subcorpus_id,
        subcorpus_orig_id=subcorpus_orig_id,
        size=main_size,
        size_info=l10n.simplify_num(main_size)
    ))
    with plugins.runtime.USER_ITEMS as uit:
        uit.add_user_item(ctrl._plugin_api, item)
        return item.to_dict()
Beispiel #3
0
def set_favorite_item(ctrl, request):
    """
    """
    corpora = []
    main_size = None
    for i, c_id in enumerate(request.form.getlist('corpora')):
        corp = ctrl.cm.get_Corpus(
            c_id, subcname=request.form['subcorpus_id'] if i == 0 else None)
        if i == 0:
            main_size = corp.search_size()
        corpora.append(dict(id=c_id, name=corp.get_conf('NAME')))
    subcorpus_id = request.form['subcorpus_id']
    item = FavoriteItem(
        dict(name=' + '.join(c['name'] for c in corpora) +
             (' : ' + subcorpus_id if subcorpus_id else ''),
             corpora=corpora,
             subcorpus_id=request.form['subcorpus_id'],
             size=main_size,
             size_info=l10n.simplify_num(main_size)))
    with plugins.runtime.USER_ITEMS as uit:
        uit.add_user_item(ctrl._plugin_api, item)
        return item.to_dict()