def visitors_export():
    filters_, _, _, _ = utilities.get_filters_order_by_limit_page(
        'visitors',
        {},
        {
            'column': 'timestamp',
            'direction': 'desc',
        },
        10,
        1
    )
    csv = StringIO()
    writer(
        csv,
        delimiter=',',
        doublequote=True,
        lineterminator='\n',
        quotechar='"',
        quoting=QUOTE_ALL,
        skipinitialspace=True
    ).writerows([[
        'ID',
        'Email',
        'Timestamp',
    ]] + [
        [
            visitor.id,
            visitor.email,
            visitor.timestamp.isoformat(' '),
        ]
        for visitor in filters.visitors(
            **filters_
        ).apply(
            g.mysql.query(models.visitor)
        ).order_by('timestamp DESC').all()
    ])
    return Response(
        csv.getvalue(),
        headers={
            'Content-Disposition': 'attachment; filename=export.csv',
        },
        mimetype='text/csv',
    )
def visitors_overview():
    filters_, order_by, limit, page = utilities.get_filters_order_by_limit_page(
        'visitors',
        {},
        {
            'column': 'timestamp',
            'direction': 'desc',
        },
        10,
        1
    )
    form = filters.visitors(**filters_)
    query = form.apply(g.mysql.query(models.visitor))
    pager = classes.pager(query.count(), limit, page)
    return render_template(
        'administrators/views/visitors_overview.html',
        form=form,
        order_by=order_by,
        pager=pager,
        visitors=query.order_by('%(column)s %(direction)s' % order_by).all()[pager.prefix:pager.suffix],
    )