Ignore:
Timestamp:
12 Aug 2010, 13:18:42 (14 years ago)
Author:
Henrik Bettermann
Message:

Implement update method for ContactAdminForm?. The form is used by anonymous users via the 'Enquiries' navigation tab and by authenticated users via the 'Contact' user navigation link.

Location:
main/waeup.sirp/branches/henrik-contactforms/src/waeup/sirp/browser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/branches/henrik-contactforms/src/waeup/sirp/browser/pages.py

    r5414 r5426  
    88import re
    99import sys
     10import time
     11import re
     12import smtplib
     13from email.mime.text import MIMEText
    1014from hurry import yui
    1115from hurry.workflow.interfaces import NoTransitionAvailableError
     
    313317            tt = u'Enquiries'         
    314318        return tt     
     319       
     320    def update(self, *args, **kw):
     321        form = self.request.form
     322        if not ('fullname' in form and 'email' in form and 'descr' in form):
     323            return
     324        self.fullname = fullname = form['fullname']
     325        email = form['email']
     326        self.descr = descr = form['descr']
     327        regno =form['regno']
     328        if not (fullname and email and descr):
     329            self.flash('Error: All fields must be filled!')
     330            return       
     331        if not re.match("^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", email):
     332            self.flash('Error: %s is not a valid email address!' % email)
     333            return
     334        if regno == 'zope.anybody':
     335            regno = 'Anonymous User'
     336        text = """Fullname: %s
     337Member ID: %s
     338Description: %s
     339"""
     340        msg = MIMEText(text % (fullname,regno,descr))
     341        msg['From'] = '%s <%s>' % (fullname,email)
     342        msg['To'] = 'henrik@waeup.org'
     343        msg['Subject'] = 'WAeUP Contact'
     344        server = smtplib.SMTP('smtp.scientific-african.org')
     345        server.login('henrik@scientific-african.org','kwamekofi')
     346        server.sendmail(email,'henrik@waeup.org',msg.as_string())
     347        server.quit()
     348        self.flash('Your message has been sent.')
     349        return
    315350
    316351#
  • main/waeup.sirp/branches/henrik-contactforms/src/waeup/sirp/browser/templates/contactadminform.pt

    r5414 r5426  
    1 <form id="form1" name="form1" method="post" action="mail2admin">
     1<form id="form1" name="form1" method="post">
    22<input type="hidden" name="regno" type="text" id="regno"
    33     tal:attributes="value layout/getUserId"/>
     
    88  </td>
    99  <td tal:condition="not:layout/isAuthenticated">
    10      <input name="fullname" type="text" id="fullname" />
     10     <input name="fullname" type="text" id="fullname" tal:attributes="value view/fullname|nothing" />
    1111  </td>
    12   <td tal:condition="layout/isAuthenticated" tal:content="layout/getUserTitle">
    13       User Name
     12  <td tal:condition="layout/isAuthenticated">
     13    <span tal:content="layout/getUserTitle" />
     14    <input type="hidden" name="fullname" type="text" id="fullname"
     15       tal:attributes="value layout/getUserTitle"/>
    1416  </td> 
    1517</tr>
     
    2729  </td>
    2830  <td>
    29      <textarea name="descr" rows="10" cols="60" id="descr"></textarea>
     31     <textarea name="descr" rows="10" cols="60" id="descr"><span tal:replace="view/descr|nothing" /></textarea>
     32     
    3033  </td>
    3134</tr>
Note: See TracChangeset for help on using the changeset viewer.