Esempio n. 1
0
def main(request):

    criteria = ['mimetype:image/jpeg', '-owner:[* TO *]']
    try:
        criteria.append('allcollections:%d' %
                        Collection.objects.get(name='front-page-content').id)
    except Collection.DoesNotExist:
        pass

    (hits, records, search_facets, orfacet, query, fields) = run_search(
        request.user,
        criteria=criteria,
        sort='random_%d asc' % random.randint(100000, 999999),
        page=1,
        pagesize=8,
        produce_facets=False)

    order = range(1, len(records or []))
    random.shuffle(order)

    request.session.set_test_cookie()
    form = AuthenticationForm()

    if is_mobile(request):
        return HttpResponseRedirect(reverse("mobile-main"))

    return render_to_response('main.html', {
        'records': records,
        'order': [0] + order,
        'login_form': form
    },
                              context_instance=RequestContext(request))
Esempio n. 2
0
def main(request):

    criteria = ['mimetype:image/jpeg', '-owner:[* TO *]']
    try:
        criteria.append('allcollections:%d' %
                        Collection.objects.get(name='front-page-content').id)
    except Collection.DoesNotExist:
        pass

    (hits, records, search_facets, orfacet, query, fields) = run_search(
        request.user,
        criteria=criteria,
        sort='random_%d asc' % random.randint(100000, 999999),
        page=1,
        pagesize=8,
        produce_facets=False)

    order = range(1, len(records or []))
    random.shuffle(order)

    request.session.set_test_cookie()
    form = AuthenticationForm()

    return render_to_response('main.html',
                              {'records': records,
                               'order': [0] + order,
                               'login_form': form},
                              context_instance=RequestContext(request))
Esempio n. 3
0
def search(term, params, off, len):
	off = int(off)
	from rooibos.solr.views import run_search
	sobj = run_search(AnonymousUser(),
		keywords=term,
		sort="title_sort desc",
		page=int(off/len if len > 0 else 0) + 1,
		pagesize=len)
	hits, records = sobj[0:2]
	result = Result(hits, off + len if off + len < hits else None)
	for i in records:
		result.addImage(ResultRecord(i, str(i.id)))
	return result
Esempio n. 4
0
def main(request):

    (hits, records, search_facets, orfacet, query, fields) = run_search(
        request.user,
        criteria=['mimetype:image/jpeg'],
        sort='random_%d asc' % random.randint(100000, 999999),
        page=1,
        pagesize=8,
        produce_facets=False)

    order = range(1, 8)
    random.shuffle(order)

    return render_to_response('main.html',
                              {'records': records,
                               'order': [0] + order},
                              context_instance=RequestContext(request))
Esempio n. 5
0
def search(request):

    collection = Collection.objects.get(name='shenandoah-national-park')
    q = request.GET.get('q', '')
    try:
        p = int(request.GET.get('p', 1))
    except ValueError:
        p = 1

    f = request.GET.get('f')
    v = request.GET.get('v')

    if f and v:

        records = [fv.record for fv in FieldValue.objects.select_related('record').filter(record__collection=collection,
                                  label=f,
                                  value=v)]

        prev_page = next_page = hits = None

    else:

        (hits, records, search_facets, orfacet, query, fields) = run_search(
            request.user,
            keywords=q,
            criteria=['allcollections:%d' % collection.id],
            sort='subject_sort asc',
            page=p,
            pagesize=20,
            produce_facets=False)

        prev_page = max(1, p - 1)
        next_page = min(p + 1, (hits - 1) / 20 + 1) if hits > 0 else 1

    results = []

    for record in records:

        mapping = {'Interviewee': 'interviewee',
                   'Identifier': 'interview_number',
                   'Location/Date': 'location_date',
                   'Description': 'description',
                   'Interviewer/Transcriber': 'interviewer_transcriber',
                   'Status': 'status',
                   }

        result = dict()

        for fv in record.get_fieldvalues():
            if mapping.has_key(fv.resolved_label):
                result[mapping[fv.resolved_label]] = fv.value

        results.append(result)


    return render_to_response('snp-search.html',
                              { 'results': results,
                                'query': q,
                                'prev_page': prev_page,
                                'next_page': next_page,
                                'hits': hits,
                               },
                              context_instance=RequestContext(request))
Esempio n. 6
0
def search(request):

    collection = Collection.objects.get(name='shenandoah-national-park')
    q = request.GET.get('q', '')
    try:
        p = int(request.GET.get('p', 1))
    except ValueError:
        p = 1

    f = request.GET.get('f')
    v = request.GET.get('v')

    if f and v:

        records = [
            fv.record
            for fv in FieldValue.objects.select_related('record').filter(
                record__collection=collection, label=f, value=v)
        ]

        prev_page = next_page = hits = None

    else:

        (hits, records, search_facets, orfacet, query,
         fields) = run_search(request.user,
                              keywords=q,
                              criteria=['allcollections:%d' % collection.id],
                              sort='subject_sort asc',
                              page=p,
                              pagesize=20,
                              produce_facets=False)

        prev_page = max(1, p - 1)
        next_page = min(p + 1, (hits - 1) / 20 + 1) if hits > 0 else 1

    results = []

    for record in records:

        mapping = {
            'Interviewee': 'interviewee',
            'Identifier': 'interview_number',
            'Location/Date': 'location_date',
            'Description': 'description',
            'Interviewer/Transcriber': 'interviewer_transcriber',
            'Status': 'status',
        }

        result = dict()

        for fv in record.get_fieldvalues():
            if mapping.has_key(fv.resolved_label):
                result[mapping[fv.resolved_label]] = fv.value

        results.append(result)

    return render_to_response('snp-search.html', {
        'results': results,
        'query': q,
        'prev_page': prev_page,
        'next_page': next_page,
        'hits': hits,
    },
                              context_instance=RequestContext(request))