Ejemplo n.º 1
0
def index(page = 1):

    samples = []
    es_samples = None
    page_offset = (app.config.get('ITEMS_PER_PAGE')*(page-1))
    sample_count = 0

    try:
        if 'search' in request.args:
            # @@ FIXME <- INJECTION PRONE!!!
            query = request.args['search']
            sample_count = es.count(query)
            if sample_count > 0:
                es_samples = es.lucene_search(query, start=page_offset, size=app.config.get('ITEMS_PER_PAGE'))
        else:
            sample_count = es.count()
            if sample_count > 0:
                es_samples = es.all(size=app.config.get('ITEMS_PER_PAGE'), start=page_offset)

                for s in es_samples['hits']['hits']:
                    samples.append(s['_source'])
    except TransportError:
        flash(gettext('Error querying ElasticSearch database. Please check configuration.'))

    page_count = int(ceil(sample_count/app.config.get('ITEMS_PER_PAGE')))
    if page_count <= 1:
        page_count = 1
    pages = range(1, page_count+1)
    return render_template('samples/index.html', sample_count=sample_count, samples=samples, pages=pages, page=page)
Ejemplo n.º 2
0
def index():

    samples = []
    sample_count = {
        'total': 0,
        'new': 0,
        'processing': 0,
        'ready': 0,
    }
    submissions = []
    submission_samples = []

    try:
        # Overall Counts
        sample_count = {
            'total': es.count(),
            'new': es.count('status:%d' % SAMPLE_STATUS_NEW),
            'processing': es.count('status:%d' % SAMPLE_STATUS_PROCESSING),
            'ready': es.count('status:%d' % SAMPLE_STATUS_PROCESSED),
        }

        # Latest submissions
        update_submissions(current_user.id)
        submissions = current_user.submissions.order_by(
            Submission.timestamp.desc()).limit(15).all()
        submission_samples = {}

        for item in submissions:
            if item.sample_uuid:
                submission_samples[item.sample_uuid] = es.get(item.sample_uuid)

        # Latest samples
        if sample_count['total'] > 0:
            es_samples = es.all(size=15)

            for s in es_samples['hits']['hits']:
                samples.append(s['_source'])

    except TransportError:
        flash(
            gettext(
                'Error querying ElasticSearch database. Please check configuration.'
            ))

    return render_template('general/index.html',
                           sample_count=sample_count,
                           submissions=submissions,
                           submission_samples=submission_samples,
                           samples=samples)
Ejemplo n.º 3
0
def index():

    samples = []
    sample_count = {
        'total': 0,
        'new':  0,
        'processing':  0,
        'ready':  0,
    }
    submissions = []
    submission_samples = []

    try:
        # Overall Counts
        sample_count = {
            'total': es.count(),
            'new':  es.count('status:%d' % SAMPLE_STATUS_NEW),
            'processing':  es.count('status:%d' % SAMPLE_STATUS_PROCESSING),
            'ready':  es.count('status:%d' % SAMPLE_STATUS_PROCESSED),
        }

        # Latest submissions
        update_submissions(current_user.id)
        submissions = current_user.submissions.order_by(Submission.timestamp.desc()).limit(15).all()
        submission_samples = {}

        for item in submissions:
            if item.sample_uuid:
                submission_samples[item.sample_uuid] = es.get(item.sample_uuid)

        # Latest samples
        if sample_count['total'] > 0:
            es_samples = es.all(size=15)

            for s in es_samples['hits']['hits']:
                samples.append(s['_source'])

    except TransportError:
        flash(gettext('Error querying ElasticSearch database. Please check configuration.'))

    return render_template('general/index.html', sample_count=sample_count, submissions=submissions, submission_samples=submission_samples, samples=samples)
Ejemplo n.º 4
0
def index(page=1):

    samples = []
    es_samples = None
    page_offset = (app.config.get('ITEMS_PER_PAGE') * (page - 1))
    sample_count = 0

    try:
        if 'search' in request.args:
            # @@ FIXME <- INJECTION PRONE!!!
            query = request.args['search']
            sample_count = es.count(query)
            if sample_count > 0:
                es_samples = es.lucene_search(
                    query,
                    start=page_offset,
                    size=app.config.get('ITEMS_PER_PAGE'))
        else:
            sample_count = es.count()
            if sample_count > 0:
                es_samples = es.all(size=app.config.get('ITEMS_PER_PAGE'),
                                    start=page_offset)

                for s in es_samples['hits']['hits']:
                    samples.append(s['_source'])
    except TransportError:
        flash(
            gettext(
                'Error querying ElasticSearch database. Please check configuration.'
            ))

    page_count = int(ceil(sample_count / app.config.get('ITEMS_PER_PAGE')))
    if page_count <= 1:
        page_count = 1
    pages = range(1, page_count + 1)
    return render_template('samples/index.html',
                           sample_count=sample_count,
                           samples=samples,
                           pages=pages,
                           page=page)