Exemplo n.º 1
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["query"] = self.request.GET.get("q")
        context["looks_like_postcode"] = is_valid_postcode(context["query"])
        if context["query"]:
            context["results"] = search_person_by_name(context["query"])[:10]

        return context
Exemplo n.º 2
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['looks_like_postcode'] = is_valid_postcode(context['query'])
     object_list = context['object_list']
     actual_pks = Person.objects.filter(
         pk__in=[r.pk for r in object_list]).values_list('pk', flat=True)
     context['object_list'] = [
         o for o in object_list if int(o.pk) in actual_pks]
     return context
 def get_redirect_url(self, *args, **kwargs):
     postcode = self.request.GET.get('postcode', '')
     if is_valid_postcode(postcode):
         return "https://whocanivotefor.co.uk/elections/{}".format(postcode)
     else:
         return "/?who_postcode={}&postcode_invalid=1".format(postcode)
 def get_context_data(self, **kwargs):
     context = super(PersonSearch, self).get_context_data(**kwargs)
     context['looks_like_postcode'] = is_valid_postcode(context['query'])
     # Only return 5 results
     context['object_list'] = context['object_list'][:5]
     return context
 def get_context_data(self, **kwargs):
     context = super(PersonSearch, self).get_context_data(**kwargs)
     context['looks_like_postcode'] = is_valid_postcode(context['query'])
     # Only return 5 results
     context['object_list'] = context['object_list'][:5]
     return context
 def get_redirect_url(self, *args, **kwargs):
     postcode = self.request.GET.get('postcode', '')
     if is_valid_postcode(postcode):
         return "https://whocanivotefor.co.uk/elections/{}".format(postcode)
     else:
         return "/?who_postcode={}&postcode_invalid=1".format(postcode)
Exemplo n.º 7
0
 def get_context_data(self, **kwargs):
     context = super(PersonSearch, self).get_context_data(**kwargs)
     context['looks_like_postcode'] = is_valid_postcode(context['query'])
     return context