Ejemplo n.º 1
0
 def testSearchName(self):
     logging.debug('Testing different searches on name...')
     containers = search_name('search_test_1', exact=True)
     self.assertEqual(len(containers), 1)
     self.assertEqual(containers.get(content__rec_id='search_test_1').id, self.ids[0])
     containers = search_name('search_test')
     self.assertEqual(len(containers), 2)
     containers = search_name('other')
     self.assertEqual(len(containers), 1)
     self.assertEqual(containers.get(content__rec_id='search_test_1_other').id, self.ids[1])
     containers = search_name('other', exact=True)
     self.assertEqual(len(containers), 0)
     containers = search_name('bundle1')
     self.assertEqual(len(containers), 0)
def next_question(questions_urls, id_number):
    answers_ids, question_now_id_id, question_name, question_now_id = search_name(questions_urls, id_number)
    if answers_ids != 0:
        outputSpeech_text = "Are you looking for " + question_name
        shouldEndSession = False
        repromt_outputSpeech_text = "Please answer yes or no or repeat"
        session_attributes = get_session_attributes(requested_value = "give_answer", previous_requested_value = "next_question", questions_urls = questions_urls, question_now_id = question_now_id, question_name = question_name, answers_ids=answers_ids)
        response = get_response(outputSpeech_text = outputSpeech_text,  repromt_outputSpeech_text=repromt_outputSpeech_text, shouldEndSession = shouldEndSession)
        return response, session_attributes
    else:
        return no_correct_answer()
Ejemplo n.º 3
0
def show_name_results(page):
    form = forms.NameSearchForm()
    search_string = form.search.data

    if page == 1:
        if not form.validate_on_submit():
            #  pass the checkbox so we can show the correct from/to pane
            return render_template('name.html', form=form, tabs=tabs)

    if search_string is None:
        search_string = session['search_string']
        filters = session['filters']
    else:
        session['search_string'] = search_string
        filters = json.loads(form.search_name_filters.data)
        session['filters'] = filters

    try:
        results = search.search_name(search_string, filters, page)
    except Exception as inst:
        try:
            reason = inst.info['error']['root_cause'][0]['reason']
        except (NameError, TypeError, AttributeError):
            reason = inst

        a = list(form.search.errors)
        a.append(reason)
        form.search.errors = tuple(a)
        form.search.data = None
        return render_template('name.html', form=form, tabs=tabs)

    count = results['total']

    if not results and page != 1:
        abort(404)

    pagination = Pagination(page, Config.ITEMS_PER_PAGE, count)
    return render_template('results.html',
                           pagination=pagination,
                           companies=results,
                           tabs=tabs,
                           view=view_type)
Ejemplo n.º 4
0
 def get_object_list(self, request):
     ''' Method to return the list of objects via GET method to the Resource (not concrete).
     If the variable 'search_type' is present returns the appropriate bundles
     which match the searching query. 'search_type' can have several values:
         'name' - accompanied by 'q_str' variable containing the search string
                  returns all Bundles containing the q_str in their name.
         'id' - accompanied by 'q_str' variable containing the search string
                        returns all Bundles containing a record that contains the q_str in their name.
         'type' - accompanied by 'q_str' variable containing the search string
                       returns all Bundles containing a literal attribute with type prov:type
                       and value containing q_str.
         'time' - accompanied by 'start' and/or 'end' variable containing the times
                       returns all Bundles with within the time frame [strat:end]
         'any' - accompanied by 'q_str' variable containing the search string
                  returns all Bundles containing anything matching q_str.
     '''
     
     search_type = request.GET.get('search_type', None)
     if not search_type:    
         return ModelResource.get_object_list(self, request)
     try:
         if search_type == 'name':
             result = search_name(request.GET.get('q_str', None))
         elif search_type == 'id':
             result = search_id(request.GET.get('q_str', None))
         elif search_type == 'type':
             result = search_literal(request.GET.get('literal', None) + 'prov#type', request.GET.get('q_str', None))
         elif search_type == 'time': 
             result = search_timeframe(request.GET.get('start', None), request.GET.get('end', None))
         elif search_type == 'any':
             result = search_any_text_field(request.GET.get('q_str', None))
         else:
             raise ImmediateHttpResponse(HttpBadRequest())
         return result
     except:
         raise ImmediateHttpResponse(HttpBadRequest())
Ejemplo n.º 5
0
def list_bundles(request):
    if request.user.is_anonymous():
        user = User.objects.get(id=ANONYMOUS_USER_ID)
    else:
        user = request.user
    bundles = None
    choice = 0
    if request.method == 'POST':
        form = SearchForm(request.POST)
        if form.is_valid():
            choice = form.cleaned_data['choice']
            if choice == 'name':
                result = search_name(form.cleaned_data['name'])
                choice = 0
            elif choice == 'id':
                result = search_id(form.cleaned_data['id'])
                choice = 1
            elif choice == 'type':
                result = search_literal(form.cleaned_data['literal']+'prov#type', form.cleaned_data['value'])
                choice = 2
            elif choice == 'time':
                start_date = form.cleaned_data['start_time_date']
                start_time = form.cleaned_data['start_time_time']
                if start_date:
                    start = str(start_date) + 'T' + str(start_time)
                else:
                    start = None
                end_date = form.cleaned_data['end_time_date']
                end_time = form.cleaned_data['end_time_time']
                if end_date:
                    end = str(end_date) + 'T' + str(end_time)
                else:
                    end = None
                result = search_timeframe(start, end)
                choice = 3
            elif form.cleaned_data['choice'] == 'any':
                result = search_any_text_field(form.cleaned_data['any'])
                choice = 4
#            if result:
#            result = result.values_list('id', flat=True)
            '''Filter the result by the user permissions '''
            bundles = get_objects_for_user(user=user, perms = ['view_container'],
                                           klass=Container, any_perm=True).filter(id__in=result).\
                                           order_by('-id')
#            else:
#                bundles = []
#            cache.set(request.user.username+'_s', bundles)
            page = 1
        else:
            pass
            #bundles = cache.get(request.user.username+'_s')
    else:
        form = SearchForm()
        page = request.GET.get('page', 1)
#        if page:
#            pass
#            bundles = cache.get(request.user.username+'_s', Container.objects.none())
#        else:
#            pass
#            cache.delete(request.user.username+'_s')    
#        if not bundles:
        bundle_list = get_objects_for_user(user=user, perms = ['view_container'],
                                       klass=Container, use_groups=True,any_perm=True).\
                                       order_by('-id').select_related('content__rec_id', 'owner')
            #cache.set(request.user.username+'_s', bundles)
            
    paginator = Paginator(bundle_list, PAGINATION_THRESHOLD)
    
    ''' Change 'bundles to the actual page object'''
    try:
        bundles = paginator.page(page)
    except PageNotAnInteger:
        bundles = paginator.page(1)
        page = 1
    except EmptyPage:
        bundles = paginator.page(paginator.num_pages)
        page = paginator.num_pages
    return render_to_response('server/list_bundles.html', 
                                  {'bundles': bundles, 'page_list': _pagination(paginator, page),
                                   'form': form, 'choice': choice},
                                  context_instance=RequestContext(request))