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)
def index(): from product.forms import SearchForm form = SearchForm() if form.validate_on_submit(): products = Products.query.filter( Products.product_name.match("%" + form.product.data + "%")).paginate(1, 10) return render_template('products.html', products=products) return render_template('search_product.html', form=form)
def signup(request): context = {} context["nav_search_form"] = SearchForm(auto_id="nav_%s") if request.method == "POST": form = AccountCreationForm(request.POST) if form.is_valid(): email = form.cleaned_data["email"] password = form.cleaned_data["password1"] first_name = form.cleaned_data["first_name"] Account.objects.create_user(email, first_name, password=password) user = authenticate(email=email, password=password) login(request, user) return HttpResponseRedirect("/") else: context["form"] = AccountCreationForm() return render(request, "account/signup.html", context=context)
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)
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)
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)
def get(self, request): form = SearchForm() return render(request, 'product/index.html', {'form': form})
def legal_notice(request): context = {} context["nav_search_form"] = SearchForm(auto_id="nav_%s") return render(request, "www/legal-notice.html", context=context)
def home(request): context = {} context["nav_search_form"] = SearchForm(auto_id="nav_%s") context["jumbotron_search_form"] = SearchForm(auto_id="jumbotron_%s") context["contact_form"] = ContactForm() return render(request, "www/home.html", context=context)
def favorites(request): context = {} context["nav_search_form"] = SearchForm(auto_id="nav_%s") user = request.user context["favorites"] = user.get_favorites() return render(request, "account/favorites.html", context=context)
def profile(request): context = {} context["nav_search_form"] = SearchForm(auto_id="nav_%s") context["password_form"] = PasswordChangeForm(request.user) return render(request, "account/profile.html", context=context)
def test_form_renders_input_with_placeholders_and_css_classes(self): form = SearchForm() self.assertIn('placeholder="Enter your search term"', form.as_p()) self.assertIn('class="form-control', form.as_p()) self.assertIn('id="input-search', form.as_p())
def test_form_validation_blank_search(self): form = SearchForm(data={}) self.assertFalse(form.is_valid()) self.assertIn('query', form.errors)