def search(request, template_name="files/search.html"): """ This page lists out all files from newest to oldest. If a search index is available, this page will also have the option to search through files. """ query = u'' category = u'' sub_category = u'' group = None form = FileSearchForm(request.GET) if form.is_valid(): query = form.cleaned_data['q'] category = form.cleaned_data['category'] sub_category = form.cleaned_data['sub_category'] group = form.cleaned_data['group'] filters = get_query_filters(request.user, 'files.view_file') files = File.objects.filter(filters).distinct() if query: files = files.filter(Q(file__icontains=query)| Q(name__icontains=query)| Q(description__icontains=query)| Q(tags__icontains=query)) if category: files = files.filter(categories__category__name=category) if sub_category: files = files.filter(categories__parent__name=sub_category) if group: files = files.filter(group_id=group) files = files.order_by('-update_dt') EventLog.objects.log() layout = get_setting("module", "files", "layout") base_template_path = "files/base.html" if layout == 'grid': base_template_path = "base-wide.html" return render_to_response( template_name, { 'files': files, 'form': form, 'layout': layout, 'base_template_path': base_template_path, }, context_instance=RequestContext(request))
def search(request, template_name="files/search.html"): """ This page lists out all files from newest to oldest. If a search index is available, this page will also have the option to search through files. """ query = u'' category = u'' sub_category = u'' group = None form = FileSearchForm(request.GET, **{'user': request.user}) if form.is_valid(): query = form.cleaned_data['q'] category = form.cleaned_data['category'] sub_category = form.cleaned_data['sub_category'] group = form.cleaned_data['group'] filters = get_query_filters(request.user, 'files.view_file') files = File.objects.filter(filters).distinct() if query: files = files.filter(Q(file__icontains=query)| Q(name__icontains=query)| Q(description__icontains=query)| Q(tags__icontains=query)) if category: files = files.filter(categories__category__name=category) if sub_category: files = files.filter(categories__parent__name=sub_category) if group: files = files.filter(group_id=group) files = files.order_by('-update_dt') EventLog.objects.log() layout = get_setting("module", "files", "layout") base_template_path = "files/base.html" if layout == 'grid': base_template_path = "base-wide.html" return render_to_response( template_name, { 'files': files, 'form': form, 'layout': layout, 'base_template_path': base_template_path, }, context_instance=RequestContext(request))
def search(request, template_name="files/search.html"): """ This page lists out all files from newest to oldest. If a search index is available, this page will also have the option to search through files. """ query = u'' category = u'' sub_category = u'' group = None has_index = get_setting('site', 'global', 'searchindex') form = FileSearchForm(request.GET) if form.is_valid(): query = form.cleaned_data['q'] category = form.cleaned_data['category'] sub_category = form.cleaned_data['sub_category'] group = form.cleaned_data['group'] if has_index and query: files = File.objects.search(query, user=request.user) if category: files = files.filter(category=category) if sub_category: files = files.filter(sub_category=sub_category) else: filters = get_query_filters(request.user, 'files.view_file') files = File.objects.filter(filters).distinct() if category: files = files.filter(categories__category__name=category) if sub_category: files = files.filter(categories__parent__name=sub_category) if group: files = files.filter(group_id=group) files = files.order_by('-update_dt') EventLog.objects.log() return render_to_response(template_name, { 'files': files, 'form': form, }, context_instance=RequestContext(request))
def search(request, template_name="files/search.html"): """ This page lists out all files from newest to oldest. If a search index is available, this page will also have the option to search through files. """ query = u"" category = u"" sub_category = u"" group = None form = FileSearchForm(request.GET) if form.is_valid(): query = form.cleaned_data["q"] category = form.cleaned_data["category"] sub_category = form.cleaned_data["sub_category"] group = form.cleaned_data["group"] filters = get_query_filters(request.user, "files.view_file") files = File.objects.filter(filters).distinct() if query: files = files.filter( Q(file__icontains=query) | Q(name__icontains=query) | Q(description__icontains=query) | Q(tags__icontains=query) ) if category: files = files.filter(categories__category__name=category) if sub_category: files = files.filter(categories__parent__name=sub_category) if group: files = files.filter(group_id=group) files = files.order_by("-update_dt") EventLog.objects.log() return render_to_response(template_name, {"files": files, "form": form}, context_instance=RequestContext(request))