コード例 #1
0
 def get_context_data(self, *, object_list=None, **kwargs):
     form = SearchForm(data=self.request.GET)
     if form.is_valid():
         search = form.cleaned_data['search']
         kwargs['search'] = search
     kwargs['form'] = form
     return super().get_context_data(object_list=object_list, **kwargs)
コード例 #2
0
def database():
    form = SearchForm()
    if form.validate_on_submit(
    ):  # if validates on sub then put it in lowercase and take the "@" sign if there is one
        form.username.data = form.username.data.lower()
        if form.username.data[0] == "@":
            form.username.data = form.username.data[1:]
        try:
            # if the user exists then report them
            scanning.get_twitter_info(form.username.data)
            return redirect(
                url_for("database_search", username=form.username.data,
                        page=1))
        except:
            flash(f"Sorry. That account does not exist", "danger")
    elif form.submit.data:
        flash(f"Sorry. That username is invalid.", "danger")
    page = request.args.get("page", 1, type=int)
    # fetch a paginated list of recent reports in order of date submitted desc
    reports = Report.query.order_by(
        Report.date_submitted.desc()).paginate(per_page=5)
    return render_template('database.html',
                           form=form,
                           reports=reports,
                           title="Database")
コード例 #3
0
def searchStock(request):
    auth = request.COOKIES.get('auth')
    if not auth:
        return render(request, 'error.html', {'error': 'Invalid authentication'})
    if(request.method == 'POST'):
        form = SearchForm(request.POST)
        if(form.is_valid()):
            query = form.cleaned_data.get('query')
            post_data = {}
            post_data['query'] = query
            post_encoded = urllib.parse.urlencode(post_data).encode('utf-8')
            req = urllib.request.Request(
                "http://exp-api:8000/exp/stock/search", data=post_encoded, method='POST')
            resp_json = urllib.request.urlopen(req).read().decode('utf-8')
            resp = json.loads(resp_json)
            if(len(resp['hits']['hits']) == 0):
                return render(request, 'search_results.html', {'error': "No matches found"})
            else:
                res = []
                for ele in resp['hits']['hits']:
                    res.append(ele['_source'])
                return render(request, 'search_results.html', {'output': res})
    else:
        form = SearchForm()
        return render(request, 'search_stock.html', {'form': form})
コード例 #4
0
 def get_queryset(self, **kwargs):
     data = Country.objects.all()
     form = SearchForm(data=self.request.GET)
     if form.is_valid():
         search = form.cleaned_data['search']
         if search:
             data = data.filter(Q(name__icontains=search))
     return data
 def get_queryset(self):
     data = User.objects.all()
     form = SearchForm(data=self.request.GET)
     if form.is_valid():
         search = form.cleaned_data['search']
         if search:
             data = data.filter(Q(name__icontains=search) | Q(description__icontains=search))
     return data
コード例 #6
0
def book_search(request):
    form = SearchForm(data=request.GET)
    if form.is_valid():
        search = form.cleaned_data['search']
        books = Book.objects.filter(author__contains=search).exclude(
            status='blocked').order_by('-created_at')
        return render(request, 'search.html', context={'books': books})
    else:
        return redirect('book_index')
コード例 #7
0
def products_list_view(request):
    products = Product.objects.filter(amount__gt=0)
    form = SearchForm(request.GET)
    if form.is_valid():
        search_query = form.cleaned_data['search']
        if search_query:
            products = products.filter(name__icontains=search_query)
    products = products.order_by('category', 'name')
    return render(request, 'products_list.html', context={'products': products, 'form': form})
コード例 #8
0
    def get_queryset(self):
        data = Tasks.objects.all()

        form = SearchForm(data=self.request.GET)
        if form.is_valid():
            search = form.cleaned_data['search']
            if search:
                data = data.filter(
                    Q(summary__icontains=search)
                    | Q(description__icontains=search))

        return data.order_by('-task_create')
コード例 #9
0
def book_search_view(request, *args, **kwargs):
    form = SearchForm(data=request.GET)
    if form.is_valid():
        text = form.cleaned_data['search']
        if len(text) > 0:
            books = Books.objects.filter(name_author__contains=text, status="active").order_by("-created_at")
            print(text)
            print(books)
            return render(request, 'index.html', context={'books': books})
        else:
            return redirect('index')
    return redirect('index')
コード例 #10
0
 def get_context_data(self, *, object_list=None, **kwargs):
     context = super().get_context_data(**kwargs)
     nom_nom = self.get_object()
     form = SearchForm(data=self.request.GET)
     data = Coin.objects.filter(Q(currency__pk=nom_nom.currency.pk) & Q(nominal=nom_nom.nominal))
     if form.is_valid():
         search = form.cleaned_data['search']
         if search:
             data = data.filter(Q(year_of_issue__icontains=search))
         kwargs['search'] = search
     context['form'] = form
     context['coins'] = data.order_by('year_of_issue')
     return context
コード例 #11
0
def musicians_list_view(request):
    musicians = Musician.objects.filter(position__gt=0)
    form = SearchForm(request.GET)
    if form.is_valid():
        search_query = form.cleaned_data['search']
        if search_query:
            musicians = musicians.filter(author__icontains=search_query)
    musicians = musicians.order_by('position', 'author')
    return render(request,
                  'musicians_list.html',
                  context={
                      'musicians': musicians,
                      'form': form
                  })
コード例 #12
0
 def get_context_data(self, *, object_list=None, **kwargs):
     form = SearchForm(data=self.request.GET)
     user = User.objects.get(pk=self.request.user.pk)
     collection_coins = Coin_in_Collection.objects.filter(owner=user)
     offers = []
     for coin in collection_coins:
         if coin.offers:
             for offer in coin.offers.all():
                 offers.append(offer)
     if form.is_valid():
         search = form.cleaned_data['search']
         kwargs['search'] = search
     kwargs['form'] = form
     kwargs['offers'] = offers
     kwargs['user'] = user
     return super().get_context_data(object_list=object_list, **kwargs)
コード例 #13
0
ファイル: __init__.py プロジェクト: pgerasimov/books_search
 def search():
     title = "Поиск книги"
     search_form = SearchForm()
     return render_template('search.html',
                            page_title=title,
                            form=search_form,
                            active='search')
コード例 #14
0
class IndexView(ListView):
    template_name = 'products/index.html'
    model = Product
    context_object_name = 'products'
    paginate_by = 5
    paginate_orphans = 1

    def get(self, request, **kwargs):
        self.form = SearchForm(request.GET)
        self.search_data = self.get_search_data()
        return super(IndexView, self).get(request, **kwargs)

    def get_queryset(self):
        queryset = super().get_queryset()

        if self.search_data:
            queryset = queryset.filter(
                Q(name__icontains=self.search_data) |
                Q(category__icontains=self.search_data)
            )
        return queryset

    def get_search_data(self):
        if self.form.is_valid():
            return self.form.cleaned_data['search_value']
        return None

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['search_form'] = self.form

        if self.search_data:
            context['query'] = urlencode({'search_value': self.search_data})
        return context
コード例 #15
0
def index():
    form = SearchForm()
    if form.validate_on_submit():
        method = form.methods.data
        content = form.content.data
        if method == 1:
            return redirect(
                url_for('result.result_title', content=content, page=1))
        elif method == 2:
            return redirect(
                url_for('result.result_author', content=content, page=1))
        elif method == 3:
            return redirect(url_for('result.result_ISBN', content=content))
        else:
            return None
    return render_template('index.html', form=form)
コード例 #16
0
ファイル: views.py プロジェクト: MuctepK/guest_book
def note_search_view(request):
    pattern = request.GET.get('pattern')
    notes = Note.objects.all().filter(author_name__icontains=pattern).\
        filter(status=DEFAULT_STATUS).order_by('-created_at')
    search_form = SearchForm()
    context = {'notes': notes, 'search_form': search_form}
    return render(request, 'index.html', context)
class IndexView(ListView):
    template_name = 'lists/index.html'
    model = List
    context_object_name = 'lists'
    ordering = ('name', '-created_at')
    paginate_by = 8
    paginate_orphans = 0

    def get(self, request, **kwargs):
        self.form = SearchForm(request.GET)
        self.search_data = self.get_search_data()
        return super().get(request, **kwargs)

    def get_queryset(self):
        queryset = super().get_queryset()

        if self.search_data:
            queryset = queryset.filter(Q(name__icontains=self.search_data))
        return queryset

    def get_search_data(self):
        if self.form.is_valid():
            return self.form.cleaned_data['search_value']
        return None

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['search_form'] = self.form

        if self.search_data:
            context['query'] = urlencode({'search_value': self.search_data})

        return context
コード例 #18
0
ファイル: views.py プロジェクト: emirnur/exam-6
def index_view(request, *args, **kwargs):
    hosts = HostBook.objects.filter(status='active').order_by('created_at')
    search_form = SearchForm()
    return render(request, 'index.html', context={
        'hosts': hosts,
        'search_form': search_form,
    })
コード例 #19
0
class IndexView(ListView):
    template_name = 'tasks/index.html'
    model = List
    context_object_name = 'lists'
    ordering = ('-created_at', 'summary')
    paginate_by = 5
    paginate_orphans = 2

    def get(self, request, **kwargs):
        self.form = SearchForm(request.GET)
        self.search_data = self.get_search_data()
        return super(IndexView, self).get(request, **kwargs)

    def get_queryset(self):
        queryset = super().get_queryset()

        if self.search_data:
            queryset = queryset.filter(
                Q(summary__icontains=self.search_data)
                | Q(description__icontains=self.search_data))
        return queryset

    def get_search_data(self):
        if self.form.is_valid():
            return self.form.cleaned_data['search_value']
        return None

    def get_context_data(self, **kwargs):
        kwargs = super().get_context_data(**kwargs)
        kwargs['search_form'] = self.form

        if self.search_data:
            kwargs['query'] = urlencode({'search_value': self.search_data})

        return kwargs
コード例 #20
0
class ProductListView(ListView):
    template_name = 'products/product-list.html'
    paginate_by = 7
    paginate_orphans = 2
    model = Product
    context_object_name = 'products'
    ordering = ('category', 'name')

    def get(self, request, **kwargs):
        self.search_form = SearchForm(request.GET)
        self.search_value = self.get_search_value()
        return super().get(request, kwargs)

    def get_search_value(self):
        if self.search_form.is_valid():
            return self.search_form.cleaned_data['search_value']
        return None

    def get_context_data(self, *, object_list=None, **kwargs):
        context = super().get_context_data()
        context['search_form'] = self.search_form

        if self.search_value:
            context['query'] = urlencode({'search_value': self.search_value})
        return context

    def get_queryset(self):
        queryset = super().get_queryset()
        if self.search_value:
            queryset = queryset.filter(
                Q(name__icontains=self.search_value)
                | Q(description__icontains=self.search_value))
        return queryset.exclude(remainder=0)
コード例 #21
0
def index_view(request):
    products = Product.objects.filter(amount__gt=0).order_by('category', 'name')
    search_form = SearchForm()
    return render(request, 'index.html', context={
        'products': products,
        'search_form': search_form
    })
コード例 #22
0
class ProjectView(ListView):
    template_name = 'project/project.html'
    model = Project
    context_object_name = 'projects'
    ordering = ('name', '-started_at')

    def get(self, request, **kwargs):
        self.form = SearchForm(request.GET)
        self.search_data = self.get_search_data()
        return super(ProjectView, self).get(request, **kwargs)

    def get_queryset(self):
        queryset = super().get_queryset()

        if self.search_data:
            queryset = queryset.filter(
                Q(name__icontains=self.search_data)
                | Q(description__icontains=self.search_data))
        return queryset

    def get_search_data(self):
        if self.form.is_valid():
            return self.form.cleaned_data['search_value']
        return None

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['search_form'] = self.form

        if self.search_data:
            context['query'] = urlencode({'search_value': self.search_data})

        return context
コード例 #23
0
def search_by_name(request, *args, **kwargs):
    search = request.GET.get('search')
    products = Product.objects.filter(name__contains=search)
    form = SearchForm()
    return render(request, 'index.html', context={
        'products': products,
        'form': form,
    })
コード例 #24
0
ファイル: views.py プロジェクト: S7bhash/tourkarnataka
def index():
    search = SearchForm()
    if search.validate_on_submit():
        sent = str(search.search.data)
        word_list = sent.split()
        results = []
        for x in word_list:
            places = retrievePlaces(x)
            if places is not None:
                for place in places:
                    results.append(place)
        return render_template('results.html',
                               results=results,
                               name=search.search.data)
    return render_template('index.html',
                           form=search,
                           current_user=current_user)
コード例 #25
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     pk = self.kwargs.get('pk')
     form = SearchForm(data=self.request.GET)
     data = Currency.objects.filter(country__pk=pk)
     context['form'] = form
     context['currencies'] = data.order_by('name')
     return context
コード例 #26
0
def index_view(request, *args, **kwargs):
    books = Book.objects.all().filter(status='active').order_by('-created_at')
    form = SearchForm()
    return render(request,
                  'index.html',
                  context={
                      'books': books,
                      'form': form
                  })
コード例 #27
0
def index_view(request):
    products = Product.objects.filter(amount__gt=0).order_by('category')
    form = SearchForm()
    return render(request,
                  'index.html',
                  context={
                      'products': products,
                      'form': form,
                      'category': PRODUCT_CATEGORY_CHOICES
                  })
コード例 #28
0
    def get_context_data(self, *args, **kwargs):
        form = SearchForm()
        context = super().get_context_data(**kwargs)
        query = self.request.GET.get('search')
        if query:
            search_project = Project.objects.filter(name__icontains=query)
            context['search_list'] = search_project

        context['form'] = form
        return context
コード例 #29
0
def category_view(request, category):
    products = Product.objects.filter(category=category).order_by('category')
    form = SearchForm()
    return render(request,
                  'index.html',
                  context={
                      'products': products,
                      'category': PRODUCT_CATEGORY_CHOICES,
                      'form': form
                  })
コード例 #30
0
def product_by_category_view(request, category):
    products = Product.objects.all().exclude(remain=0).filter(
        category=category).order_by('name')
    search_form = SearchForm()
    choose = [cat[1] for cat in CATEGORY_CHOICES if cat[0] == category]
    context = {
        'products': products,
        'search_form': search_form,
        'category': choose[0]
    }
    return render(request, 'product_category.html', context)
コード例 #31
0
ファイル: views.py プロジェクト: dingding132/Float
def search_result(request):
	if request.method == 'GET':
		return render(request,'search_result.html')
	if request.method == 'POST':
		form = SearchForm(request.POST)
		if form.is_valid():
			#get search details
			departure = form.cleaned_data['departure']
			arrival = form.cleaned_data['arrival']
			date = form.cleaned_data['date']

			# #get all trips
			# trips = Trip()
			# trips = Trip.objects.all()

			#trips with only 1 connection
			trips1 = Trip()
			trips1 = Trip.objects.filter(departure_city=departure).filter(arrival_city=arrival).filter(departure_date=date)
			for trip in trips1:
				distance_dict = gmaps.distance_matrix(trip.departure_city,trip.arrival_city)
				distance1 = distance_dict['rows'][0]['elements'][0]['distance']['value']
				trip.distance = distance1/1000
				trip.save

			# #trips with 2 connections
			# firstTripID = []
			# secondTripID = []
			# trips2_departure_match = {"id", "driver","departure_date", "departure_time", "departure_city",
			# "arrival_city", "distance", "messages"}
			# trips2_arrival_match = {"id", "driver","departure_date", "departure_time", "departure_city",
			# "arrival_city", "distance", "messages"}
			# trips2_departure_match = Trip.objects.filter(departure_city=departure).values
			# trips2_arrival_match = Trip.objects.filter(arrival_city=arrival).values

			# for tripDeparture in trips2_departure_match:
			# 	for tripArrival in trips2_arrival_match:
			# 		if tripDeparture["arrival_city"] == tripArrival["departure_city"]:
			# 			firstTrip.append(tripDeparture["id"])
			# 			secondTrip.append(tripArrival["id"])

			# firstTrips = Trip()
			# secondTrips = Trip()

			# for i in firstTripID:
			# 	trip1 = Trip.objects.filter(id=firstTripID[i])
			# 	trip2 = Trip.objects.filter(id=secondTripID[i])
			# 	firstTrips.append(trip1)
			# 	secondTrips.append(trip2)


		 # #   #get distance from google api
			# # for trip in trips2FirstTrip:
			# # 	distance_dict = gmaps.distance_matrix(trip.departure_city,trip.arrival_city)
			# # 	distance1 = distance_dict['rows'][0]['elements'][0]['distance']['value']
			# # 	trip.distance = distance1/1000
			# # 	trip.save

			# # for trip in trips2SecondTrip:
			# # 	distance_dict = gmaps.distance_matrix(trip.departure_city,trip.arrival_city)
			# # 	distance1 = distance_dict['rows'][0]['elements'][0]['distance']['value']
			# # 	trip.distance = distance1/1000
			# # 	trip.save

			# #get total distance for 2 connections
			# # totalDistance2 = []
			# # for i in trips2SecondTrip.amount():
			# # 	distance = trips2FirstTrip[i].distance + trips2SecondTrip[i].distance
			# # 	totalDistance2.append(distance)

	return render(request, 'search_result.html', {'trips1': trips1})