def upload_price(request): if request.user.is_authenticated() and request.user.is_staff: return render_to_response("pricelog/upload_price.html", {}, get_context(request)) else: return error(request, u"Ошибка доступа", u"Только персонал может загрузить и распарсить прайс!")
def login_page(request): if request.user.is_authenticated(): return error( request, u"Ошибка", u"Пользователь авторизован как %s." % str(request.user.username)) else: return render_to_response("userprofile/login_page.html", context_instance=get_context(request))
def home(request): special_price_products = None #Product.subset_of_special_price() req = { "special_price_products": special_price_products } #return render("1") return render_to_response("common/landing.html", req, get_context(request))
def rubrics_hierarchy(request, choose=False, tpl='products/hierarchy.html', is_published=True): rubrics = Rubric.objects.filter(parent__isnull=True, is_published=True) if rubrics.count(): return render_to_response(tpl, { "rubrics": rubrics, "choose": choose, "sale_rate": None }, get_context(request)) else: return message(request, u"Нет активных рубрик!", u"")
def rubricator(request): rubric_id = request.GET.get("rubric", None) rubric = None rubrics = Rubric.get_published_rubrics().filter(parent=None) if rubric_id is not None: try: rubric = Rubric.objects.get(id=rubric_id) except Rubric.DoesNotExist: return error(request, u"Нет рубрики с таким идентификатором!", u"") rubricator_path = [] parents_id = [] rubrics_view = rubrics products = Product.get_published_products() products_count = products.count() if rubric is not None: rubricator_path = rubric.rubricator_path() parents_id = map(lambda r: r.id, rubricator_path) all_children = rubric.get_all_published_children() products = products.filter( Q(rubrics__in=all_children) | Q(rubrics__in=[rubric])) rubrics_view = all_children if len(rubrics_view): products = products.order_by("?")[:21] else: products_count = products.count() paginator = Paginator(products, 21) page = request.GET.get('page') try: products = paginator.page(page) except PageNotAnInteger: products = paginator.page(1) except EmptyPage: products = paginator.page(paginator.num_pages) else: products = products.order_by("?")[:21] return render_to_response( "rubrics/rubrics.html", { 'main': rubric, 'products': products, 'products_count': products_count, 'rubrics_view': rubrics_view, 'rubrics': rubrics, 'parents_id': parents_id, 'rubricator_path': rubricator_path }, get_context(request))
def render_product(request, product): return render_to_response("products/product.html", {'product': product}, get_context(request))
def bookcall(request): return render_to_response("userprofile/bookcall.html", get_context(request))
def edit_profile_view(request): if request.user.is_authenticated(): return render_to_response("userprofile/edit_profile.html", context_instance=get_context(request)) else: return redirect(reverse('login_page'))
def rubricator(request): rubric_id = request.GET.get("rubric", None) rubric = None rubrics = Rubric.get_published_rubrics().filter(parent=None) if rubric_id is not None : try: rubric = Rubric.objects.get(id=rubric_id) except Rubric.DoesNotExist : return error(request, u"Нет рубрики с таким идентификатором!", u"") rubricator_path = [] parents_id = [] rubrics_view = rubrics products = Product.get_published_products() products_count = products.count() if rubric is not None : rubricator_path = rubric.rubricator_path() parents_id = map(lambda r: r.id, rubricator_path) all_children = rubric.get_all_published_children() products = products.filter(Q(rubrics__in=all_children)|Q(rubrics__in=[rubric])) rubrics_view = all_children if len(rubrics_view) : products = products.order_by("?")[:21] else: products_count = products.count() paginator = Paginator(products, 21) page = request.GET.get('page') try: products = paginator.page(page) except PageNotAnInteger: products = paginator.page(1) except EmptyPage: products = paginator.page(paginator.num_pages) else: products = products.order_by("?")[:21] return render_to_response("rubrics/rubrics.html", {'main': rubric, 'products':products, 'products_count':products_count, 'rubrics_view':rubrics_view, 'rubrics':rubrics, 'parents_id':parents_id, 'rubricator_path':rubricator_path}, get_context(request))
def render_page(request, page): return render_to_response("pages/page.html", {'page':page}, get_context(request))
def signup_view(request): if request.user.is_authenticated(): return redirect(reverse('me')) else: return render_to_response("userprofile/signup.html", context_instance=get_context(request))
def render_product(request, product): return render_to_response("products/product.html", {'product':product}, get_context(request))
def listing(request): vendors = Vendor.objects.all() rubrics = Rubric.get_published_rubrics() q_filter = request.GET.get("q", "") price_from_filter = proc_price_param(request.GET.get("price_from", "")) price_to_filter = proc_price_param(request.GET.get("price_to", "")) available_filter = request.GET.get("a", "") == "1" vendor_filter = request.GET.getlist("vendor", None) rubric_filter = request.GET.getlist("rubric", None) products = Product.objects.filter(is_published=True) if price_from_filter : products = products.filter(retail_price__gt=price_from_filter) if price_to_filter : products = products.filter(retail_price__lt=price_to_filter) if q_filter : products = products.filter(Q(short_desc__icontains=q_filter)|Q(name__icontains=q_filter)|Q(desc__icontains=q_filter)|Q(vendor__name__icontains=q_filter)) if available_filter : products = products.filter(available_for_retail=available_filter) if vendor_filter : products = products.filter(vendor__in=vendor_filter) if rubric_filter : rubrics_id = [] rubrics_id += rubric_filter rubrics = Rubric.objects.filter(id__in=rubric_filter) for rubric in rubrics : get_children_ids(rubrics_id, rubric) products = products.filter(rubrics__in=rubrics_id) order_by = request.REQUEST.get("order_by", "") direction = request.REQUEST.get("direction", "") direction = "-" if direction == "-" else "" if order_by in ["vendor__name", "id", "retail_price"] : products = products.order_by(direction + order_by) else: order_by = None products_count = products.count() paginator = Paginator(products, 25) page = request.GET.get('page') try: products = paginator.page(page) except PageNotAnInteger: products = paginator.page(1) except EmptyPage: products = paginator.page(paginator.num_pages) qparams = { 'q_filter':q_filter, 'vendor_filter': map(id_to_int, vendor_filter), 'rubric_filter': map(id_to_int, rubric_filter), 'price_from_filter':price_from_filter, 'price_to_filter':price_to_filter, 'available_filter':available_filter } qd = request.GET.copy() if "page" in qd : qd.pop('page') if "order_by" in qd : qd.pop('order_by') req = { "products": products, "direction":direction, "order_by": order_by, "qparams":qparams, "qparams_str":qd.urlencode(), "product_count":products_count, "vendors": vendors, "rubrics": rubrics } return render_to_response('products/list.html', req, get_context(request))
def edit_profile_view(request): if request.user.is_authenticated() : return render_to_response("userprofile/edit_profile.html", context_instance=get_context(request)) else: return redirect(reverse('login_page'))
def listing(request): vendors = Vendor.objects.all() rubrics = Rubric.get_published_rubrics() q_filter = request.GET.get("q", "") price_from_filter = proc_price_param(request.GET.get("price_from", "")) price_to_filter = proc_price_param(request.GET.get("price_to", "")) available_filter = request.GET.get("a", "") == "1" vendor_filter = request.GET.getlist("vendor", None) rubric_filter = request.GET.getlist("rubric", None) products = Product.objects.filter(is_published=True) if price_from_filter: products = products.filter(retail_price__gt=price_from_filter) if price_to_filter: products = products.filter(retail_price__lt=price_to_filter) if q_filter: products = products.filter( Q(short_desc__icontains=q_filter) | Q(name__icontains=q_filter) | Q(desc__icontains=q_filter) | Q(vendor__name__icontains=q_filter)) if available_filter: products = products.filter(available_for_retail=available_filter) if vendor_filter: products = products.filter(vendor__in=vendor_filter) if rubric_filter: rubrics_id = [] rubrics_id += rubric_filter rubrics = Rubric.objects.filter(id__in=rubric_filter) for rubric in rubrics: get_children_ids(rubrics_id, rubric) products = products.filter(rubrics__in=rubrics_id) order_by = request.REQUEST.get("order_by", "") direction = request.REQUEST.get("direction", "") direction = "-" if direction == "-" else "" if order_by in ["vendor__name", "id", "retail_price"]: products = products.order_by(direction + order_by) else: order_by = None products_count = products.count() paginator = Paginator(products, 25) page = request.GET.get('page') try: products = paginator.page(page) except PageNotAnInteger: products = paginator.page(1) except EmptyPage: products = paginator.page(paginator.num_pages) qparams = { 'q_filter': q_filter, 'vendor_filter': map(id_to_int, vendor_filter), 'rubric_filter': map(id_to_int, rubric_filter), 'price_from_filter': price_from_filter, 'price_to_filter': price_to_filter, 'available_filter': available_filter } qd = request.GET.copy() if "page" in qd: qd.pop('page') if "order_by" in qd: qd.pop('order_by') req = { "products": products, "direction": direction, "order_by": order_by, "qparams": qparams, "qparams_str": qd.urlencode(), "product_count": products_count, "vendors": vendors, "rubrics": rubrics } return render_to_response('products/list.html', req, get_context(request))
def signup_view(request): if request.user.is_authenticated() : return redirect(reverse('me')) else: return render_to_response("userprofile/signup.html", context_instance = get_context(request))
def me(request): if request.user.is_authenticated() : return render_to_response("userprofile/me.html", get_context(request)) else: return redirect(reverse('login_page'))
def login_page(request): if request.user.is_authenticated() : return error(request, u"Ошибка", u"Пользователь авторизован как %s." % str(request.user.username)) else: return render_to_response("userprofile/login_page.html", context_instance = get_context(request))
def feedback(request): return render_to_response("userprofile/feedback.html", get_context(request))
def upload_price(request): if request.user.is_authenticated() and request.user.is_staff : return render_to_response("pricelog/upload_price.html", {}, get_context(request)) else: return error(request, u"Ошибка доступа", u"Только персонал может загрузить и распарсить прайс!")
def rubrics_hierarchy(request, choose=False, tpl='products/hierarchy.html', is_published=True): rubrics = Rubric.objects.filter(parent__isnull=True, is_published=True) if rubrics.count() : return render_to_response(tpl, {"rubrics":rubrics, "choose":choose, "sale_rate": None}, get_context(request)) else: return message(request, u"Нет активных рубрик!", u"")
def home(request): special_price_products = None #Product.subset_of_special_price() req = {"special_price_products": special_price_products} #return render("1") return render_to_response("common/landing.html", req, get_context(request))
def me(request): if request.user.is_authenticated(): return render_to_response("userprofile/me.html", get_context(request)) else: return redirect(reverse('login_page'))
def render_page(request, page): return render_to_response("pages/page.html", {'page': page}, get_context(request))