Пример #1
0
def home(request):
    api = Api(request)

    categories = (
        {'name':_('Last Releases'), 'api':local.API_URL_LAST,     'link':'last_releases'},
        {'name':_('Upcoming'),      'api':local.API_URL_UPCOMING, 'link':'upcomming'},
        {'name':_('Popular'),       'api':local.API_URL_POPULAR,  'link':'popular'},
        {'name':_('Top Rated'),     'api':local.API_URL_TOPRATED, 'link':'top_rated'},
    )

    params = {
        'api_key' : local.API_KEY,
        'language': request.LANGUAGE_CODE
    }

    featured = None

    for category in categories:
        result = api.get(category['api'], params)
        items  = result.get('results', [])

        for item in items:
            try:
                item['year'] = datetime.strptime(item.get('release_date'), '%Y-%m-%d').year
            except Exception as e:
                # pass
                raise Exception(e)

        category['items'] = items

        if category['link'] == 'popular':
            featured = items[:5]



    context = {
        'app': 'home',

        'featured'  : featured,
        'categories': categories,
    }

    return render(request, 'home.html', context)
Пример #2
0
def detail(request, id):
    api = Api(request)

    params = {
        'api_key'           : local.API_KEY,
        'language'          : request.LANGUAGE_CODE,
        'append_to_response': 'videos,images,similar'
    }
    item = api.get(local.API_URL_MOVIE % id, params)

    if item:
        # Passar o release_date para datetime
        try:
            item['release_date_dt'] = datetime.strptime(item.get('release_date'), '%Y-%m-%d').date()
        except Exception as e:
            pass

        # Passar o runtime para datetime
        runtime = item.get('runtime')

        if type(runtime) == int:
            ttime = runtime / 60, runtime % 60
            item['runtime_dt'] = time(ttime[0], ttime[1])

        # Passar o release_date dos sililares para datetime
        similars = item.get('similar', {}).get('results', [])

        for similar in similars:
            try:
                similar['year'] = datetime.strptime(similar.get('release_date'), '%Y-%m-%d').year
            except Exception as e:
                #pass
                raise Exception(e)


    context = {
        'app' : 'detail',

        'item': item,
    }
    return render(request, 'detail.html', context)
Пример #3
0
def search(request, query):
    api = Api(request)

    try:
        page = int(request.GET.get('p',    1))
        safe = int(request.GET.get('safe', 1))
    except Exception as e:
        raise Exception(e)

    params = {
        'api_key'      : local.API_KEY,
        'language'     : request.LANGUAGE_CODE,
        'page'         : page,
        'include_adult': False if safe else True,
        'query'        : query,
    }
    result = api.get(local.API_URL_SEARCH, params)
    items  = result.get('results', [])

    # Converte a data para datetime e retorna o ano
    for item in items:
        try:
            item['year'] = datetime.strptime(item.get('release_date'), '%Y-%m-%d').year
        except Exception as e:
            pass
            #raise Exception(e)


    context = {
        'app'   : 'search',

        'search': query,
        'page'  : page,
        'safe'  : safe,

        'items'      : result.get('results'),
        'total_items': result.get('total_results'),
        'total_pages': result.get('total_pages'),
    }
    return render(request, 'search.html', context)