Ejemplo n.º 1
0
def post_archetypes():
    search_results = []
    if request.form.get('deck_id') is not None:
        archetype_ids = request.form.getlist('archetype_id')
        # Adjust archetype_ids if we're assigning multiple decks to the same archetype.
        if len(archetype_ids) == 1 and len(
                request.form.getlist('deck_id')) > 1:
            archetype_ids = archetype_ids * len(
                request.form.getlist('deck_id'))
        for deck_id in request.form.getlist('deck_id'):
            archetype_id = archetype_ids.pop(0)
            if archetype_id:
                archs.assign(deck_id, archetype_id)
    elif request.form.get('q') is not None:
        search_results = ds.load_decks_by_cards(
            request.form.get('q').splitlines())
    elif request.form.getlist('archetype_id') is not None and len(
            request.form.getlist('archetype_id')) == 2:
        archs.move(
            request.form.getlist('archetype_id')[0],
            request.form.getlist('archetype_id')[1])
    elif request.form.get('parent') is not None:
        archs.add(request.form.get('name'), request.form.get('parent'))
    else:
        raise InvalidArgumentException(
            'Did not find any of the expected keys in POST to /admin/archetypes: {f}'
            .format(f=request.form))
    return edit_archetypes(search_results)
Ejemplo n.º 2
0
def post_archetypes() -> wrappers.Response:
    search_results: List[Deck] = []
    if request.form.get('deck_id') is not None:
        archetype_ids = request.form.getlist('archetype_id')
        # Adjust archetype_ids if we're assigning multiple decks to the same archetype.
        if len(archetype_ids) == 1 and len(request.form.getlist('deck_id')) > 1:
            archetype_ids = archetype_ids * len(request.form.getlist('deck_id'))
        for deck_id in request.form.getlist('deck_id'):
            archetype_id = archetype_ids.pop(0)
            if archetype_id:
                archs.assign(deck_id, archetype_id, auth.person_id())
                redis.clear(f'decksite:deck:{deck_id}')
    elif request.form.get('q') is not None and request.form.get('notq') is not None:
        search_results = ds.load_decks_by_cards(cast(str, request.form.get('q')).splitlines(), cast(str, request.form.get('notq')).splitlines())
    elif request.form.get('find_conflicts') is not None:
        search_results = ds.load_conflicted_decks()
    elif request.form.get('rename_to') is not None:
        archs.rename(cast_int(request.form.get('archetype_id')), cast(str, request.form.get('rename_to')))
    elif request.form.get('new_description') is not None:
        archs.update_description(cast_int(request.form.get('archetype_id')), cast(str, request.form.get('new_description')))
    elif request.form.getlist('archetype_id') is not None and len(request.form.getlist('archetype_id')) == 2:
        archs.move(request.form.getlist('archetype_id')[0], request.form.getlist('archetype_id')[1])
    elif request.form.get('parent') is not None:
        archs.add(cast(str, request.form.get('name')), cast_int(request.form.get('parent')))
    else:
        raise InvalidArgumentException('Did not find any of the expected keys in POST to /admin/archetypes: {f}'.format(f=request.form))
    return edit_archetypes(search_results, request.form.get('q', ''), request.form.get('notq', ''))