X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=main.py;h=7df6af3d4f54b64813ce4d7aeda9c65bad96008d;hb=d2ce3749c6a729861fac51c2f4e4dc32916f97bc;hp=fde382fbfdf05939073b81202443ab305f6d62f5;hpb=ce16da78f97de079b797276db9d1248507f996dd;p=cavote.git diff --git a/main.py b/main.py index fde382f..7df6af3 100755 --- a/main.py +++ b/main.py @@ -3,16 +3,21 @@ from flask import Flask, request, session, g, redirect, url_for, abort, \ render_template, flash -from gettext import gettext +from gettext import translation +import locale +import os + +current_locale, encoding = locale.getdefaultlocale() +locale_path = 'translations/' +language = translation('messages', locale_path, [current_locale]) +gettext = language.ugettext + #from flask_openid import OpenID #from flaskext.babel import Babel, gettext, ngettext import sqlite3 from datetime import date, time, timedelta, datetime import time from contextlib import closing -import locale -locale.setlocale(locale.LC_ALL, '') -import os import hashlib import smtplib import string @@ -757,7 +762,6 @@ def admin_vote_edit(voteid): vote = query_db('select * from votes where id = ?', [voteid], one=True) if vote is None: abort(404) - print "\nvote: %s\n" % str(vote) if request.method == 'POST': if request.form['title']: if request.form['days'] > 0: @@ -771,33 +775,39 @@ def admin_vote_edit(voteid): public = 1 isopen = 0 isterminated = 0 + print "POST" if request.form['status'] == 'Ouvert': - choices = query_db('select id_vote, count(*) as nb \ - from choices where id_vote = ? \ + choices = query_db('select id_vote, count(*) as nb, groups.name as group_name \ + from choices \ + join votes on votes.id = choices.id_vote \ + join groups on groups.id = votes.id_group \ + where id_vote = ? \ group by id_vote', [voteid], one=True) if choices is not None and choices['nb'] >= 1: isopen = 1 previousvote = query_db('select id, is_open, id_group from votes where id = ?', [voteid], one=True) - if previousvote is None or previousvote['is_open'] == 0: + if (previousvote is None or previousvote['is_open'] == 0) and 'mail_notice' in request.form: users_to_vote = query_db('select users.email, users.name from users \ join user_group on users.id=user_group.id_user \ where user_group.id_group = ?', [previousvote['id_group']]) for user in users_to_vote: link = request.url_root + url_for('vote', idvote=voteid) BODY = string.join(( - "From: %s" % EMAIL, - "To: %s" % user['email'], - "Subject: [Cavote] %s" % gettext(u"A vote has been opened for your group"), - "Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()).decode('utf-8'), - "Content-type: text/plain; charset=utf-8", - "X-Mailer: %s" % VERSION, - "", - "%(text)s %(title)s" % {"text": gettext(u"A vote has been opened and you are in a group concerned by it :"), "title": request.form['title']}, + u"From: %s" % EMAIL, + u"To: %s" % user['email'], + u"Subject: [vote] [%s] %s" % (choices['group_name'], request.form['title']), + u"Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()).decode('utf-8'), + u"Content-type: text/plain; charset=utf-8", + u"X-Mailer: %s" % VERSION, "", - gettext(u"This link will bring you to the form where you will be able to vote :"), + u"%(text0)s%(group)s" % \ + { "text0":gettext(u"A new vote concerns you within the group: ") \ + , "group":choices['group_name'] }, \ link, "", - gettext(u"If you think this mail is not for you, please ignore and delete it.") + gettext(u"If you think this mail is not for you, please ignore and delete it."), + gettext(u"For more informations, you can contact:"), + EMAIL ), "\r\n") server = smtplib.SMTP(SMTP_SERVER) server.sendmail(EMAIL, [user['email']], BODY.encode('utf-8'))