Exemple #1
0
def home(request, **kwargs):
    shopping = Shopping.objects.get(slug=kwargs['slug'])
    destaques = Oferta.prontos(tipo=Oferta.DESTAQUE, shopping=shopping.id)

    eventos = Oferta.prontos(tipo=Oferta.EVENTO, shopping=shopping.id)

    ofertas = Oferta.prontos(shopping=shopping.id)
    mais_paginas = True if len(ofertas) > 14 else False
    ofertas = ofertas[:slice_oferta(len(destaques),len(eventos))]

    contexto = contexto_home(destaques,eventos,ofertas,mais_paginas,shopping)

    response = render(request, "home.html", contexto)
    response.set_cookie(key='shp_id', value=shopping.id)

    return response
Exemple #2
0
def ofertas(request, *args, **kwargs):
    tipo = request.GET.get('type', None)
    if request.method != 'GET':
        dados = {'error': u'Método inválido', 'error_message': u'Método não permitido nesse serviço'}
    else:
        slug = request.GET.get('slug', None)
        id_multiplan = request.GET.get('id_multiplan', None)
        id_multiplan = int(id_multiplan) if id_multiplan else None
        from_id = request.GET.get('ultimo_id', None)
        dados = {'error': None, 'error_message': None}
        if not slug and not id_multiplan:
            dados.update({'error': 'Shopping não informado',
                          'error_message': 'Favor informe a slug do shopping ou id do shopping na '
                                           'Multiplan'})
        elif id_multiplan or slug:
            usuario = kwargs.get('usuario', None)
            ApiLog.cria_log(kwargs['sessao'], u'%s listou ofertas' % usuario, ApiLog.CONSUMO)

            ids_do_usuario = [int(s.id_multiplan) for s in usuario.shopping.all()]
            slugs_do_usuario = [s.slug for s in usuario.shopping.all()]
            tem_acesso = True

            if id_multiplan and id_multiplan not in ids_do_usuario:
                tem_acesso = False
            if slug and slug not in slugs_do_usuario:
                tem_acesso = False

            if not tem_acesso:
                dados.update({'error': 'Sem acesso ao shopping',
                              'error_message': 'Sua perfil não tem acesso a dados desse shopping'})

                return retorno(dados, tipo)
        if id_multiplan:
            if from_id:
                ofertas, ultimo_id = Oferta.prontos_api(id_multiplan=id_multiplan,from_id=from_id)
            else:
                ofertas, ultimo_id = Oferta.prontos_api(id_multiplan=id_multiplan)
        elif slug:
            shopping = Shopping.objects.get(slug=slug)
            ofertas, ultimo_id = Oferta.prontos_api(id_multiplan=shopping.id_multiplan)
        else:
            ofertas = ultimo_id = None

        dados.update({'ofertas': ofertas, 'ultimo_id': ultimo_id})
    return retorno(dados, tipo)
Exemple #3
0
def itens_com_mais(request, shopping_id, acao, tipo):
    inicio_str = inicio = fim_str = fim = None
    if request.method == "POST":
        inicio_str = request.POST.get('inicio', None)
        inicio = datetime.strptime(inicio_str, '%d/%m/%Y')
        fim_str = request.POST.get('fim', None)
        fim = datetime.strptime(fim_str, '%d/%m/%Y')

    if inicio and fim:
        query_filtro = Oferta.relatorio_filtrado(shopping_id, acao, tipo, inicio, fim)

        filtradas, total_filtradas = listas_e_totais(query_filtro, 'vistas')
        contexto = {'tipo': Oferta.TIPOS[tipo][1], 'nome_shopping': Shopping.objects.get(id=shopping_id).nome,
                    'filtradas': filtradas, 'total_filtradas': total_filtradas,
                    'inicio': inicio_str, 'fim': fim_str}
    else:
        contexto = Oferta.itens_mais(shopping_id, acao, tipo)

    return contexto
Exemple #4
0
def contexto_home(destaques, eventos, ofertas, mais_paginas, shopping, com_filtro=False):
    trinta = tem_trinta = tem_cinq = cinquenta = tem_setenta = setenta \
    = preco1 = tem_preco1 = preco2 = tem_preco2 = preco3 = tem_preco3 = preco4 \
        = tem_preco4 = preco5 = tem_preco5 = False
    generos = []

    if com_filtro:
        destaques_x = Oferta.prontos(tipo=Oferta.DESTAQUE, shopping=shopping.id)
        eventos_x = Oferta.prontos(tipo=Oferta.EVENTO, shopping=shopping.id)
        ofertas_x = Oferta.prontos(shopping=shopping.id)
        ofertas_x = ofertas_x[:slice_oferta(len(destaques_x), len(eventos_x))]
    else:
        destaques_x = destaques
        eventos_x = eventos
        ofertas_x = ofertas

    lojas_dict = {}
    for i in Oferta.itens_por_shopping(shopping=shopping.id):
        #Condição antiga. **Fabiano Miranda**
        #if i.genero and Oferta.GENEROS[i.genero][1].lower() not in generos: 
        if Oferta.GENEROS[i.genero][1].lower() not in generos:
            generos.append(Oferta.GENEROS[i.genero][1])
        desconto = int(i.desconto) if i.desconto else None
        if desconto:
            if not tem_trinta and desconto <= 30:
                trinta = tem_trinta = True
            if not tem_cinq and desconto > 30 and desconto <= 50:
                cinquenta = tem_cinq = True
            if not tem_setenta and desconto > 50:
                setenta = tem_setenta = True

        preco = int(i.preco_final) if i.preco_final else None
        if preco:
            if not tem_preco1 and preco <= 30:
                preco1 = tem_preco1 = True
            if not tem_preco2 and preco > 30 and preco <= 50:
                preco2 = tem_preco2 = True
            if not tem_preco3 and preco > 50 and preco <= 100:
                preco3 = tem_preco3 = True
            if not tem_preco4 and preco > 100 and preco <= 300:
                preco4 = tem_preco4 = True
            if not tem_preco5 and preco > 300:
                preco5 = tem_preco5 = True
        if i.loja:
            lojas_dict[i.loja.slug] = i.loja.nome
    #for i in destaques_x+eventos_x+ofertas_x:
    #    if i.get('genero', None) and i['genero'].lower() not in generos:
    #        generos.append(i['genero'])
    #    desconto = int(i['desconto']) if i.get('desconto', None) else None
    #    if desconto:
    #        if not tem_trinta and desconto <= 30:
    #            trinta = tem_trinta = True
    #        if not tem_cinq and desconto > 30 and desconto <= 50:
    #            cinquenta = tem_cinq = True
    #        if not tem_setenta and desconto > 50:
    #            setenta = tem_setenta = True
    #    if i.get('loja', None):
    #        lojas_dict[i['loja']['slug']] = i['loja']['nome'] 
    #    preco = int(i['preco_final']) if i.get('preco_final', None) else None
    #    if preco:
    #        if not tem_preco1 and preco <= 30:
    #            preco1 = tem_preco1 = True
    #        if not tem_preco2 and preco > 30 and preco <= 50:
    #            preco2 = tem_preco2 = True
    #        if not tem_preco3 and preco > 50 and preco <= 100:
    #            preco3 = tem_preco3 = True
    #        if not tem_preco4 and preco > 100 and preco <= 300:
    #            preco4 = tem_preco4 = True
    #        if not tem_preco5 and preco > 300:
    #            preco5 = tem_preco5 = True

    return {'destaques': destaques,
            'ultimo_destaque_id': [int(d['id']) for d in destaques],
            'eventos': eventos,
            'ultimo_evento_id': [int(e['id']) for e in eventos],
            'ofertas': ofertas,
            'ultima_oferta_id': [int(o['id']) for o in ofertas],
            'categorias': Categoria.publicadas_com_oferta(shopping.id),
            'mais_paginas': mais_paginas,
            #'lojas': Loja.publicadas_com_oferta(shopping=shopping.id),
            'lojas_dict': OrderedDict(sorted(lojas_dict.items(), key=lambda n: n[1])),
            'lojas_splash': Loja.publicadas_sem_oferta(shopping=shopping.id),
            'sazonal': Sazonal.atual(shopping=shopping.id),
            'shopping_id': shopping.id,
            'shopping_slug': shopping.slug,
            'shopping_nome': shopping.nome,
            'generos': set(generos),
            'trinta': trinta,
            'cinquenta': cinquenta,
            'setenta': setenta,
            'preco1': preco1,
            'preco2': preco2,
            'preco3': preco3,
            'preco4': preco4,
            'preco5': preco5}
Exemple #5
0
def ofertas(request, *args, **kwargs):
    tipo = request.GET.get('type', None)
    if request.method != 'GET':
        dados = {
            'error': u'Método inválido',
            'error_message': u'Método não permitido nesse serviço'
        }
    else:
        slug = request.GET.get('slug', None)
        id_multiplan = request.GET.get('id_multiplan', None)
        id_multiplan = int(id_multiplan) if id_multiplan else None
        from_id = request.GET.get('ultimo_id', None)
        dados = {'error': None, 'error_message': None}
        if not slug and not id_multiplan:
            dados.update({
                'error':
                'Shopping não informado',
                'error_message':
                'Favor informe a slug do shopping ou id do shopping na '
                'Multiplan'
            })
        elif id_multiplan or slug:
            usuario = kwargs.get('usuario', None)
            ApiLog.cria_log(kwargs['sessao'], u'%s listou ofertas' % usuario,
                            ApiLog.CONSUMO)

            ids_do_usuario = [
                int(s.id_multiplan) for s in usuario.shopping.all()
            ]
            slugs_do_usuario = [s.slug for s in usuario.shopping.all()]
            tem_acesso = True

            if id_multiplan and id_multiplan not in ids_do_usuario:
                tem_acesso = False
            if slug and slug not in slugs_do_usuario:
                tem_acesso = False

            if not tem_acesso:
                dados.update({
                    'error':
                    'Sem acesso ao shopping',
                    'error_message':
                    'Sua perfil não tem acesso a dados desse shopping'
                })

                return retorno(dados, tipo)
        if id_multiplan:
            if from_id:
                ofertas, ultimo_id = Oferta.prontos_api(
                    id_multiplan=id_multiplan, from_id=from_id)
            else:
                ofertas, ultimo_id = Oferta.prontos_api(
                    id_multiplan=id_multiplan)
        elif slug:
            shopping = Shopping.objects.get(slug=slug)
            ofertas, ultimo_id = Oferta.prontos_api(
                id_multiplan=shopping.id_multiplan)
        else:
            ofertas = ultimo_id = None

        dados.update({'ofertas': ofertas, 'ultimo_id': ultimo_id})
    return retorno(dados, tipo)