Esempio n. 1
0
def product_details(request, product_id):
    product = Product.objects.get(pk=product_id)
    
    form = DateRangeForm(request.GET)
    if not form.is_valid():
        form = DateRangeForm()
        start_date = form.fields['start_date'].initial
        end_date = form.fields['end_date'].initial
    else:
        start_date = form.cleaned_data['start_date']
        end_date = form.cleaned_data['end_date']
        if end_date > date.today():
            end_date = date.today()
        if start_date >= end_date:
            url = reverse('solonotebooks.cotizador.views_services.product_details', args = [product.id])
            return HttpResponseRedirect(url)
    
    # First chart

    raw_data = ProductVisit.objects.filter(notebook = product, date__gte = start_date, date__lt = end_date + timedelta(days = 1)).extra(select = {'d': 'CAST(date AS DATE)'}).values('d').annotate(Count('id')).order_by('d')
    chart_data = [(entry['d'], entry['id__count']) for entry in raw_data]

    product_visit_count = sum([e[1] for e in chart_data])

    generate_timelapse_chart([chart_data], start_date, end_date, [u'Número de visitas'], 'services_product_' + str(product.id) + '_01.png', u'Número de visitas al producto en SoloTodo')
    
    # Second chart
    
    raw_data = ExternalVisit.objects.filter(shn__shp__product = product, date__gte = start_date, date__lt = end_date + timedelta(days = 1)).values('date').annotate(Count('id')).order_by('date')
    chart_data = [(entry['date'], entry['id__count']) for entry in raw_data]
    
    all_external_visit_count = sum([e[1] for e in chart_data])
    
    generate_timelapse_chart([chart_data], start_date, end_date, ['Clicks totales a tiendas'], 'services_product_' + str(product.id) + '_02.png', u'Número de clicks a tiendas')
    
    # Third chart
    
    raw_data = ExternalVisit.objects.filter(shn__shp__product = product, date__gte = start_date, date__lt = end_date + timedelta(days = 1)).values('shn__store').annotate(Count('id'))
    
    chart_data = [(unicode(Store.objects.get(pk = pair['shn__store'])), pair['id__count']) for pair in raw_data]
    store_distribution_data = chart_data
    
    generated_pie_chart = generate_pie_chart(chart_data, 'services_product_' + str(product.id) + '_03.png', u'Distribución de clicks entre tiendas')
    
    return append_metadata_to_response(request, 'services/product_details.html', {
        'product': product,
        'form': form,
        'tag': random.randint(1, 1000000),
        'product_prices': product.storehasproduct_set.filter(shpe__isnull = False).order_by('shpe__latest_price'),
        'product_visit_count': product_visit_count,
        'all_external_visit_count': all_external_visit_count,
        'generated_pie_chart': generated_pie_chart,
        'store_distribution_data': store_distribution_data,
    })
Esempio n. 2
0
def append_store_metadata_to_response(request, template, args):
    tabs = [
            u'Opciones',
            [
                    ['Registro', reverse('solonotebooks.cotizador.views_store.registry')],
                    ['Estadísticas', reverse('solonotebooks.cotizador.views_store.statistics')],
                    ['Resultados patrocinados', reverse('solonotebooks.cotizador.views_store.sponsored_results')],
                    ['Publicidad', reverse('solonotebooks.cotizador.views_store.advertisement_results')]
            ]
        ]

    args['tabs'] = tabs
    args['store'] = request.user.get_profile().assigned_store
    return append_metadata_to_response(request, template, args)
Esempio n. 3
0
def login(request):
    next_url = '/'
    if 'next' in request.GET:
        next_url = request.GET['next']
        
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = auth.authenticate(username = username, password = password)
        
        if user is not None:
            auth.login(request, user)
        else:
            request.flash['error'] = 'Nombre de usuario o contraseña incorrectos'
            return HttpResponseRedirect('/account/login/?next=%s' % urlquote(next_url))
    
    if request.user.is_authenticated():
        return HttpResponseRedirect(next_url)
    else:
        return append_metadata_to_response(request, 'account/login.html', {
            })
Esempio n. 4
0
def append_account_ptype_to_response(request, template, args):
    tabs = []
    
    name = 'Mis productos'
    url = reverse('solonotebooks.cotizador.views_account.subscriptions')
    tabs.append([-1, name, url])
    
    if request.user.is_authenticated() and not request.user.get_profile().facebook_name:
        name = 'Cambiar correo electrónico'
        url = reverse('solonotebooks.cotizador.views_account.change_email')
        tabs.append([-1, name, url])
        
        name = u'Cambiar contraseña'
        url = reverse('solonotebooks.cotizador.views_account.change_password')
        tabs.append([-1, name, url])
        
        name = 'Fusionar con Facebook'
        url = reverse('solonotebooks.cotizador.views_account.fuse_facebook_account')
        tabs.append([-1, name, url])
    
    args['tabs'] = ['', tabs]
    return append_metadata_to_response(request, template, args)
Esempio n. 5
0
def login(request):
    next_url = '/'
    if 'next' in request.GET:
        next_url = request.GET['next']

    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = auth.authenticate(username=username, password=password)

        if user is not None:
            auth.login(request, user)
        else:
            request.flash[
                'error'] = 'Nombre de usuario o contraseña incorrectos'
            return HttpResponseRedirect('/account/login/?next=%s' %
                                        urlquote(next_url))

    if request.user.is_authenticated():
        return HttpResponseRedirect(next_url)
    else:
        return append_metadata_to_response(request, 'account/login.html', {})
Esempio n. 6
0
def append_store_metadata_to_response(request, template, args):
    tabs = [
        u'Opciones',
        [['Registro',
          reverse('solonotebooks.cotizador.views_store.registry')],
         [
             'Estadísticas',
             reverse('solonotebooks.cotizador.views_store.statistics')
         ],
         [
             'Resultados patrocinados',
             reverse('solonotebooks.cotizador.views_store.sponsored_results')
         ],
         [
             'Publicidad',
             reverse(
                 'solonotebooks.cotizador.views_store.advertisement_results')
         ]]
    ]

    args['tabs'] = tabs
    args['store'] = request.user.get_profile().assigned_store
    return append_metadata_to_response(request, template, args)
Esempio n. 7
0
def append_account_ptype_to_response(request, template, args):
    tabs = []

    name = 'Mis productos'
    url = reverse('solonotebooks.cotizador.views_account.subscriptions')
    tabs.append([-1, name, url])

    if request.user.is_authenticated(
    ) and not request.user.get_profile().facebook_name:
        name = 'Cambiar correo electrónico'
        url = reverse('solonotebooks.cotizador.views_account.change_email')
        tabs.append([-1, name, url])

        name = u'Cambiar contraseña'
        url = reverse('solonotebooks.cotizador.views_account.change_password')
        tabs.append([-1, name, url])

        name = 'Fusionar con Facebook'
        url = reverse(
            'solonotebooks.cotizador.views_account.fuse_facebook_account')
        tabs.append([-1, name, url])

    args['tabs'] = ['', tabs]
    return append_metadata_to_response(request, template, args)