Report who the site managers are for the BCC
authorDiane Trout <diane@caltech.edu>
Tue, 1 Sep 2009 23:03:01 +0000 (23:03 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 1 Sep 2009 23:03:01 +0000 (23:03 +0000)
also include the affiliations email as one of the entities being notified
about a library.

htsworkflow/frontend/experiments/experiments.py
htsworkflow/frontend/experiments/views.py
htsworkflow/frontend/templates/experiments/email_preview.html

index cfea75f895e31ca2fcb2c4aba2559f768678e337..5b7019343b698f28d68cb874627bc856bb8bae7b 100755 (executable)
@@ -217,7 +217,17 @@ def makeUserLaneMap(flowcell):
 
     return users
 
-def makeUserLibrarMap(libraries):
+def getUsersForFlowcell(flowcell):
+    users = set()
+    
+    for lane in flowcell.lane_set.all():
+        for affiliation in lane.library.affiliations.all():
+            for user in affiliation.users.all():
+                users.add(user)
+                
+    return users
+    
+def makeUserLibraryMap(libraries):
     """
     Given an interable set of libraries return a mapping or
     users interested in those libraries.
@@ -230,3 +240,29 @@ def makeUserLibrarMap(libraries):
                 users.setdefault(user,[]).append(library)
                 
     return users
+
+def makeAffiliationLaneMap(flowcell):
+    affs = {}
+
+    for lane in flowcell.lane_set.all():
+        for affiliation in lane.library.affiliations.all():
+            affs.setdefault(affiliation,[]).append(lane)
+
+    return affs
+
+def makeEmailLaneMap(flowcell):
+    """
+    Create a list of email addresses and the lanes associated with those users.
+
+    The email addresses can come from both the "users" table and the "affiliations" table.
+    """
+    emails = {}
+    for lane in flowcell.lane_set.all():
+        for affiliation in lane.library.affiliations.all():
+            if affiliation.email is not None and len(affiliation.email) > 0:
+                emails.setdefault(affiliation.email,set()).add(lane)
+            for user in affiliation.users.all():
+                if user.email is not None and len(user.email) > 0:
+                    emails.setdefault(user.email,set()).add(lane)
+
+    return emails
index 92f6cbd9227bcffa2eb465177f4d226c3ccc30ba..71266ab96a03c19369bbb3653b7b91511b4bbd04 100755 (executable)
@@ -12,7 +12,8 @@ from django.template.loader import get_template
 from htsworkflow.frontend.experiments.models import *
 from htsworkflow.frontend.experiments.experiments import \
      estimateFlowcellDuration, \
-     makeUserLaneMap
+     getUsersForFlowcell, \
+     makeEmailLaneMap
 
 def index(request):
     all_runs = DataRun.objects.order_by('-run_start_time')
@@ -61,7 +62,8 @@ def startedEmail(request, pk):
     else:
         bcc_managers = False
 
-    user_lane = makeUserLaneMap(fc)
+    email_lane = makeEmailLaneMap(fc)
+    flowcell_users = getUsersForFlowcell(fc)
     estimate_low, estimate_high = estimateFlowcellDuration(fc)
     email_verify = get_template('experiments/email_preview.html')
     email_template = get_template('experiments/started_email.html')
@@ -69,49 +71,44 @@ def startedEmail(request, pk):
 
     warnings = []
     emails = []
+
+    emailless_users = []
+    for user in flowcell_users:
+        # provide warning
+        if user.email is None or len(user.email) == 0:
+            warnings.append((user.admin_url(), user.username))
+    user=None
     
-    for user in user_lane.keys():
+    for user_email in email_lane.keys():
         sending = ""
         # build body
         context = Context({u'flowcell': fc,
-                   u'lanes': user_lane[user],
+                   u'lanes': email_lane[user_email],
                    u'runfolder': 'blank',
                    u'finish_low': estimate_low,
                    u'finish_high': estimate_high,
-                   u'user_admin': user.admin_url(),
                   })
 
         # build view
         subject = "Flowcell  %s" % ( fc.flowcell_id )
         body = email_template.render(context)
 
-        # provide warning
-        has_email = True
-        if user.email is None or len(user.email) == 0:
-            warnings.append((user.admin_url(), user.username))
-            has_email = False
-            
         if send:
-            if has_email:
-                email = EmailMessage(subject, body, sender, to=[user.email])
-                if bcc_managers:
-                    print 'bcc_managers', bcc_managers
-                    email.bcc = settings.MANAGERS
-                print email.to, email.bcc
-                email.send()
-                sending = "sent"
-            else:
-                print settings.MANAGERS
-                mail_managers("Couldn't send to "+user.username, body)
-                sending = "bounced to managers"
+            email = EmailMessage(subject, body, sender, to=[user_email])
+            if bcc_managers:
+                print 'bcc_managers', bcc_managers
+                email.bcc = settings.MANAGERS
+            print email.to, email.bcc
+            email.send()
 
-        emails.append((user.email, subject, body, sending))
+        emails.append((user_email, subject, body, sending))
 
     verify_context = Context({
         'send': send,
         'warnings': warnings,
         'emails': emails,
         'from': sender,
+        'site_managers': settings.MANAGERS,
         })
     return HttpResponse(email_verify.render(verify_context))
     
index a045c74ca9fc16fd37efffa90706e018625d861d..6cbc065ac73b6ec038c67f6fde8d35432b1f5373 100644 (file)
@@ -18,7 +18,7 @@ email address <br/>
 {{ body }}
 {% endfor %}<hr/>
 <form method="get">
-<label for="bcc">BCC Managers?</label>
+<label for="bcc">BCC {% for m in site_managers %}{{ m }} {% endfor %}</label>
 <input type="checkbox" id="bcc" name="bcc" checked="on"/><br/>
 <input type="hidden" name="send" value="1"/>
 <input type="submit" value="Send Email"/>