Ignore:
Timestamp:
09/18/07 13:17:59 (12 years ago)
Author:
pjotr
Message:

Created a main shell for method that will send e-mails with answers to teachers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ExerciseMaterial.py

    r2030 r2032  
    149149        return text 
    150150 
     151    def sendAnsweredExercise(self, REQUEST): 
     152        """ Send e-mail to a teacher """ 
     153        putils = getToolByName(self,'plone_utils') 
     154        mhost = putils.getMailHost() 
     155        message = '' 
     156        students_name = '' 
     157        students_email = '' 
     158        teachers_email = '' 
     159        if REQUEST.has_key('your_name'): 
     160            students_name = REQUEST.get('your_name') 
     161        if REQUEST.has_key('students_email'): 
     162            students_email = REQUEST.get('students_email') 
     163        if REQUEST.has_key('teachers_email'): 
     164            teachers_email = REQUEST.get('teachers_email') 
     165        if not teachers_email or not students_email or not students_name: 
     166            msg = _(u"You have not provided enough information to send an e-mail.") 
     167            putils.addPortalMessage(msg) 
     168            return REQUEST.RESPONSE.redirect(self.absolute_url()) 
     169        # Now we should compose the message body 
     170        exercise_body = self.getBodyText() 
     171        message += "This is an answer of %s to the exercise %s at %s\n\n" % (students_name, self.Title(), self.absolute_url()) 
     172        # XXX Message body should be composed question by question 
     173         
     174        message_from = "%s <%s>" % (students_name, students_email) 
     175        message_subject = "Answers to exercise %s by %s" % (self.Title(), students_name) 
     176        try: 
     177            mhost.send(message, mto=teachers_email, mfrom=message_from, subject=message_subject) 
     178            msg = _(u"The e-mail has been sent to a teacher.") 
     179            putils.addPortalMessage(msg) 
     180            return REQUEST.RESPONSE.redirect(self.absolute_url()) 
     181        except: 
     182            msg = _(u"The e-mail could not be sent.") 
     183            putils.addPortalMessage(msg) 
     184            return REQUEST.RESPONSE.redirect(self.absolute_url()) 
     185 
    151186 
    152187 
Note: See TracChangeset for help on using the changeset viewer.