Ejemplo n.º 1
0
def actualite_index(request, type='actu'):
    if type == 'appels':
        search_form = AppelSearchForm(request.GET)
        template = "savoirs/appels_index.html"
        try:
            p = PageStatique.objects.get(id='appels')
            entete = p.contenu
        except PageStatique.DoesNotExist:
            entete = "<h1>Appels d'offres scientifiques</h1>"
    else:
        search_form = ActualiteSearchForm(request.GET)
        template = "savoirs/actualite_index.html"
        try:
            p = PageStatique.objects.get(id='actualites')
            entete = p.contenu
        except PageStatique.DoesNotExist:
            entete = '<h1>Actualités</h1>'

    if search_form.is_valid():
        search = search_form.save(commit=False)
    else:
        raise Http404
    actualites = search.run()
    excerpt = excerpt_function(
        Actualite.objects, search_form.cleaned_data['q']
    )

    return render(request, template, {
        'actualites': actualites,
        'search_form': search_form,
        'excerpt': excerpt,
        'nb_resultats': actualites.count(),
        'entete': entete,
    })
Ejemplo n.º 2
0
def recherche(request, discipline=None, region=None):
    query = request.GET.get("q", "")
    if not query.strip():

        # Si on n'a pas de recherche par mots-clés, on redirige vers
        # l'accueil.
        kwargs = {}
        if discipline:
            kwargs['discipline'] = discipline
        if region:
            kwargs['region'] = region
        return redirect('savoirs.views.index', **kwargs)

    # Effectuer la recherche
    discipline_obj = discipline and \
            get_object_or_404(Discipline, pk=discipline)
    region_obj = region and get_object_or_404(Region, pk=region)
    search = Search(q=query, discipline=discipline_obj, region=region_obj)
    results = search.run()

    # Bâtissons une query string pour les liens vers les briques
    params = {}
    if query:
        params['q'] = query
    if discipline:
        params['discipline'] = unicode(discipline)
    if region:
        params['region'] = unicode(region)
    if params:
        briques_query_string = mark_safe(
            '?' + '&'.join(k + '=' + v.replace('"', '&quot;')
                           for (k, v) in params.iteritems())
        )
    else:
        briques_query_string = None

    excerpt = excerpt_function(Record.objects, query)

    return render(request, "savoirs/recherche.html", {
        'q': query,
        'excerpt': excerpt,
        'ressources': results.ressources[0:5],
        'total_ressources': results.ressources.count(),
        'evenements': results.evenements[0:5],
        'total_evenements': results.evenements.count(),
        'chercheurs': results.chercheurs[0:10],
        'total_chercheurs': results.chercheurs.count(),
        'groupes': results.groupes[0:10],
        'total_groupes': results.groupes.count(),
        'actualites': results.actualites[0:5],
        'total_actualites': results.actualites.count(),
        'appels': results.appels[0:5],
        'total_appels': results.appels.count(),
        'sites': results.sites[0:5],
        'total_sites': results.sites.count(),
        'sites_auf': results.sites_auf[0:5],
        'briques_query_string': briques_query_string
    })
Ejemplo n.º 3
0
def evenement_index(request):
    if request.GET.get('q', False) \
       or request.GET.get('type', False) \
       or request.GET.get('date_min', False) \
       or request.GET.get('date_max', False) \
       or request.GET.get('discipline', False) \
       or request.GET.get('region', False):
        search_form = EvenementSearchForm(request.GET)
        if search_form.is_valid():
            search = search_form.save(commit=False)
        else:
            raise Http404
        q = search_form.cleaned_data.get('q', '')

    else:
        today = datetime.date.today()
        search_form = EvenementSearchForm({'date_min': today})
        if search_form.is_valid():
            search = search_form.save(commit=False)
        else:
            raise Http404
        search.date_min = today
        q = ''

    evenements = search.run()
    excerpt = excerpt_function(Evenement.objects, q)

    ordre = request.GET.get('sort', 'soumission')
    if ordre == 'soumission':
        evenements = evenements.order_by('-date_modification')
    else:
        evenements = evenements.order_by('debut')

    try:
        p = PageStatique.objects.get(id='agenda')
        entete = p.contenu
    except PageStatique.DoesNotExist:
        entete = '<h1>Agenda</h1>'

    return render(request, "savoirs/evenement_index.html", {
        'evenements': evenements,
        'search_form': search_form,
        'ordre': ordre,
        'excerpt': excerpt,
        'nb_resultats': evenements.count(),
        'entete': entete,
    })
Ejemplo n.º 4
0
def ressource_index(request):
    search_form = RessourceSearchForm(request.GET)
    if search_form.is_valid():
        search = search_form.save(commit=False)
    else:
        raise Http404
    ressources = search.run()
    nb_resultats = ressources.count()
    excerpt = excerpt_function(Record.objects, search_form.cleaned_data['q'])
    try:
        p = PageStatique.objects.get(id='ressources')
        entete = p.contenu
    except PageStatique.DoesNotExist:
        entete = '<h1>Ressources</h1>'

    return render(request, "savoirs/ressource_index.html", {
        'search_form': search_form,
        'ressources': ressources,
        'nb_resultats': nb_resultats,
        'excerpt': excerpt,
        'entete': entete,
    })