Exemplo n.º 1
0
def detail(request, id):

    if request.method == 'POST':
        if request.method == "POST":
            form = CarSelectForm(request.POST)
            if form.is_valid():
                carSelected = form.cleaned_data['CarSelected']
                return http.HttpResponseRedirect('./' + str(carSelected) + '/')

    if request.method == 'POST':

        form = CommentForm(request.POST)
        if form.is_valid():
            # create a new item
            contact = Comment.objects.create(
                                       CAR= get_object_or_404(Car, pk=id),
				       NAME = form.cleaned_data['name'],
                                       COMMENT=form.cleaned_data['comment'],
                                       DATE = datetime.datetime.today()
                                       )
            return http.HttpResponseRedirect('./')

    p = get_object_or_404(Car, pk=id)
    car_list = Car.objects.filter(BODYTYPE=p.BODYTYPE).filter( HP__range = (p.HP-25,p.HP+25)).filter( DRIVETRAIN = p.DRIVETRAIN).filter( CURBWEIGHT__range = (p.CURBWEIGHT-500,p.CURBWEIGHT+500)).filter( MPG__range = (p.MPG-5,p.MPG+5)).exclude(id = p.id) #Ivan "Comparable Car" filter
    comments = Comment.objects.filter(CAR=p)
    commentBox = CommentForm(request.POST)
    
    full_stars = int(math.floor(p.RATING.get_rating())) * 2
    empty_stars = 10 - full_stars
    count = p.COUNT - 1
    context = Context({'car' : p, 'comment_list' : comments, 'form' : commentBox, 'car_list' : car_list, 'count':count, 'full_stars' : range(full_stars), 'empty_stars':range(empty_stars)})

    return render_to_response('cars/detail.html', context, context_instance=RequestContext(request))
Exemplo n.º 2
0
def gallery(request, id):

    if request.method == 'POST':
        if request.method == "POST":
            form = CarSelectForm(request.POST)
            if form.is_valid():
                carSelected = form.cleaned_data['CarSelected']
                return http.HttpResponseRedirect('./' + str(carSelected) + '/')

    p = get_object_or_404(Car, pk=id)
    car_list = Car.objects.filter(BODYTYPE=p.BODYTYPE).filter( HP__range = (p.HP-25,p.HP+25)).filter( DRIVETRAIN = p.DRIVETRAIN).filter( CURBWEIGHT__range = (p.CURBWEIGHT-500,p.CURBWEIGHT+500)).filter( MPG__range = (p.MPG-5,p.MPG+5)).exclude(id = p.id) #Ivan "Comparable Car" filter
    img = Images.objects.filter(CAR = id)
    count = p.COUNT - 1
    context = Context({'car' : p, 'car_list' : car_list, 'count' : count, 'img' : img})
    return render_to_response('cars/gallery.html', context, context_instance=RequestContext(request))