My form isn't being processed

80 views
Skip to first unread message

Mario Menezes

unread,
Apr 25, 2012, 12:49:51 PM4/25/12
to django-...@googlegroups.com
Hi,

  I've created a custom search form with some additional processing for empty results but no matter what I do, this form is being sillently ignored when processing.
 
  I could not figure out the problem, so please, help me with this.

  My urls.py:

urlpatterns += patterns('haystack.views',
    url(r'^busca$', MyFacetedSearchView(form_class=FacetedSearchForm , searchqueryset=sqs, template='lfs/search/search.html'), name='haystack_search_marca'),
    url(r'^busca$',  search_view_factory(view_class=SearchView, template='lfs/search/search.html',\
        form_class=ProductSearchForm, \
    ), name='haystack_search'),
)

 My form:

class ProductSearchForm(SearchForm):
   
    def search(self):
        sqs = super(ProductSearchForm, self).search()
        print "AH AH AH AH AH \n\n\n"
        if not self.is_valid():
            return self.no_query_found()

        if not self.cleaned_data.get('q'):
            return self.no_query_found()

        sqs = self.searchqueryset.auto_query(self.cleaned_data['q'])
       
        if len(sqs)==0:
            q_split = q.split()
            if len(q_split)>3:
                q1 = ' '.join(q_split[0:2])
                sqs_alt = self.searchqueryset.filter(content=q1)
                if len(sqs_alt)>0:
                    if self.load_all:
                        sqs_alt = sqs_alt.load_all()
                    sqs = sqs_alt

        if self.load_all:
            sqs = sqs.load_all()

        return sqs


   I've put a print statement so make sure my form is being called and nothing is printed by django!

   If I put the print statement directly on haystack forms.py, it got printed.

   Is there any other thing I have to do so that my form is called? Any error that's preventing it of being processed?

   Thanks in advance for any help.

Mario Menezes

David Sauve

unread,
Apr 25, 2012, 12:53:16 PM4/25/12
to django-...@googlegroups.com
I think there's an issue with your url patterns.  You have the same regex twice, ''^busca$'.  Since they parsed in the order they appear, it will always match the first one, bypassing yours.
--
You received this message because you are subscribed to the Google Groups "django-haystack" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-haystack/-/szSH--OK4LIJ.
To post to this group, send email to django-...@googlegroups.com.
To unsubscribe from this group, send email to django-haysta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-haystack?hl=en.

Mario Menezes

unread,
Apr 25, 2012, 12:55:43 PM4/25/12
to django-...@googlegroups.com
Hi David,

  Thanks for your quick answer.

  How I could change the urls so that I get faceted search? Should I have only one entry or should I have a different url for faceted search?

  Regards,

2012/4/25 David Sauve



--
--
Mario O.de Menezes, Ph.D.
"Many are the plans in a man's heart, but is the Lord's purpose that prevails" Pv 19.21
http://www.momenezes.com     -    LinuxUser: #24626



David Sauve

unread,
Apr 25, 2012, 12:58:30 PM4/25/12
to django-...@googlegroups.com
You'll need a different url for one of the views if you want Django to be able to know which to use.  Alternatively, maybe you could derive your SearchForm from FacetedSearchForm so you only have url.

Mario Menezes

unread,
Apr 25, 2012, 2:06:28 PM4/25/12
to django-...@googlegroups.com
Ok! I'm trying to do this. Not sure yet how to differentiate between the first call and successive narrowing searchs (user clicking in one facet). Any hint on how to do this?

Thanks
2012/4/25 David Sauve
To post to this group, send email to django-haystack@googlegroups.com.
To unsubscribe from this group, send email to django-haystack+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-haystack?hl=en.

--
You received this message because you are subscribed to the Google Groups "django-haystack" group.
To post to this group, send email to django-haystack@googlegroups.com.
To unsubscribe from this group, send email to django-haystack+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-haystack?hl=en.



--
--
Mario O.de Menezes, Ph.D.
"Many are the plans in a man's heart, but is the Lord's purpose that prevails" Pv 19.21
http://www.momenezes.com     -    LinuxUser: #24626



--
You received this message because you are subscribed to the Google Groups "django-haystack" group.
To post to this group, send email to django-haystack@googlegroups.com.
To unsubscribe from this group, send email to django-haystack+unsubscribe@googlegroups.com.

David Sauve

unread,
Apr 25, 2012, 2:13:17 PM4/25/12
to django-...@googlegroups.com
I'm not clear as to why you would need to know if it's the first time the view has been called or not.  You can test for `selected_facets` in the cleaned_data of the form if you want to get the user selected facets.  If you really wanted to know how many times the user has viewed the page, you could probably include a hidden form field that incremented on each successive view.
To view this discussion on the web visit https://groups.google.com/d/msg/django-haystack/-/nO2umKmu-F8J.
To post to this group, send email to django-...@googlegroups.com.
To unsubscribe from this group, send email to django-haysta...@googlegroups.com.

Mario Menezes

unread,
Apr 25, 2012, 2:49:18 PM4/25/12
to django-...@googlegroups.com
I'm new to django-haystack and I'm trying to figure out how to do faceted search.

I thought I would need to know if the form was called the first time (without facets) and when it was called second time, now with facets. But removing my custom form and using default FacetedSearchForm seems to be fine.

Now I need to figure out a proper regular expression to offer the user a "remove filter" option, that is, removing from the faceted url the current facet and reseting the search or leaving only one other facet.

Thanks for your hint.

2012/4/25 David Sauve <dns...@gmail.com>

David Sauve

unread,
Apr 25, 2012, 2:53:20 PM4/25/12
to django-...@googlegroups.com
Np worries.  I think your best bet for resetting/manipulating the facets would be through the client side form fields.  Maybe display them as a list of checkboxes and let the user turn them on and off as desired?

Mario Menezes

unread,
Apr 25, 2012, 3:04:36 PM4/25/12
to django-...@googlegroups.com
It's exactly this I'm trying to do! But to remove one filter after the user remove an check I should be able to remove that unselected facet from the URL and this is what I'm trying to do.

As I'm not very good with Django as well maybe I'm not understanding your advice. Could you kindly explain a bit further this strategy? I would be very thankful.

The code I'm using to try to do this is from this msg:

https://groups.google.com/d/topic/django-haystack/Rk-Qoz1Z0og/discussion

See the last post by LarryEitel.

Thanks again for your attention.

Best regards.

2012/4/25 David Sauve <dns...@gmail.com>

David Sauve

unread,
Apr 25, 2012, 3:21:52 PM4/25/12
to django-...@googlegroups.com
Ah, I see.  In this case you don't need to worry about managing the url yourself.  The querystring will be built and managed by the form itself so if you post/get your form back to the view you will be able to get the selected_facets from the cleaned_data attribute of the form.

If you're using the built-in FacetedSearchForm in your template, when it gets sent back to the view for processing it'll have the currently selected facets available in the `cleaned_data['selected_facets']` attribute.  You shouldn't need to muck around with most of them though, unless you're trying to customise things, as it should just work out of the box.

What is it that you are trying to do with these views, out of curiousity?

Mario Menezes

unread,
Apr 25, 2012, 3:32:20 PM4/25/12
to django-...@googlegroups.com
I found another post just now that shows a picture of what I'm trying to do, if you don't mind.

https://groups.google.com/d/topic/django-haystack/xWhpYu1stjA/discussion

The initial post explain the objective. I have only two facets: brand and category.

I would like something like:

Refine your search by:

Brands
Brand A  (count)
Brand B  (count)


Categories
Category A (count)
Category B (count)


Then, if the user select one brand or category, the next screen should show only remaining possible facets along a option to remove that facet. This is my point.

I will definitely study that post a bit more. Maybe my answer is there.

Or maybe building a more elegant form, with checkboxes and a button Refine and Remove could be easier. I'll see.

Thanks for your time and patience

Mario


2012/4/25 David Sauve <dns...@gmail.com>

David Sauve

unread,
Apr 25, 2012, 3:44:19 PM4/25/12
to django-...@googlegroups.com
Makes sense.  I think you can probably achieve what you're looking for with the built in forms and views, actually.  Have you had a chance to read through this document: http://django-haystack.readthedocs.org/en/latest/faceting.html

It's doing the facetting in the query string itself, but you could also implement your own form to encapsulate this if you'd prefer to go that route.
Reply all
Reply to author
Forward
0 new messages