Ignore:
Timestamp:
17 Jun 2012, 06:42:20 (13 years ago)
Author:
Henrik Bettermann
Message:

Let's use the msave helper function also in university and other packages. msave applies applyData to the view and writes a view-specific log message. The context object of the view must have a writeLogMessage method.

In the students package writeLogMessage is now provided by all classes which implement IStudentNavigation.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/accommodation.py

    r8194 r8735  
    5151        return self.__parent__
    5252
     53    def writeLogMessage(self, view, message):
     54        return self.__parent__.writeLogMessage(view, message)
     55
    5356StudentAccommodation = attrs_to_fields(StudentAccommodation)
    5457
     
    6871    def getStudent(self):
    6972        return self.__parent__.__parent__
     73
     74    def writeLogMessage(self, view, message):
     75        return self.__parent__.__parent__.writeLogMessage(view, message)
    7076
    7177    def getSessionString(self):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r8688 r8735  
    6262from waeup.kofa.browser.resources import toggleall
    6363from waeup.kofa.hostels.hostel import NOT_OCCUPIED
    64 from waeup.kofa.utils.helpers import get_current_principal, to_timezone
    65 
    66 def write_log_message(view, message):
    67     ob_class = view.__implemented__.__name__.replace('waeup.kofa.','')
    68     view.context.getStudent().loggerInfo(ob_class, message)
    69     return
    70 
    71 # Save function used for save methods in pages
    72 def msave(view, **data):
    73     changed_fields = view.applyData(view.context, **data)
    74     # Turn list of lists into single list
    75     if changed_fields:
    76         changed_fields = reduce(lambda x,y: x+y, changed_fields.values())
    77     # Inform catalog if certificate has changed
    78     # (applyData does this only for the context)
    79     if 'certificate' in changed_fields:
    80         notify(grok.ObjectModifiedEvent(view.context.getStudent()))
    81     fields_string = ' + '.join(changed_fields)
    82     view.flash(_('Form has been saved.'))
    83     if fields_string:
    84         write_log_message(view, 'saved: %s' % fields_string)
    85     return
     64from waeup.kofa.utils.helpers import get_current_principal, to_timezone, msave
    8665
    8766def emit_lock_message(view):
     
    394373        self.flash(_('Form has been saved.'))
    395374        if fields_string:
    396             write_log_message(self, 'saved: % s' % fields_string)
     375            self.context.writeLogMessage(self, 'saved: % s' % fields_string)
    397376        return
    398377
     
    10301009            self.flash(_('Successfully removed: ${a}',
    10311010                mapping = {'a': ', '.join(deleted)}))
    1032             write_log_message(self,'removed: % s' % ', '.join(deleted))
     1011            self.context.writeLogMessage(
     1012                self,'removed: % s' % ', '.join(deleted))
    10331013        self.redirect(self.url(self.context))
    10341014        return
     
    11011081        success, msg, log = self.context.approveStudentPayment()
    11021082        if log is not None:
    1103             write_log_message(self,log)
     1083            self.context.writeLogMessage(self,log)
    11041084        self.flash(msg)
    11051085        return
     
    12021182            self.flash(_('Successfully removed: ${a}',
    12031183                mapping = {'a':', '.join(deleted)}))
    1204             write_log_message(self,'removed: % s' % ', '.join(deleted))
     1184            self.context.writeLogMessage(
     1185                self,'removed: % s' % ', '.join(deleted))
    12051186        self.redirect(self.url(self.context))
    12061187        return
     
    14981479            if not errors:
    14991480                IUserAccount(self.context).setPassword(password)
    1500                 write_log_message(self, 'saved: password')
     1481                self.context.writeLogMessage(self, 'saved: password')
    15011482                self.flash(_('Password changed.'))
    15021483            else:
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r8621 r8735  
    129129
    130130class IStudentNavigation(IKofaObject):
    131     """Interface needed for student navigation.
     131    """Interface needed for student navigation, logging, etc.
    132132
    133133    """
    134134    def getStudent():
    135135        """Return student object.
     136
     137        """
     138
     139    def writeLogMessage(view, message):
     140        """Write a view specific log message into students.log.
    136141
    137142        """
     
    152157    display_fullname = Attribute('The fullname of an applicant')
    153158
    154     def loggerInfo(ob_class, comment):
    155         """Adds an INFO message to the log file.
    156 
    157         """
    158 
    159159    student_id = schema.TextLine(
    160160        title = _(u'Student Id'),
     
    383383    def addCourseTicket(courseticket):
    384384        """Add a course ticket object.
    385         """
    386 
    387     def getStudent():
    388         """Return student
    389385        """
    390386
  • main/waeup.kofa/trunk/src/waeup/kofa/students/payments.py

    r8732 r8735  
    4343        return self.__parent__
    4444
     45    def writeLogMessage(self, view, message):
     46        return self.__parent__.writeLogMessage(view, message)
     47
    4548StudentPaymentsContainer = attrs_to_fields(StudentPaymentsContainer)
    4649
     
    6063        except AttributeError:
    6164            return None
     65
     66    def writeLogMessage(self, view, message):
     67        return self.__parent__.__parent__.writeLogMessage(view, message)
    6268
    6369    def _createActivationCodes(self):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/student.py

    r8481 r8735  
    6161        return
    6262
    63     def loggerInfo(self, ob_class, comment=None):
    64         target = self.__name__
    65         return grok.getSite()['students'].logger_info(ob_class,target,comment)
     63    def writeLogMessage(self, view, message):
     64        ob_class = view.__implemented__.__name__.replace('waeup.kofa.','')
     65        return self.__parent__.logger_info(ob_class,self.__name__,comment=None)
    6666
    6767    @property
     
    139139            self.get('studycourse', None), 'is_postgrad', False)
    140140        return is_postgrad
     141
    141142
    142143# Set all attributes of Student required in IStudent as field
  • main/waeup.kofa/trunk/src/waeup/kofa/students/studycourse.py

    r8483 r8735  
    4242    def getStudent(self):
    4343        return self.__parent__
     44
     45    def writeLogMessage(self, view, message):
     46        return self.__parent__.writeLogMessage(view, message)
    4447
    4548    @property
  • main/waeup.kofa/trunk/src/waeup/kofa/students/studylevel.py

    r8494 r8735  
    4343    def getStudent(self):
    4444        return getattr(getattr(self, '__parent__', None), '__parent__', None)
     45
     46    def writeLogMessage(self, view, message):
     47        return self.__parent__.__parent__.writeLogMessage(view, message)
    4548
    4649    @property
     
    107110            return None
    108111
     112    def writeLogMessage(self, view, message):
     113        return self.__parent__.__parent__.__parent__.writeLogMessage(view, message)
     114
    109115    def getLevel(self):
    110116        """Returns the id of the level the ticket has been added to.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py

    r8467 r8735  
    3636from waeup.kofa.students.interfaces import (
    3737    IStudent, IStudentStudyCourse, IStudentPaymentsContainer,
    38     IStudentAccommodation, IStudentStudyLevel, ICourseTicket, IBedTicket)
     38    IStudentAccommodation, IStudentStudyLevel, ICourseTicket, IBedTicket,
     39    IStudentNavigation)
    3940from waeup.kofa.students.tests.test_batching import StudentImportExportSetup
    4041from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
     
    8687    def test_interfaces(self):
    8788        verify.verifyClass(IStudent, Student)
     89        verify.verifyClass(IStudentNavigation, Student)
    8890        verify.verifyObject(IStudent, self.student)
     91        verify.verifyObject(IStudentNavigation, self.student)
     92
    8993        verify.verifyClass(IStudentStudyCourse, StudentStudyCourse)
     94        verify.verifyClass(IStudentNavigation, StudentStudyCourse)
    9095        verify.verifyObject(IStudentStudyCourse, self.studycourse)
     96        verify.verifyObject(IStudentNavigation, self.studycourse)
     97
     98        verify.verifyClass(IStudentStudyLevel, StudentStudyLevel)
     99        verify.verifyClass(IStudentNavigation, StudentStudyLevel)
    91100        verify.verifyObject(IStudentStudyLevel, self.studylevel)
     101        verify.verifyObject(IStudentNavigation, self.studylevel)
     102
     103        verify.verifyClass(ICourseTicket, CourseTicket)
     104        verify.verifyClass(IStudentNavigation, CourseTicket)
    92105        verify.verifyObject(ICourseTicket, self.courseticket)
     106        verify.verifyObject(IStudentNavigation, self.courseticket)
     107
    93108        verify.verifyClass(IStudentPaymentsContainer, StudentPaymentsContainer)
     109        verify.verifyClass(IStudentNavigation, StudentPaymentsContainer)
    94110        verify.verifyObject(IStudentPaymentsContainer, self.payments)
     111        verify.verifyObject(IStudentNavigation, self.payments)
     112
    95113        verify.verifyClass(IStudentAccommodation, StudentAccommodation)
     114        verify.verifyClass(IStudentNavigation, StudentAccommodation)
    96115        verify.verifyObject(IStudentAccommodation, self.accommodation)
     116        verify.verifyObject(IStudentNavigation, self.accommodation)
     117
    97118        verify.verifyClass(IBedTicket, BedTicket)
     119        verify.verifyClass(IStudentNavigation, BedTicket)
    98120        verify.verifyObject(IBedTicket, self.bedticket)
     121        verify.verifyObject(IStudentNavigation, self.bedticket)
    99122        return
    100123
  • main/waeup.kofa/trunk/src/waeup/kofa/students/viewlets.py

    r8476 r8735  
    3535    VALIDATED)
    3636from waeup.kofa.students.browser import (
    37     StudentClearanceManageFormPage, write_log_message,
     37    StudentClearanceManageFormPage,
    3838    StudentBaseManageFormPage, StudentFilesUploadPage,
    3939    ExportPDFClearanceSlipPage, StudentsContainerPage,
     
    568568    store = getUtility(IExtFileStore)
    569569    store.deleteFileByContext(context, attr=download_name)
    570     write_log_message(view, 'deleted: %s' % download_name)
     570    context.writeLogMessage(view, 'deleted: %s' % download_name)
    571571    view.flash(_('${a} deleted.', mapping = {'a':download_name}))
    572572    return
     
    607607    file_id = IFileStoreNameChooser(context).chooseName(attr=download_name)
    608608    store.createFile(file_id, upload)
    609     write_log_message(view, 'uploaded: %s (%s)' % (
     609    context.writeLogMessage(view, 'uploaded: %s (%s)' % (
    610610        download_name,upload.filename))
    611611    view.flash(_('File ${a} uploaded.', mapping = {'a':download_name}))
  • main/waeup.kofa/trunk/src/waeup/kofa/university/certificate.py

    r8310 r8735  
    151151        studycourse.certificate = None
    152152        notify(grok.ObjectModifiedEvent(student))
    153         student.loggerInfo('ObjectRemovedEvent', 'removed: certificate')
     153        student.__parent__.logger_info(
     154            'ObjectRemovedEvent',student.__name__,'removed: certificate')
    154155    return
    155156
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py

    r8633 r8735  
    3838from zope.security.management import getInteraction
    3939from zope.pluggableauth.interfaces import IAuthenticatorPlugin
     40from waeup.kofa.interfaces import MessageFactory as _
    4041
    4142BUFSIZE = 8 * 1024
     
    682683        writer.writerow(row)
    683684    return tmp_path
     685
     686# Save function used for save methods in pages
     687def msave(view, **data):
     688    changed_fields = view.applyData(view.context, **data)
     689    # Turn list of lists into single list
     690    if changed_fields:
     691        changed_fields = reduce(lambda x,y: x+y, changed_fields.values())
     692    # Inform catalog if certificate has changed
     693    # (applyData does this only for the context)
     694    if 'certificate' in changed_fields:
     695        notify(grok.ObjectModifiedEvent(view.context.getStudent()))
     696    fields_string = ' + '.join(changed_fields)
     697    view.flash(_('Form has been saved.'))
     698    if fields_string:
     699        view.context.writeLogMessage(view, 'saved: %s' % fields_string)
     700    return
Note: See TracChangeset for help on using the changeset viewer.