details: http://www.bx.psu.edu/hg/galaxy/rev/bb2f3963136d changeset: 3648:bb2f3963136d user: rc date: Wed Apr 14 11:21:00 2010 -0400 description: lims: added email notification on request completion diffstat: lib/galaxy/model/__init__.py | 3 +- lib/galaxy/model/mapping.py | 1 + lib/galaxy/model/migrate/versions/0044_add_notify_column_to_request_table.py | 24 +++++++++ lib/galaxy/web/controllers/requests.py | 18 ++++++- lib/galaxy/web/controllers/requests_admin.py | 26 +++++++++- 5 files changed, 69 insertions(+), 3 deletions(-) diffs (205 lines): diff -r f905e1415dd4 -r bb2f3963136d lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Wed Apr 14 10:20:32 2010 -0400 +++ b/lib/galaxy/model/__init__.py Wed Apr 14 11:21:00 2010 -0400 @@ -1402,12 +1402,13 @@ REJECTED = 'Rejected', COMPLETE = 'Complete' ) def __init__(self, name=None, desc=None, request_type=None, user=None, - form_values=None): + form_values=None, notify=None): self.name = name self.desc = desc self.type = request_type self.values = form_values self.user = user + self.notify = notify self.samples_list = [] def state(self): if self.events: diff -r f905e1415dd4 -r bb2f3963136d lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py Wed Apr 14 10:20:32 2010 -0400 +++ b/lib/galaxy/model/mapping.py Wed Apr 14 11:21:00 2010 -0400 @@ -641,6 +641,7 @@ Column( "update_time", DateTime, default=now, onupdate=now ), Column( "name", TrimmedString( 255 ), nullable=False ), Column( "desc", TEXT ), + Column( "notify", Boolean, default=False ), Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ), Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), index=True ), Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), diff -r f905e1415dd4 -r bb2f3963136d lib/galaxy/model/migrate/versions/0044_add_notify_column_to_request_table.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/galaxy/model/migrate/versions/0044_add_notify_column_to_request_table.py Wed Apr 14 11:21:00 2010 -0400 @@ -0,0 +1,24 @@ +""" +Migration script to add a notify column to the request table. +""" + +from sqlalchemy import * +from migrate import * +from migrate.changeset import * + +import logging +log = logging.getLogger( __name__ ) + +metadata = MetaData( migrate_engine ) + +def upgrade(): + print __doc__ + metadata.reflect() + + Request_table = Table( "request", metadata, autoload=True ) + c = Column( "notify", Boolean, default=False ) + c.create( Request_table ) + assert c is Request_table.c.notify + +def downgrade(): + pass diff -r f905e1415dd4 -r bb2f3963136d lib/galaxy/web/controllers/requests.py --- a/lib/galaxy/web/controllers/requests.py Wed Apr 14 10:20:32 2010 -0400 +++ b/lib/galaxy/web/controllers/requests.py Wed Apr 14 11:21:00 2010 -0400 @@ -209,6 +209,7 @@ request_details.append(dict(label='Type', value=request.type.name, helptext='')) + request_details.append(dict(label='State', value=request.state(), helptext='')) @@ -235,6 +236,13 @@ request_details.append(dict(label=field['label'], value=request.values.content[index], helptext=field['helptext']+' ('+req+')')) + if request.notify: + notify = 'Yes' + else: + notify = 'No' + request_details.append(dict(label='Send email notification once the sequencing request is complete', + value=notify, + helptext='')) return request_details def __show_request(self, trans, **kwd): params = util.Params( kwd ) @@ -707,6 +715,9 @@ util.restore_text( params.get( 'desc', '' ) )), helptext='(Optional)')) widgets = widgets + request_type.request_form.get_widgets( trans.user, **kwd ) + widgets.append(dict(label='Send email notification once the sequencing request is complete', + widget=CheckboxField('email_notify', False), + helptext='')) return trans.fill_template( '/requests/new_request.mako', select_request_type=select_request_type, request_type=request_type, @@ -755,6 +766,7 @@ request_type = trans.sa_session.query( trans.app.model.RequestType ).get( int( params.select_request_type ) ) name = util.restore_text(params.get('name', '')) desc = util.restore_text(params.get('desc', '')) + notify = CheckboxField.is_checked( params.get('email_notify', '') ) # library try: library = trans.sa_session.query( trans.app.model.Library ).get( int( params.get( 'library_id', None ) ) ) @@ -801,7 +813,7 @@ trans.sa_session.flush() if not request: request = trans.app.model.Request(name, desc, request_type, - trans.user, form_values) + trans.user, form_values, notify) trans.sa_session.add( request ) trans.sa_session.flush() trans.sa_session.refresh( request ) @@ -816,6 +828,7 @@ request.type = request_type request.user = trans.user request.values = form_values + request.notify = notify trans.sa_session.add( request ) trans.sa_session.flush() return request @@ -896,6 +909,9 @@ widget=TextField('desc', 40, desc), helptext='(Optional)')) widgets = widgets + request.type.request_form.get_widgets( trans.user, request.values.content, **kwd ) + widgets.append(dict(label='Send email notification once the sequencing request is complete', + widget=CheckboxField('email_notify', request.notify), + helptext='')) return trans.fill_template( '/requests/edit_request.mako', select_request_type=select_request_type, request_type=request.type, diff -r f905e1415dd4 -r bb2f3963136d lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Wed Apr 14 10:20:32 2010 -0400 +++ b/lib/galaxy/web/controllers/requests_admin.py Wed Apr 14 11:21:00 2010 -0400 @@ -362,6 +362,9 @@ widget=TextField('desc', 40, desc), helptext='(Optional)')) widgets = widgets + request.type.request_form.get_widgets( request.user, request.values.content, **kwd ) + widgets.append(dict(label='Send email notification once the sequencing request is complete', + widget=CheckboxField('email_notify', request.notify), + helptext='')) return trans.fill_template( '/admin/requests/edit_request.mako', select_request_type=select_request_type, request_type=request.type, @@ -633,6 +636,9 @@ util.restore_text( params.get( 'desc', '' ) )), helptext='(Optional)')) widgets = widgets + request_type.request_form.get_widgets( user, **kwd ) + widgets.append(dict(label='Send email notification once the sequencing request is complete', + widget=CheckboxField('email_notify', False), + helptext='Email would be sent to the lab admin and the user for whom this request has been created.')) return trans.fill_template( '/admin/requests/new_request.mako', select_request_type=select_request_type, request_type=request_type, @@ -694,6 +700,7 @@ user = trans.sa_session.query( trans.app.model.User ).get( int( params.get( 'select_user', '' ) ) ) name = util.restore_text(params.get('name', '')) desc = util.restore_text(params.get('desc', '')) + notify = CheckboxField.is_checked( params.get('email_notify', '') ) # fields values = [] for index, field in enumerate(request_type.request_form.fields): @@ -728,7 +735,7 @@ trans.sa_session.flush() if not request: request = trans.app.model.Request(name, desc, request_type, - user, form_values) + user, form_values, notify) trans.sa_session.add( request ) trans.sa_session.flush() trans.sa_session.refresh( request ) @@ -745,6 +752,7 @@ request.desc = desc request.type = request_type request.user = user + request.notify = notify request.values = form_values trans.sa_session.add( request ) trans.sa_session.flush() @@ -1183,6 +1191,13 @@ request_details.append(dict(label=field['label'], value=request.values.content[index], helptext=field['helptext']+' ('+req+')')) + if request.notify: + notify = 'Yes' + else: + notify = 'No' + request_details.append(dict(label='Send email notification once the sequencing request is complete', + value=notify, + helptext='')) return request_details def __validate_barcode(self, trans, sample, barcode): ''' @@ -1333,6 +1348,15 @@ event = trans.app.model.RequestEvent(request, request.states.COMPLETE, comments) trans.sa_session.add( event ) trans.sa_session.flush() + # now that the request is complete send the email notification to the + # the user + if request.notify: + mail = os.popen("%s -t" % trans.app.config.sendmail_path, 'w') + subject = "Galaxy Sample Tracking: '%s' sequencing request in complete." % request.name + body = "The '%s' sequencing request (type: %s) is now complete. Datasets from all the samples are now available for analysis or download from the respective data libraries in Galaxy." % (request.name, request.type.name) + email_content = "To: %s\nFrom: no-reply@nowhere.edu\nSubject: %s\n\n%s" % (request.user.email, subject, body) + mail.write( email_content ) + x = mail.close() def change_state(self, trans, sample): possible_states = sample.request.type.states curr_state = sample.current_state()