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

Merge changes from henrik-contactforms back into trunk.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/browser
Files:
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/browser.txt

    r5408 r5433  
    7272  Content-Type: text/xml; charset=UTF-8
    7373  X-Powered-By: Zope (www.zope.org), Python (www.python.org)
     74
     75Contact Form
     76============
     77
     78Let's enter the contact form::
     79
     80  >>> browser.open('http://localhost/myuniversity/contactadmin')
     81  >>> print browser.contents
     82  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
     83  ...<h2>Contact</h2>
     84  ...
     85
     86We fill in a wrong email address::
     87
     88  >>> browser.getControl(name='email').value = "xx@yy"
     89  >>> browser.getControl(name='descr').value = "test message"
     90  >>> browser.getControl('Submit').click()
     91  >>> print browser.contents     
     92  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
     93  ...<li class="message">Error: xx@yy is not a valid email address!</li>
     94  ...
     95
     96Now we fill the form properly::
     97
     98  >>> browser.getControl(name='email').value = "xx@yy.zz"
     99  >>> browser.getControl(name='descr').value = "test message"
     100  >>> browser.getControl('Submit').click()
     101  >>> print browser.contents     
     102  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
     103  ...<li class="message">Your message has been sent.</li>
     104  ...
    74105
    75106
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/layout.py

    r5407 r5433  
    121121        return usertitle
    122122
     123    def getUserId(self):
     124        """Return id of current user.
     125        """
     126        userid = self.request.principal.id
     127        return userid
     128
    123129    def update(self):
    124130        yui.reset_fonts_grids.need()
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r5422 r5433  
    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
     
    300304        self.hitlist = search(query=self.query, view=self)
    301305        return
     306       
     307#
     308# Contact forms...
     309#
     310class ContactAdminForm(WAeUPPage):
     311    grok.context(IUniversity)
     312    grok.name('contactadmin')
     313    grok.template('contactadminform')
     314    grok.require('waeup.Public')
     315    pnav = 3
     316   
     317    def title(self):
     318        """Return True if the calling user is authenticated.
     319        """
     320        userid = self.request.principal.id
     321        if userid != 'zope.anybody':
     322            tt = u'Contact'
     323        else:
     324            tt = u'Enquiries'         
     325        return tt     
     326       
     327    def update(self, *args, **kw):
     328        form = self.request.form
     329        if not ('fullname' in form and 'email' in form and 'descr' in form):
     330            return
     331        self.fullname = fullname = form['fullname']
     332        email = form['email']
     333        self.descr = descr = form['descr']
     334        regno =form['regno']
     335        if not (fullname and email and descr):
     336            self.flash('Error: All fields must be filled!')
     337            return       
     338        if not re.match("^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", email):
     339            self.flash('Error: %s is not a valid email address!' % email)
     340            return
     341        if regno == 'zope.anybody':
     342            regno = 'Anonymous User'
     343        text = """Fullname: %s
     344Member ID: %s
     345Description: %s
     346"""
     347        msg = MIMEText(text % (fullname,regno,descr))
     348        msg['From'] = '%s <%s>' % (fullname,email)
     349       
     350        # These parameters should be part of the portal configuration.
     351        msg['To'] = 'contact@waeup.org'
     352        msg['Subject'] = 'WAeUP Contact'
     353        #server = smtplib.SMTP('smtp_server')
     354        #server.login('user_name','secret_password')
     355        server = smtplib.SMTP('localhost')
     356        server.sendmail(email,'contact@waeup.org',msg.as_string())
     357       
     358        server.quit()
     359        self.flash('Your message has been sent.')
     360        return
    302361
    303362#
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/templates/sitelayout.pt

    r5407 r5433  
    5252            <ul id="user-navigation"
    5353                tal:condition="layout/isAuthenticated">
     54              <li>
     55                <a href="#"
     56                   tal:attributes="href python: view.url(layout.site,
     57                   '@@contactadmin')">Contact</a>
     58              </li>
    5459              <li>
    5560                <a href="#"
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/viewlets.py

    r5404 r5433  
    529529        return self.view.application_url('faculties')
    530530
    531 class SearchTab(PrimaryNavTab):
    532     """Search tab in primary navigation.
    533     """
    534     grok.order(3)
    535     grok.require('waeup.View')
     531   
     532class ContactTab(PrimaryNavTab):
     533    """Contact tab in primary navigation.
     534    """
     535    grok.order(4)
     536    grok.require('waeup.Anonymous')
    536537    grok.template('primarynavtab')
    537 
     538   
    538539    pnav = 2
    539     tab_title = u'Search'
     540    def tab_title(self):
     541        """Display tab only for anonymous. Authenticated users can call the
     542        form from the user navigation bar.
     543        """
     544        userid = self.request.principal.id
     545        if userid != 'zope.anybody':
     546            tt = u''
     547        else:
     548            tt = u'Enquiries'         
     549        return tt
    540550
    541551    @property
    542552    def link_target(self):
    543         return self.view.application_url('@@search')
     553        return self.view.application_url('contactadmin')       
     554
     555
    544556
    545557#
Note: See TracChangeset for help on using the changeset viewer.