Exemple #1
0
def home(request):
    search_form = SearchForm()
    engine_list = util.get_engine_titles()
    return render_to_response("djbeagle/home.html",
                { "search_form" : search_form,
                 'engine_list' : engine_list, },
                context_instance=RequestContext(request))
Exemple #2
0
def search(request, search_id=None):
    if request.method == "POST":
        search = Search(user=request.user)
        search_form = SearchForm(request.POST, instance=search)
        if search_form.is_valid():
            saved_search = search_form.save()

            for criterion in request.POST.getlist('criterion'):
                saved_search.criteria.add(Criterion.objects.get_or_create(search_string=criterion)[0])

                for engine in request.POST.getlist('engine'):
                    engine_obj = Engine.objects.get_or_create(name=engine)[0]
                    saved_search.engines.add(engine_obj)
                    results = run(engine, criterion)

                    for result in results:
                        article = Article.objects.get_or_create(title=result['title'], year=result['year'], 
                                                            link=result['link'], authors=result['authors'],
                                                            engine=engine_obj)[0]
                        article.criteria.add(Criterion.objects.get_or_create(search_string=criterion)[0])
                        saved_search.articles.add(article)

            return redirect('search_url', search_id=saved_search.id)
        else:
            return HttpResponse("fail")
    elif request.method == "GET":
        if search_id is None:
            search_list = Search.objects.all()
            search_form = SearchForm()
            engine_list = util.get_engine_titles()

            return render_to_response("djbeagle/home.html",
                        {"search_form"  : search_form,
                        "engine_list"   : engine_list,
                        "search_list"   : search_list},
                        context_instance=RequestContext(request))
        else:
            search = Search.objects.get(pk=search_id)
            return render_to_response("djbeagle/search.html",
                        {'search' : search},
                        context_instance=RequestContext(request))
    elif request.method == 'DELETE':
        search = Search.objects.get(pk=search_id)
        try:
            search.delete()
            response = { 'status' : 'success' }
        except:
            response = { 'status' : 'error' }

        return HttpResponse(json.dumps(response), mimetype="application/json")
Exemple #3
0
 def test_get_engine_titles(self):
     titles = util.get_engine_titles()
     self.assertTrue("Google Scholar" in titles)