예제 #1
0
파일: views.py 프로젝트: qxs820624/django
def product_list(request):
    """product catagroy and search"""
    #url = request.path
    # method = request.method
    group = get_user_group(request)
    if request.method =='POST':
        query_str = request.POST.get('query_product',None)
        if query_str:
            products_list = Product.objects.filter(name__icontains = query_str)
            if not products_list:
                result = {'result':-1}
            else:
                products_list = products_list[0].name
                result={'result':products_list}
            #return render(request,'products/product_list.html',{ 'result':result})
            return JsonResponse(result,safe=False)
        #the query string in blank
        else:
            return render(request,'products/product_list.html',{'error':'you must enter something to forward',})
        return render(request,'products/product_list.html',
                      {'products_list':products_list,
                       'group':group,
                       })
    else:
        query_product = Product.objects.all()
        logger.info('find products {} '.format(list(query_product)))
        return render(request,'products/product_list.html',{
            'product_list':query_product,
            'group':group,
        })
예제 #2
0
def upload(request):
    group = get_user_group(request)
    user = request.user
    return render(request, 'cdyd.html', {
        'group': group,
        'user': user,
        'sheets': None
    })
    if request.method == "POST":
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            filehandle = request.FILES['file']
            return excel.make_response(filehandle.get_sheet(),
                                       "csv",
                                       file_name="download")
    else:
        form = UploadFileForm()
    return render(
        request, 'upload_form.html', {
            'form':
            form,
            'title':
            'Excel file upload and download example',
            'header':
            ('Please choose any excel file ' + 'from your cloned repository:')
        })
예제 #3
0
파일: views.py 프로젝트: qxs820624/django
 def get(self,request,*args,**kwargs):
     product_arg = args[0]
     try:
         product = Product.objects.filter(name=product_arg)[0]
         kwargs['product'] = product
     except:
         return render(request,'404.html',{})
     group = get_user_group(request)
     kwargs['group'] = group
     return super(ProductDetail,self).get(request,*args,**kwargs)
예제 #4
0
파일: client.py 프로젝트: qxs820624/django
def ClientConsole(request):
    """client console"""
    group = get_user_group(request)
    user = request.user
    orders, servers, tickets, reviews = get_order_information(user, group)
    return render(
        request, 'panel/console.html', {
            'group': group,
            'orders': orders,
            'servers': servers,
            'tickets': tickets,
            'reviews': reviews,
        })
예제 #5
0
 def custom_queryset(cls, request, **kwargs):
     """Define your own custom queryset for list view"""
     user = request.user
     # p = user.get_all_permissions()
     # for pi in p:
     #     print(pi)
     group = get_user_group(request)
     if group.name == "Staff" or request.user.is_superuser:
         qset = cls.model.objects.all()
         return qset
     else:
         qset = cls.model.objects.filter(user_id=request.user)
         return qset
예제 #6
0
파일: views.py 프로젝트: qxs820624/django
 def get(self, request, *args, **kwargs):
     user = self.request.user
     kwargs['group'] = get_user_group(request)
     product = self.request.GET.get('p', None)
     if not product:
         messages.error(request, "The product required. "
                        "Please choice a product to order.",
                        extra_tags='danger')
         kwargs["order_form"] = OrderForm()
         return super(MakeOrder, self).get(request, *args, **kwargs)
     if "order_form" not in kwargs:
         kwargs["order_form"] = OrderForm()
         kwargs['p'] = product
     return super(MakeOrder, self).get(request, *args, **kwargs)
예제 #7
0
파일: views.py 프로젝트: qxs820624/django
 def post(self, request, *args, **kwargs):
     user = self.request.user
     kwargs['group'] = get_user_group(request)
     product = self.request.GET.get('p', None)
     print(product)
     # product not exists return
     if not product:
         messages.error(request, "The product required. "
                        "Please choice a product to order.",
                        extra_tags='danger')
         kwargs["order_form"] = OrderForm()
         return super(MakeOrder, self).get(request, *args, **kwargs)
     #valid form data
     order_form = OrderForm(request.POST)
     if not order_form.is_valid():
         order_form = OrderForm(request.POST)
         return super(MakeOrder, self).get(request,
                                           order_form=order_form,
                                           p=Product)
     #save form data to database
     memory = request.POST.get('memory', None)
     #print(request.POST)
     plan_id = request.POST.get('plan_id', None)
     plan = Plan.objects.get(id=plan_id)
     product_obj = Product.objects.get(name=product)
     name = user.name + '_' + product + '_' + datetime.datetime.now(
     ).strftime("%Y-%m-%d %H:%M:%S")
     try:
         Package(user_id=user,
                 product_id=product_obj,
                 plan_id=plan,
                 name=name,
                 memory=memory).save()
         messages.success(request, "The order is setup succussfully!")
     except:
         logger.info('{} order the {} failed!'.format(user.name, product))
         messages.error(request,
                        "The order failed please contact the support team!",
                        extra_tags='danger')
     return redirect("order:service")
예제 #8
0
def staff_order(request):
    """manage orders"""
    STATUS = {
        'All': '',
        'Pending': '',
        'Active': '',
        'Canceled': '',
        'Suspended': '',
        'Fraud': '',
    }
    group = get_user_group(request)
    if request.method == "GET":
        print(request.GET)
        p = Package.objects.all()
        q = request.GET.get('q', '')
        q_s = request.GET.get("s_value", '')
        STATUS[q_s] = 'selected'
        q_s_tuple = (
            "Pending",
            'Active',
            'Canceled',
            'Suspended',
            'Fraud',
        ) if q_s == "All" else (q_s, )
        p = p.filter(user_id__name__icontains=q).filter(status__in=q_s_tuple)
        table = PackageTable(p)
        return render(request, 'panel/stafforders.html', {
            'table': table,
            'group': group,
            'status': STATUS,
        })
    elif request.method == "POST":
        p = Package.objects.all()
        return render(request, 'panel/stafforders.html', {
            'orders': p,
            'group': group,
            'status': STATUS,
        })
예제 #9
0
def StaffConsole(request):
    """staff console"""
    group = get_user_group(request)
    user = request.user
    return render(request, 'panel/console.html', {'group': group})