14 from ldt.ldt_utils.views.workspace import get_search_results |
14 from ldt.ldt_utils.views.workspace import get_search_results |
15 from ldt.utils.url import static |
15 from ldt.utils.url import static |
16 from tagging.models import TaggedItem |
16 from tagging.models import TaggedItem |
17 import logging |
17 import logging |
18 from guardian.shortcuts import get_objects_for_group |
18 from guardian.shortcuts import get_objects_for_group |
|
19 from ldt.indexation import get_results_with_context |
19 |
20 |
20 User = get_user_model() |
21 User = get_user_model() |
21 logger = logging.getLogger(__name__) |
22 logger = logging.getLogger(__name__) |
22 |
23 |
23 |
24 |
118 if tag_label is None : |
119 if tag_label is None : |
119 content_list = Content.safe_objects.all().select_related('stat_annotation') |
120 content_list = Content.safe_objects.all().select_related('stat_annotation') |
120 else : |
121 else : |
121 content_list = TaggedItem.objects.get_by_model(Content.safe_objects.all().select_related('stat_annotation'), '"'+tag_label+'"') |
122 content_list = TaggedItem.objects.get_by_model(Content.safe_objects.all().select_related('stat_annotation'), '"'+tag_label+'"') |
122 else : |
123 else : |
123 content_list = Content.safe_objects.filter(title__icontains=media_title).select_related('stat_annotation') |
124 #content_list = Content.safe_objects.filter(title__icontains=media_title).select_related('stat_annotation') |
124 |
125 content_searched = get_results_with_context(Content, "all", media_title) |
|
126 content_list = Content.objects.filter(pk__in=[c['indexation_id'] for c in content_searched]).select_related('stat_annotation') |
125 |
127 |
126 nb = settings.LDT_FRONT_MEDIA_PER_PAGE |
128 nb = settings.LDT_FRONT_MEDIA_PER_PAGE |
127 if page=="x": |
129 if page=="x": |
128 nb = content_list.count() |
130 nb = content_list.count() |
129 |
131 |
235 content_tag = None |
237 content_tag = None |
236 colorurl=static("ldt/swf/ldt/pkg/color.xml") |
238 colorurl=static("ldt/swf/ldt/pkg/color.xml") |
237 i18nurl=static("ldt/swf/ldt/pkg/i18n") |
239 i18nurl=static("ldt/swf/ldt/pkg/i18n") |
238 baseurl=static("ldt/swf/ldt/") |
240 baseurl=static("ldt/swf/ldt/") |
239 sform = SearchForm(request.GET) |
241 sform = SearchForm(request.GET) |
|
242 content_results = None |
|
243 more_contents = False |
|
244 |
|
245 # Now we handle the segment search |
240 if sform.is_valid(): |
246 if sform.is_valid(): |
241 search = sform.cleaned_data["search"] |
247 search = sform.cleaned_data["search"] |
242 field = sform.cleaned_data["field"] |
248 field = sform.cleaned_data["field"] |
|
249 # If the request has a page indicated, we are in segment search |
|
250 if "page" not in request.GET: |
|
251 # If not, we are in the first page of results, so we display the first contents |
|
252 content_searched = get_results_with_context(Content, field, search) |
|
253 if len(content_searched) > settings.LDT_MEDIA_IN_RESULTS_PAGE : |
|
254 more_contents = True |
|
255 content_searched = content_searched[:settings.LDT_MEDIA_IN_RESULTS_PAGE] |
|
256 content_results = Content.objects.filter(pk__in=[c['indexation_id'] for c in content_searched]).select_related('stat_annotation') |
|
257 |
243 page = sform.cleaned_data["page"] or 1 |
258 page = sform.cleaned_data["page"] or 1 |
244 # If asked, we filter the request with only the contents tagged with content_tag |
259 # If asked, we filter the request with only the contents tagged with content_tag |
245 content_tag = sform.cleaned_data["content_tag"] |
260 content_tag = sform.cleaned_data["content_tag"] |
246 content_list = None |
261 content_list = None |
247 if content_tag is not None and content_tag != "" : |
262 if content_tag is not None and content_tag != "" : |
248 content_list = TaggedItem.objects.get_by_model(Content.objects.all(), '"'+content_tag+'"') |
263 content_list = TaggedItem.objects.get_by_model(Content.objects.all(), '"'+content_tag+'"') |
249 results, nb, nb_segment = get_search_results(request, search, field, page, content_list) |
264 results, nb, nb_segment = get_search_results(request, search, field, page, content_list) |
250 |
265 |
251 return render_to_response('front/front_search_results.html', {'results': results, 'nb_results' : nb, 'nb_segment':nb_segment, 'search' : search, 'field': field, 'tag_label':content_tag, 'colorurl': colorurl, 'i18nurl': i18nurl, 'language': language_code, 'baseurl': baseurl}, context_instance=RequestContext(request)) |
266 return render_to_response('front/front_search_results.html', { |
252 |
267 'results': results, 'nb_results' : nb, 'nb_segment':nb_segment, 'search' : search, |
253 |
268 'field': field, 'tag_label':content_tag, 'colorurl': colorurl, 'i18nurl': i18nurl, |
254 |
269 'language': language_code, 'baseurl': baseurl, |
|
270 'content_results': content_results, 'more_contents': more_contents, |
|
271 }, context_instance=RequestContext(request)) |
|
272 |
|
273 |
|
274 |