예제 #1
0
def valorar(request):
    context = RequestContext(request)
    valor= None
    if not request.user.is_authenticated():
        print("hola")
    else:
        if request.method == 'POST':
            librete = Libro.objects.get(id=request.POST['id'])
            val=Valoracion()
            val.nombre=request.POST['nombre']
            val.valoracion=request.POST['valoracion']
            val.pub=request.POST['pub']
            val.published_in=librete
            val.save()
            valor=Valoracion.objects.filter(published_in=librete).order_by('-fecha')
        return render_to_response('opinion.html',
                                    {'valor':valor},
                                    context)
예제 #2
0
def libroT(request, libId):
    context = RequestContext(request)
    librete = Libro.objects.get(id=libId)

    if request.method == 'POST':
        val=Valoracion()
        val.nombre=request.POST['nombre']
        val.valoracion=request.POST['valoracion']
        val.pub=request.POST['pub']
        val.published_in=librete
        val.save()

    res=Valoracion.objects.filter(published_in=librete).order_by('-fecha')
    avgEs=res.aggregate(Avg('valoracion'))['valoracion__avg']
    print(avgEs)
    if avgEs!=None:
        librete.punt_media=avgEs
        librete.save()

    return render_to_response('libro.html',
                                  {'libroI':librete,
                                   'valor':res,
                                  'avgEs':avgEs},
                                  context)