Send a main when opening a vote
authorArnaud Delcasse <arnaud@delcasse.fr>
Tue, 11 Sep 2012 22:30:41 +0000 (00:30 +0200)
committerArnaud Delcasse <arnaud@delcasse.fr>
Tue, 11 Sep 2012 22:30:41 +0000 (00:30 +0200)
main.py
schema_0.2.X_to_0.3.X.sql [new file with mode: 0644]
templates/admin_vote_edit.html

diff --git a/main.py b/main.py
index fc18674..e70d72d 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -598,14 +598,36 @@ def admin_vote_edit(voteid):
                 choices = query_db('select id_vote, count(*) as nb from choices where id_vote = ? group by id_vote', [voteid], one=True)
                 if choices is not None and choices['nb'] >= 2:
                     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:
+                        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] 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'),
+                                "X-Mailer: %s" % VERSION,
+                                "",
+                                "A vote has been opened and you are in a group concerned by it : %s" % request.form['title'],
+                                "",
+                                "This link will bring you to the form where you will be able to vote :",
+                                link,
+                                "",
+                                "If you think this mail is not for you, please ignore and delete it."
+                                ), "\r\n")
+                            server = smtplib.SMTP(SMTP_SERVER)
+                            server.sendmail(EMAIL, [user['email']], BODY)
+                            server.quit()
                 else:
                     flash(u'Vous devez proposer au moins deux choix pour ouvrir le vote.', 'error')
             elif request.form['status'] == u'Terminé':
                 isterminated = 1
                 if vote['is_open']:
                     isopen = 1
-            g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ?, is_terminated = ?, date_end = ? where id = ?',
-                    [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, isterminated, date_end, voteid])
+            g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ?, is_terminated = ?, date_end = ?, reminder_last_days = ? where id = ?',
+                    [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, isterminated, date_end, request.form['reminder'], voteid])
             g.db.commit()
             vote = query_db('select * from votes where id = ?', [voteid], one=True)
             flash(u"Le vote a bien été mis à jour.", "success")
diff --git a/schema_0.2.X_to_0.3.X.sql b/schema_0.2.X_to_0.3.X.sql
new file mode 100644 (file)
index 0000000..1ffa657
--- /dev/null
@@ -0,0 +1,2 @@
+ALTER TABLE votes
+ADD reminder_last_days INTEGER DEFAULT 3 NOT NULL;
index 85c38fa..42eef08 100644 (file)
                   <span class="help-inline">Du {{ vote.date_begin }} au {{ vote.date_end }}</span>
                 </div>
               </div>
+              <div class="control-group">
+                <label class="control-label" for="reminder">Rappel par mail les</label>
+                <div class="controls">
+                  <select class="span1" name="reminder" id="reminder">
+                    {% for i in range(1, 31) %}
+                    {% if i == vote.reminder_last_days %}
+                    <option selected>{{ i }}</option>
+                    {% else %}
+                    <option>{{ i }}</option>
+                    {% endif %}
+                    {% endfor %}
+                  </select>
+                  <span class="help-inline">derniers jours</span>
+                </div>
+              </div>
             </div>
           </div>
         </div>