Commits

Virgil Dupras  committed 10517fa

Added the change_email utility.

  • Participants
  • Parent commits 272d09d

Comments (0)

Files changed (3)

File change_email.py

+import sys
+
+from .env import Session
+from .model import Contributor
+
+def main(oldemail, newemail):
+    session = Session()
+    contributor = session.query(Contributor).filter_by(email=oldemail).one()
+    print("Contributor found. ID: {} Name: {}".format(contributor.id, contributor.fullname))
+    contributor.email = newemail
+    session.commit()
+    for contrib in contributor.contributions:
+        project = contrib.project
+        print("{} - {} - {} <{}> ({:0.2f}) --> {}".format(contrib.date, project.name,
+            contributor.fullname, contributor.email, contrib.gross_amount/100,
+            contrib.getkey()))
+    
+if __name__ == '__main__':
+    oldemail, newemail = sys.argv[1:]
+    main(oldemail, newemail)
         session.delete(self)
         session.commit()
     
+    def getkey(self):
+        payer_email = self.contributor.email
+        allcontribs = list(self.contributor.contributions)
+        seq = allcontribs.index(self)
+        blob = str(self.project_id) + payer_email + str(seq) + 'aybabtu'
+        return hashlib.md5(blob.encode('utf-8')).hexdigest()
+    
     @property
     def unallocated(self):
         allocated = sum((a.amount for a in self.allocations), 0)

File sendemail.py

 import sys
-from hashlib import md5
 
 from .env import Session, tmplenv, sendmail
 from .model import Contribution
     contrib = session.query(Contribution).filter_by(id=contribid).one()
     contributor = contrib.contributor
     project = contrib.project
-    payer_email = contrib.contributor.email
-    seq = len(contributor.contributions)
-    blob = str(project.id) + payer_email + str(seq) + 'aybabtu'
-    new_key = md5(blob.encode('utf-8')).hexdigest()
+    payer_email = contributor.email
+    new_key = contrib.getkey()
     
     template = tmplenv.get_template('email_buy.txt')
     rendered = template.render(first_name='', email=payer_email,