Beispiel #1
0
def search(request, query):
    meta_fulltext = WhatMetaFulltext.objects.only('id', 'artist', 'torrent_group')
    meta_fulltext = meta_fulltext.extra(
        where=['MATCH(`info`, `more_info`) AGAINST (%s IN BOOLEAN MODE)'], params=[query])
    meta_fulltext = meta_fulltext.extra(select={'score': 'MATCH (`info`) AGAINST (%s)'},
                                        select_params=[query])
    meta_fulltext = meta_fulltext.extra(order_by=['-score'])
    meta_fulltext = meta_fulltext.prefetch_related('artist', 'torrent_group', 'artist_alias',
                                                   'artist_alias__artist')
    meta_fulltext = meta_fulltext[:20]
    results = []
    for result in meta_fulltext:
        if result.artist:
            results.append({'type': 'artist', 'artist': get_artist_dict(result.artist)})
        elif result.torrent_group:
            results.append({
                'type': 'torrent_group',
                'torrent_group': get_torrent_group_dict(result.torrent_group)
            })
        elif result.artist_alias:
            results.append({
                'type': 'artist',
                'artist': get_artist_alias_dict(result.artist_alias)
            })
    return results
Beispiel #2
0
def random_torrent_groups(request):
    count = request.GET.get('count', 10)
    torrent_group_ids = list(WhatTorrentGroup.objects.extra(select={
        'rand': 'RAND()'
    }, order_by=['rand']).values_list('id', flat=True)[:count])
    torrent_groups = WhatTorrentGroup.objects.in_bulk(torrent_group_ids)
    return [get_torrent_group_dict(g) for g in torrent_groups.itervalues()]
Beispiel #3
0
def get_torrent_group(request, group_id):
    try:
        if 'HTTP_X_REFRESH' in request.META:
            raise WhatTorrentGroup.DoesNotExist()
        torrent_group = WhatTorrentGroup.objects.get(id=group_id)
    except WhatTorrentGroup.DoesNotExist:
        what_client = get_what_client(request)
        torrent_group = WhatTorrentGroup.update_from_what(what_client, group_id)
    data = get_torrent_group_dict(torrent_group)
    data.update(get_torrent_groups_have([torrent_group.id], True)[torrent_group.id])
    return data