Changeset 5433 for main/waeup.sirp/trunk/src/waeup/sirp/browser
- Timestamp:
- 13 Aug 2010, 10:10:18 (14 years ago)
- 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 72 72 Content-Type: text/xml; charset=UTF-8 73 73 X-Powered-By: Zope (www.zope.org), Python (www.python.org) 74 75 Contact Form 76 ============ 77 78 Let'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 86 We 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 96 Now 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 ... 74 105 75 106 -
main/waeup.sirp/trunk/src/waeup/sirp/browser/layout.py
r5407 r5433 121 121 return usertitle 122 122 123 def getUserId(self): 124 """Return id of current user. 125 """ 126 userid = self.request.principal.id 127 return userid 128 123 129 def update(self): 124 130 yui.reset_fonts_grids.need() -
main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py
r5422 r5433 8 8 import re 9 9 import sys 10 import time 11 import re 12 import smtplib 13 from email.mime.text import MIMEText 10 14 from hurry import yui 11 15 from hurry.workflow.interfaces import NoTransitionAvailableError … … 300 304 self.hitlist = search(query=self.query, view=self) 301 305 return 306 307 # 308 # Contact forms... 309 # 310 class 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 344 Member ID: %s 345 Description: %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 302 361 303 362 # -
main/waeup.sirp/trunk/src/waeup/sirp/browser/templates/sitelayout.pt
r5407 r5433 52 52 <ul id="user-navigation" 53 53 tal:condition="layout/isAuthenticated"> 54 <li> 55 <a href="#" 56 tal:attributes="href python: view.url(layout.site, 57 '@@contactadmin')">Contact</a> 58 </li> 54 59 <li> 55 60 <a href="#" -
main/waeup.sirp/trunk/src/waeup/sirp/browser/viewlets.py
r5404 r5433 529 529 return self.view.application_url('faculties') 530 530 531 class SearchTab(PrimaryNavTab): 532 """Search tab in primary navigation. 533 """ 534 grok.order(3) 535 grok.require('waeup.View') 531 532 class ContactTab(PrimaryNavTab): 533 """Contact tab in primary navigation. 534 """ 535 grok.order(4) 536 grok.require('waeup.Anonymous') 536 537 grok.template('primarynavtab') 537 538 538 539 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 540 550 541 551 @property 542 552 def link_target(self): 543 return self.view.application_url('@@search') 553 return self.view.application_url('contactadmin') 554 555 544 556 545 557 #
Note: See TracChangeset for help on using the changeset viewer.