Changeset 7231 for main


Ignore:
Timestamp:
28 Nov 2011, 11:12:39 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement ContactUserForm?.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/browser
Files:
2 edited

Legend:

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

    r7229 r7231  
    189189
    190190#
     191# Contact form...
     192#
     193
     194class ContactAdminForm(Form):
     195    grok.name('contactadmin')
     196    #grok.context(IUniversity)
     197    grok.template('contactform')
     198    grok.require('waeup.Authenticated')
     199    pnav = 2
     200    form_fields = grok.AutoFields(IContactForm).select('body')
     201
     202    @property
     203    def config(self):
     204        return grok.getSite()['configuration']
     205
     206    def title(self):
     207        userid = self.request.principal.id
     208        return u'Contact %s' % self.config.name_admin
     209
     210    def label(self):
     211        return self.title()
     212
     213    @property
     214    def get_user_account(self):
     215        return get_user_account(self.request)
     216
     217    @grok.action('Send message now')
     218    def send(self, *args, **data):
     219        useraccount = self.get_user_account
     220        if useraccount is None:
     221            self.flash("You don't have a user account.")
     222            return
     223        fullname = useraccount.title
     224        email_from = useraccount.email
     225        username = useraccount.name
     226        body = data['body']
     227        email_to = self.config.email_admin
     228        subject = self.config.email_subject
     229        success = send_mail(fullname,username,self.config.name,
     230                  body,email_from,email_to,subject)
     231        if success:
     232            self.flash('Your message has been sent.')
     233        else:
     234            self.flash('An smtp server error occurred.')
     235        return
     236
     237class EnquiriesForm(ContactAdminForm):
     238    grok.name('enquiries')
     239    grok.require('waeup.Public')
     240    pnav = 2
     241    form_fields = grok.AutoFields(IContactForm).select(
     242                          'fullname', 'email_from', 'body')
     243
     244    @grok.action('Send now')
     245    def send(self, *args, **data):
     246        email_from = data['email_from']
     247        fullname = data['fullname']
     248        body = data['body']
     249        username = u'None'
     250        email_to = self.config.email_admin
     251        subject = self.config.email_subject
     252        success = send_mail(fullname,username,self.config.name,
     253                  body,email_from,email_to,subject)
     254        if success:
     255            self.flash('Your message has been sent.')
     256        else:
     257            self.flash('A smtp server error occurred.')
     258        return
     259
     260#
    191261# University related pages...
    192262#
     
    377447        return
    378448
     449class ContactUserForm(ContactAdminForm):
     450    grok.name('contactuser')
     451    grok.context(IUserAccount)
     452    grok.template('contactform')
     453    grok.require('waeup.manageUsers')
     454    pnav = 0
     455    form_fields = grok.AutoFields(IContactForm).select('body')
     456
     457    @grok.action('Send message now')
     458    def send(self, *args, **data):
     459        useraccount = self.get_user_account
     460        if useraccount is None:
     461            self.flash("You don't have a user account.")
     462            return
     463        fullname = useraccount.title
     464        email_from = useraccount.email
     465        username = useraccount.name
     466        body = data['body']
     467        email_to = self.context.email
     468        subject = self.config.email_subject
     469        success = send_mail(fullname,username,self.config.name,
     470                  body,email_from,email_to,subject)
     471        if success:
     472            self.flash('Your message has been sent.')
     473        else:
     474            self.flash('An smtp server error occurred.')
     475        return
     476
    379477class UserEditFormPage(UserManageFormPage):
    380478    """Edit a user account by user
     
    450548        self.query = query
    451549        self.hitlist = search(query=self.query, view=self)
    452         return
    453 
    454 #
    455 # Contact form...
    456 #
    457 
    458 class ContactAdminForm(Form):
    459     grok.name('contactadmin')
    460     #grok.context(IUniversity)
    461     grok.template('contactform')
    462     grok.require('waeup.Authenticated')
    463     pnav = 2
    464     form_fields = grok.AutoFields(IContactForm).select('body')
    465 
    466     @property
    467     def config(self):
    468         return grok.getSite()['configuration']
    469 
    470     def title(self):
    471         userid = self.request.principal.id
    472         return u'Contact %s' % self.config.name_admin
    473 
    474     def label(self):
    475         return self.title()
    476 
    477     @property
    478     def get_user_account(self):
    479         return get_user_account(self.request)
    480 
    481     @grok.action('Send message now')
    482     def send(self, *args, **data):
    483         useraccount = self.get_user_account
    484         if useraccount is None:
    485             self.flash("You don't have a user account.")
    486             return
    487         fullname = useraccount.title
    488         email_from = useraccount.email
    489         username = useraccount.name
    490         body = data['body']
    491         email_to = self.config.email_admin
    492         subject = self.config.email_subject
    493         success = send_mail(fullname,username,self.config.name,
    494                   body,email_from,email_to,subject)
    495         if success:
    496             self.flash('Your message has been sent.')
    497         else:
    498             self.flash('An smtp server error occurred.')
    499         return
    500 
    501 class EnquiriesForm(ContactAdminForm):
    502     grok.name('enquiries')
    503     grok.require('waeup.Public')
    504     pnav = 2
    505     form_fields = grok.AutoFields(IContactForm).select(
    506                           'fullname', 'email_from', 'body')
    507 
    508     @grok.action('Send now')
    509     def send(self, *args, **data):
    510         email_from = data['email_from']
    511         fullname = data['fullname']
    512         body = data['body']
    513         username = u'None'
    514         email_to = self.config.email_admin
    515         subject = self.config.email_subject
    516         success = send_mail(fullname,username,self.config.name,
    517                   body,email_from,email_to,subject)
    518         if success:
    519             self.flash('Your message has been sent.')
    520         else:
    521             self.flash('A smtp server error occurred.')
    522550        return
    523551
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/viewlets.py

    r7225 r7231  
    2323from waeup.sirp.browser.pages import (
    2424    UniversityPage, FacultyContainerPage, DatacenterPage, FacultyPage,
    25     DepartmentPage, CoursePage, CertificatePage, CertificateCoursePage, UsersContainerPage)
     25    DepartmentPage, CoursePage, CertificatePage, CertificateCoursePage,
     26    UsersContainerPage, UserManageFormPage)
    2627from waeup.sirp.browser.interfaces import (
    2728    IFacultyContainer, IFaculty, IDepartment, ICourse, ICertificate,
    2829    ICertificateCourse, IBreadcrumbContainer, IUniversity, IUsersContainer)
    2930from waeup.sirp.interfaces import (IWAeUPObject, IWAeUPXMLExporter,
    30                                    IWAeUPXMLImporter, IDataCenter)
     31                                   IWAeUPXMLImporter, IDataCenter, IUserAccount)
    3132from waeup.sirp.browser.layout import WAeUPPage
    3233from waeup.sirp.utils.helpers import get_user_account
     
    336337    text = u'Portal Users'
    337338
     339class ContactActionButton(ManageActionButton):
     340    grok.order(4)
     341    grok.context(IUserAccount)
     342    grok.view(UserManageFormPage)
     343    grok.require('waeup.manageUsers')
     344    icon = 'actionicon_mail.png'
     345    text = 'Send email'
     346    target = 'contactuser'
     347
    338348class ManageDataCenter(ManageLink):
    339349    """A link to datacenter, placed in upper left box.
Note: See TracChangeset for help on using the changeset viewer.