Ejemplo n.º 1
0
def gens_view(request, item_type=None, item_name=None,
              ordering='popular', search_term=None,
              page_no=1, num=ITEMS_PER_PAGE):
    num = num or ITEMS_PER_PAGE
    type = item_name or 'Popular'
    if item_type == 'category':
        type = item_name.rsplit('.', 1)[-1]

    item_name = query.get_user(item_name) if item_type == 'user' else item_name
    keywords = {str(item_type): item_name} if item_type else {}
    gens = query.get_generators_list(ordering, search_term, **keywords)

    for gen in gens:
        gen['fimages'] = get_fimages(gen, '160x120')
       
    paginator = Paginator(gens, int(num))
    try:
        gens = paginator.page(int(page_no))
    except (EmptyPage, InvalidPage):
        gens = paginator.page(paginator.num_pages)

    return render_response(request, 'ui/home.html', {
        'type': type,
        'gens': gens,
        'item_type': item_type,
        'item_name': item_name,
        'top_authors': get_top_authors(),
        'recent_gens': get_recent_gens()})
Ejemplo n.º 2
0
def gen_view(request, item_name=None):
    gen_info = query.get_generator_info(item_name)

    gen = query.get_generator(item_name)
    if gen:
        views = gen.views+1 if gen.views else 1
        gen_info['views'] = views
        gen.views = views
        gen.save()

    gen_info['fimages'] = get_fimages(gen_info, '180x120')

    package_info = query.get_package_info(gen_info['package_id'])

    for gen in package_info['gens']:
        gen['fimages'] = get_fimages(gen, '30x30')

    user=query.get_user(package_info['username'])
    user_top = query.get_generators_list('popular', user=user, limit=5)
    for gen in user_top:
        gen['fimages'] = get_fimages(gen, '30x30')

    return render_response(request, 'ui/generator.html', {
        'gen': gen_info,
        'package': package_info,
        'user_top': user_top
        })
Ejemplo n.º 3
0
def item_list_view(request, item_type, item_name, item_list_type,
              ordering='relevance', search_term=None,
              page_no=1, num=ITEMS_PER_PAGE):

    type = 'get_%s_list' %item_list_type
    fn = getattr(query, type)

    item_name = query.get_user(item_name) if item_type == 'user' else item_name
    keywords = {str(item_type): item_name}
    values = fn(ordering, search_term, **keywords)

    code = 'success' if values else 'err_record'

    return apiresponse(code=code, data=values)
Ejemplo n.º 4
0
def user_view(request, username):
    user=query.get_user(username)
    user_info = query.get_user_info(record=user)

    for gen in user_info['favs']:
        gen['fimages'] = get_fimages(gen, '30x30')

    user_gens = query.get_generators_list(user=user, limit=10)
    for gen in user_gens:
        gen['fimages'] = get_fimages(gen, '30x30')

    user_packs = query.get_packages_list(user=user)
    for pack in user_packs:
        for gen in pack['gens'][:1]:
            pack['fimages'] = get_fimages(gen, '30x30')

    return render_response(request, 'ui/user.html', {
        'username': username,
        'user_info': user_info,
        'user_gens': user_gens,
        'user_packs': user_packs
        })