コード例 #1
0
def index(request):
    mobiles = Mobile.objects.all()
    context = {}
    context["mobiles"] = mobiles
    form = SearchForm()
    context["search"] = form
    if request.method == "POST":
        form = SearchForm(request.POST)
        if form.is_valid():
            brand = form.cleaned_data.get("Brand_name")
            products = Mobile.objects.filter(
                brand__brand_name=brand
            )  #brand is ForiegnKey which refers to 'Brand' model where 'brand_name' is there. So use 'brand__brand_name'
            context["mobiles"] = products
            return render(request, "product/index.html", context)
    return render(request, "product/index.html", context)
コード例 #2
0
ファイル: views.py プロジェクト: timur-ul-hasan/sensoi-api
def dashboard(request):
    global main_table_data
    sorted = False
    value = None
    is_old = 0
    data = Files_upload.objects.filter(
        user=request.user).order_by('name').all()

    if request.method == 'POST':
        is_old = 1
        form = SearchForm(request.POST or None)
        if form.is_valid():
            value = form.cleaned_data.get('search')
            data = data.filter(name__icontains=value)
    if request.GET.get('sorted'):
        # data = data.order_by('-date')
        sorted = True
    if request.session.get('folder', None) is not None:
        entries = alfresco.getFolderChild(request.session['folder'])
        folder = {
            'id': request.session['folder'],
            'parentId': request.session['parent']
        }
    else:
        entries = alfresco.getUserHomeDirectory(request)
        folder = alfresco.getUserHome(request)
        request.session['folder'] = folder['id']
        request.session['parent'] = folder['parentId']

    # data = alfresco.getDetailedData(entries)
    project_home = alfresco.getFolderByPath(request.user.id, '/Projects')['id']
    projects = []
    main_table_data = entries
    context = {
        'projects': projects,
        'data': FileUploadSerializer(data, many=True).data,
        'sorted': sorted,
        'title': 'Sensai|Dashboard',
        "value": value,
        'entries': entries,
        'parent_id': folder['parentId'],
        'folder_id': folder['id'],
        "is_old": is_old
    }
    return Response(context)
コード例 #3
0
ファイル: views.py プロジェクト: sailusm/sampleproject
def homePage(request):
    context = {}
    obj = Mobile.objects.all()
    context['products'] = obj
    form = SearchForm
    context['search'] = form
    if request.method == "POST":
        form = SearchForm(request.POST)
        if form.is_valid():
            brand = request.POST.get("brand_name")
            products = Mobile.objects.filter(brand__brand_name=brand)
            print(products)
            context['products'] = products
            return render(request, 'product/homepage.html', context)
        else:
            msg = "No Result found!"
            context['msg'] = msg
            return render(request, 'product/homepage.html', context)

    return render(request, 'product/homepage.html', context)
コード例 #4
0
ファイル: views.py プロジェクト: sailusm/sampleproject
def searchBrand(request):
    form = SearchForm
    context = {}
    context['form'] = form
    if request.method == "POST":
        print("hi")
        form = SearchForm(request.POST)
        brand = request.POST.get('brand_name')
        if form.is_valid():

            obj = Brand.objects.all()
            print(obj)
            for i in obj:
                print(brand, "--", i.brand_name)
                if brand == i.brand_name:
                    print(brand, "matched", i.brand_name)
                    context['form'] = i
                    return render(request, 'product/search.html', context)
                # else:
                #     context['form']="not found"
                #     return render(request, 'product/search.html', context)

    return render(request, 'product/home.html', context)
コード例 #5
0
    def test_form_validation_blank_search(self):
        form = SearchForm(data={})

        self.assertFalse(form.is_valid())
        self.assertIn('query', form.errors)