示例#1
0
文件: views.py 项目: durm/aksvrnru
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"Только персонал может загрузить и распарсить прайс!")
示例#2
0
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))
示例#3
0
文件: views.py 项目: durm/aksvrnru
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))
示例#4
0
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"")
示例#5
0
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))
示例#6
0
def render_product(request, product):
    return render_to_response("products/product.html", {'product': product},
                              get_context(request))
示例#7
0
def bookcall(request):
    return render_to_response("userprofile/bookcall.html",
                              get_context(request))
示例#8
0
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'))
示例#9
0
文件: views.py 项目: durm/aksvrnru
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))
示例#10
0
文件: views.py 项目: durm/aksvrnru
def render_page(request, page):
    return render_to_response("pages/page.html", {'page':page}, get_context(request))
示例#11
0
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))
示例#12
0
文件: views.py 项目: durm/aksvrnru
def render_product(request, product):
    return render_to_response("products/product.html", {'product':product}, get_context(request))
示例#13
0
文件: views.py 项目: durm/aksvrnru
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))
示例#14
0
文件: views.py 项目: durm/aksvrnru
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'))
示例#15
0
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))
示例#16
0
文件: views.py 项目: durm/aksvrnru
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))
示例#17
0
文件: views.py 项目: durm/aksvrnru
def me(request):
    if request.user.is_authenticated() :
        return render_to_response("userprofile/me.html", get_context(request))
    else:
        return redirect(reverse('login_page'))
示例#18
0
文件: views.py 项目: durm/aksvrnru
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))
示例#19
0
文件: views.py 项目: durm/aksvrnru
def feedback(request):
    return render_to_response("userprofile/feedback.html", get_context(request))
示例#20
0
文件: views.py 项目: durm/aksvrnru
def bookcall(request):
    return render_to_response("userprofile/bookcall.html", get_context(request))
示例#21
0
文件: views.py 项目: durm/aksvrnru
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"Только персонал может загрузить и распарсить прайс!")
示例#22
0
def feedback(request):
    return render_to_response("userprofile/feedback.html",
                              get_context(request))
示例#23
0
文件: views.py 项目: durm/aksvrnru
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"")
示例#24
0
文件: views.py 项目: durm/aksvrnru
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))
示例#25
0
def me(request):
    if request.user.is_authenticated():
        return render_to_response("userprofile/me.html", get_context(request))
    else:
        return redirect(reverse('login_page'))
示例#26
0
文件: views.py 项目: durm/aksvrnru
def render_page(request, page):
    return render_to_response("pages/page.html", {'page': page},
                              get_context(request))