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)
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))
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)
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)))
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)))
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))
def test_export_anonymisation_csv(advice): row = csv.to_anon_row(advice) assert len(row) == 4 assert row[0] == advice.id assert row[1] == url_for('site.display', id=advice.id, _external=True)