Ejemplo n.º 1
0
def questanswer(request, page=None):
    context = RequestContext(request)
    context['title'] = u'Вопрос-ответ'
    if request.method == 'POST':
        context['author_error'] = False
        context['mes_error'] = False

        if not request.POST.get('q_autor', ''):
            context['author_error'] = True
        else:
            context['q_autor'] = request.POST['q_autor']
        
        if not request.POST.get('q_mes', ''):
            context['mes_error'] = True
        else:
            context['q_mes'] = request.POST['q_mes']
        
        if context['author_error'] or context['mes_error']:
            pass
        else:
            qa = QuestAnswer(author = context['q_autor'], question = context['q_mes'])
            qa.save()
            context['ok'] = True
    context['unanswered'] = QuestAnswer.objects.order_by('-date_publication').filter(is_public=False)
    context['tags'] = TagName.objects.all()
    context['alphabet'] = Alphabet.objects.filter(is_action=True).order_by('letter')
    paginate(
        context, 'questanswer', 
        QuestAnswer.objects.order_by('-date_publication').filter(is_public=True),
        count=QA_ON_PAGE, page=page, 
        root=context['current_section'].path
    )
    return render_to_response('qa/questanswer.html', context)
Ejemplo n.º 2
0
def catalog_item(request, slug):
    context = get_default_context(request)
    product = get_object_or_404(Product, slug=slug)
    context['catalog'] = product.catalog
    context['catalog_properties'] = context['catalog'].properties.all()
    
    for size in product.pricing_set.all():
        if size.is_exist:
            context['size_is_exist'] = size.size_id
            break
    
    for p in context['catalog_properties']:
        if p.type == 4:
            fv = request.GET.getlist(p.slug)
            if fv is not None:
                p.filtered_values = fv
        else:
            fv = request.GET.get(p.slug)
            if fv is not None:
                p.filtered_value = fv

    context['catalog_position'] = product
    context['catalog_position_wtp'] = product.wtp.all()
    context['catalog_position_pricing'] = Pricing.objects.filter(product=product).order_by('size')
    context['catalog_position_images'] = product.picture_set.all()
    context['properties'] = get_extended_properties(product)
    context['crumbs'].append({ 
      'caption': product.name, 
      'path': context['current_section'].path + product.slug + '/'
    })
    basket = Basket(request.session)
    context['order_count'] = basket.get_count(product.id)
    
    #title
    if not Metatag.objects.filter(name=context['current_section'].path + product.slug + '/') \
        and product.catalog_id == 10: #пока что только для каталога Обувь
        if not ChangeTitle.objects.filter(path=context['current_section'].path + product.slug + '/'):            
            word_1 = Title.objects.filter(position=1).order_by('?')[0].title
            while True:
                word_2 = Title.objects.filter(position=2).order_by('?')[0].title
                if word_2.lower() != word_1.lower():
                    break
            while True:
                word_3 = Title.objects.filter(position=3).order_by('?')[0].title
                if word_3.lower() != word_1.lower() and word_3.lower() != word_2.lower():
                    break
            while True:
                word_4 = Title.objects.filter(position=4).order_by('?')[0].title
                if word_4.lower() != word_1.lower() and word_4.lower() != word_2.lower() and word_4.lower() != word_3.lower():
                    break
            title = ChangeTitle(path=context['current_section'].path + product.slug + '/', title='%s %s %s %s %s' % (word_1, word_2, context['catalog_position'].name, word_3, word_4))
            title.save()
            context['catalog_position'].title = '%s %s %s %s %s' % (word_1, word_2, context['catalog_position'].name, word_3, word_4)
        else:
            context['catalog_position'].title = ChangeTitle.objects.filter(path=context['current_section'].path + product.slug + '/')[0].title
    #title
    if request.method == 'POST':
        context['author_error'] = False
        context['mes_error'] = False

        if not request.POST.get('q_autor', ''):
            context['author_error'] = True
        else:
            context['q_autor'] = request.POST['q_autor']
        
        if not request.POST.get('q_mes', ''):
            context['mes_error'] = True
        else:
            context['q_mes'] = request.POST['q_mes']
        
        if context['author_error'] or context['mes_error']:
            pass
        else:
            qa = QuestAnswer(author = context['q_autor'], question = context['q_mes'])
#            send_mail(context['q_autor'], context['q_mes'])
            qa.save()
            qa.product_set.add(product)
            context['ok'] = True
    context['unanswered'] = product.qa.order_by('-date_publication').filter(is_public=False)
    context['questanswer'] = product.qa.order_by('-date_publication').filter(is_public=True)
    if 'ajax' in request.GET:
        return render_to_response('catalog/position_ajax.html', context)
    else:
        return render_to_response('catalog/position.html', context)