コード例 #1
0
ファイル: views.py プロジェクト: pborreli/cada
    def generate():
        csvfile = StringIO.StringIO()
        writer = csv.writer(csvfile)
        # Generate header
        writer.writerow(csv.HEADER)
        yield csvfile.getvalue()

        for advice in Advice.objects.order_by('id'):
            csvfile = StringIO.StringIO()
            writer = csv.writer(csvfile)
            writer.writerow(csv.to_row(advice))
            yield csvfile.getvalue()
コード例 #2
0
ファイル: views.py プロジェクト: psorianom/cada
    def generate():
        csvfile = io.StringIO()
        writer = csv.writer(csvfile)
        # Generate header
        writer.writerow(csv.HEADER)
        yield csvfile.getvalue()

        for advice in Advice.objects.order_by('id'):
            csvfile = io.StringIO()
            writer = csv.writer(csvfile)
            writer.writerow(csv.to_row(advice))
            yield csvfile.getvalue()
コード例 #3
0
ファイル: commands.py プロジェクト: AntoineAugusti/cada
def anon():
    '''Check for candidates to anonymization'''
    header(anon.__doc__)
    filename = 'urls_to_check.csv'

    candidates = Advice.objects(
        __raw__={
            '$or': [{
                'subject': {
                    '$regex':
                    '(Monsieur|Madame|Docteur|Mademoiselle)\s+[^X\s\.]{3}',
                    '$options': 'imx',
                }
            }, {
                'content': {
                    '$regex':
                    '(Monsieur|Madame|Docteur|Mademoiselle)\s+[^X\s\.]{3}',
                    '$options': 'imx',
                }
            }]
        })

    with open(filename, 'wb') as csvfile:
        writer = csv.writer(csvfile)
        # Generate header
        writer.writerow(csv.ANON_HEADER)

        for idx, advice in enumerate(candidates, 1):
            writer.writerow(csv.to_anon_row(advice))
            echo('.' if idx % 50 else white(idx), nl=False)
        echo(white(idx) if idx % 50 else '')

    success('Total: {0} candidates', len(candidates))
コード例 #4
0
ファイル: views.py プロジェクト: pborreli/cada
def alert(id):
    advice = Advice.objects.get_or_404(id=id)
    form = AlertAnonForm()
    if form.validate_on_submit():
        csvfile = StringIO.StringIO()
        writer = csv.writer(csvfile)
        writer.writerow(csv.ANON_HEADER)
        writer.writerow(csv.to_anon_row(advice))
        attachment = Attachment(
            'cada-fix-{0}.csv'.format(advice.id),
            'text/csv',
            csvfile.getvalue()
        )
        mail.send_message("Défaut d'anonymisation sur l'avis CADA {0}".format(advice.id),
            recipients=[app.config['ANON_ALERT_MAIL']],
            html=render_template('anon_alert_mail.html', advice=advice, details=form.details.data),
            attachments=[attachment]
        )
        flash(
            "<strong>Merci pour voter contribution!</strong> Nous avons bien pris en compte votre signalement.",
            'success'
        )
        return redirect(url_for('display', id=advice.id))
    else:
        abort(400)
コード例 #5
0
ファイル: views.py プロジェクト: AntoineAugusti/cada
def alert(id):
    advice = Advice.objects.get_or_404(id=id)
    form = AlertAnonForm()
    if form.validate_on_submit():
        csvfile = StringIO.StringIO()
        writer = csv.writer(csvfile)
        writer.writerow(csv.ANON_HEADER)
        writer.writerow(csv.to_anon_row(advice))
        attachment = Attachment(
            'cada-fix-{0}.csv'.format(advice.id),
            'text/csv',
            csvfile.getvalue()
        )
        mail.send_message("Défaut d'anonymisation sur l'avis CADA {0}".format(advice.id),
                          recipients=[current_app.config['ANON_ALERT_MAIL']],
                          html=render_template('anon_alert_mail.html', advice=advice, details=form.details.data),
                          attachments=[attachment]
                          )
        flash(
            "<strong>Merci pour votre contribution!</strong> Nous avons bien pris en compte votre signalement.",
            'success'
        )
        return redirect(url_for('site.display', id=advice.id))
    else:
        abort(400)
コード例 #6
0
ファイル: commands.py プロジェクト: gitter-badger/cada
def anon():
    '''Check for candidates to anonymization'''
    filename = 'urls_to_check.csv'

    candidates = Advice.objects(
        __raw__={
            '$or': [{
                'subject': {
                    '$regex':
                    '(Monsieur|Madame|Docteur|Mademoiselle)\s+[^X\s\.]{3}',
                    '$options': 'imx',
                }
            }, {
                'content': {
                    '$regex':
                    '(Monsieur|Madame|Docteur|Mademoiselle)\s+[^X\s\.]{3}',
                    '$options': 'imx',
                }
            }]
        })

    with open(filename, 'wb') as csvfile:
        writer = csv.writer(csvfile)
        # Generate header
        writer.writerow(csv.ANON_HEADER)

        for idx, advice in enumerate(candidates):
            writer.writerow(csv.to_anon_row(advice))
            print('.' if idx % 50 else idx, end='')
        print('')

    print('Total: {0} candidates'.format(len(candidates)))
コード例 #7
0
ファイル: commands.py プロジェクト: pborreli/cada
def anon():
    '''Check for candidates to anonymization'''
    filename = 'urls_to_check.csv'

    candidates = Advice.objects(__raw__={
        '$or': [
            {'subject': {
                '$regex': '(Monsieur|Madame|Docteur|Mademoiselle)\s+[^X\s\.]{3}',
                '$options': 'imx',
            }},
            {'content': {
                '$regex': '(Monsieur|Madame|Docteur|Mademoiselle)\s+[^X\s\.]{3}',
                '$options': 'imx',
            }}
        ]
    })

    with open(filename, 'wb') as csvfile:
        writer = csv.writer(csvfile)
        # Generate header
        writer.writerow(csv.ANON_HEADER)

        for idx, advice in enumerate(candidates):
            writer.writerow(csv.to_anon_row(advice))
            print('.' if idx % 50 else idx, end='')
        print('')

    print('Total: {0} candidates'.format(len(candidates)))
コード例 #8
0
ファイル: commands.py プロジェクト: etalab/cada
def anon():
    '''Check for candidates to anonymization'''
    header(anon.__doc__)
    filename = 'urls_to_check.csv'

    candidates = Advice.objects(__raw__={
        '$or': [
            {'subject': {
                '$regex': '(Monsieur|Madame|Docteur|Mademoiselle)\s+[^X\s\.]{3}',
                '$options': 'imx',
            }},
            {'content': {
                '$regex': '(Monsieur|Madame|Docteur|Mademoiselle)\s+[^X\s\.]{3}',
                '$options': 'imx',
            }}
        ]
    })

    with open(filename, 'wb') as csvfile:
        writer = csv.writer(csvfile)
        # Generate header
        writer.writerow(csv.ANON_HEADER)

        for idx, advice in enumerate(candidates, 1):
            writer.writerow(csv.to_anon_row(advice))
            echo('.' if idx % 50 else white(idx), nl=False)
        echo(white(idx) if idx % 50 else '')

    success('Total: {0} candidates', len(candidates))