Changeset 7229 for main/waeup.sirp/trunk


Ignore:
Timestamp:
28 Nov 2011, 10:35:47 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement contact form to send messages to students.

helpers.py: Let get_user_account look for the right IAuthenticatorPlugin (works well with students and users but not with applicants).
applicants/authentication.py: Add getAccount method which returns None at the moment (to let the tests pass).

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/authentication.py

    r7192 r7229  
    245245        return None
    246246
     247    def getAccount(self, login):
     248        return None
     249
    247250class ApplicantsAuthUtility(grok.GlobalUtility):
    248251    """A global utility that sets up any PAU passed.
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/__init__.py

    r7137 r7229  
    44    WAeUPPage, WAeUPLayout, WAeUPDisplayFormPage, WAeUPEditFormPage,
    55    WAeUPAddFormPage, NullValidator)
     6from waeup.sirp.browser.pages import ContactAdminForm
    67
    78IMAGE_PATH = os.path.join(
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/browser.txt

    r7225 r7229  
    4545  >>> print browser.contents
    4646  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
    47   ...There were errors...
     47  ...>Required input is missing...
    4848  ...
    4949
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r7227 r7229  
    479479        return get_user_account(self.request)
    480480
    481     @grok.action('Send now')
     481    @grok.action('Send message now')
    482482    def send(self, *args, **data):
    483483        useraccount = self.get_user_account
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r7205 r7229  
    3131from waeup.sirp.accesscodes.workflow import USED
    3232from waeup.sirp.browser import (
    33     WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, WAeUPDisplayFormPage)
     33    WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, WAeUPDisplayFormPage,
     34    ContactAdminForm)
    3435from waeup.sirp.browser.breadcrumbs import Breadcrumb
    3536from waeup.sirp.browser.resources import datepicker, datatable, tabs
     
    3738    ManageActionButton, AddActionButton)
    3839from waeup.sirp.interfaces import (
    39     IWAeUPObject, IUserAccount, IExtFileStore, IPasswordValidator)
     40    IWAeUPObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm)
    4041from waeup.sirp.widgets.datewidget import (
    4142    FriendlyDateWidget, FriendlyDateDisplayWidget,
     
    5758from waeup.sirp.authentication import get_principal_role_manager
    5859from waeup.sirp.hostels.hostel import NOT_OCCUPIED
     60from waeup.sirp.utils.helpers import get_user_account, send_mail
    5961
    6062def write_log_message(view, message):
     
    350352            return 'set'
    351353        return 'unset'
     354
     355class ContactActionButton(ManageActionButton):
     356    grok.order(4)
     357    grok.context(IStudent)
     358    grok.view(StudentBaseDisplayFormPage)
     359    grok.require('waeup.manageStudent')
     360    icon = 'actionicon_mail.png'
     361    text = 'Send email'
     362    target = 'contacstudent'
     363
     364class ContactStudentForm(ContactAdminForm):
     365    grok.context(IStudent)
     366    grok.name('contacstudent')
     367    grok.require('waeup.manageStudent')
     368    pnav = 4
     369    title = 'Contact'
     370    form_fields = grok.AutoFields(IContactForm).select('subject', 'body')
     371
     372    def label(self):
     373        return u'Send message to %s' % self.context.fullname
     374
     375    @grok.action('Send message now')
     376    def send(self, *args, **data):
     377        useraccount = self.get_user_account
     378        if useraccount is None:
     379            self.flash("You don't have a user account.")
     380            return
     381        fullname = useraccount.title
     382        email_from = useraccount.email
     383        username = useraccount.name
     384        body = data['body']
     385        #subject = u'Mail from SIRP'
     386        subject = data['subject']
     387        email_to = self.context.email
     388        success = send_mail(fullname,username,self.config.name,
     389                  body,email_from,email_to,subject)
     390        if success:
     391            self.flash('Your message has been sent.')
     392        else:
     393            self.flash('An smtp server error occurred.')
     394        return
    352395
    353396class StudentBaseManageActionButton(ManageActionButton):
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/helpers.py

    r7225 r7229  
    2727from cStringIO import StringIO
    2828from docutils.core import publish_string
    29 from zope.component import getUtility
     29from zope.component import getUtility, getUtilitiesFor
    3030from zope.component.interfaces import IFactory
    3131from zope.interface import implementedBy
     
    477477    """
    478478    principal_id = request.principal.id
    479     authenticator = getUtility(IAuthenticatorPlugin, name='users')
    480     account = authenticator.getAccount(principal_id)
     479    authenticators = getUtilitiesFor(IAuthenticatorPlugin)
     480    for authenticator in authenticators:
     481        account = authenticator[1].getAccount(principal_id)
     482        if account:
     483            break
    481484    return account
    482485
Note: See TracChangeset for help on using the changeset viewer.