Ignore:
Timestamp:
18 Jul 2012, 06:01:56 (12 years ago)
Author:
Henrik Bettermann
Message:

Let's provide some UI components for helpers and utilities.

Move msave from helpers.py to pages.py.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
2 added
3 edited

Legend:

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

    r8984 r9011  
    6767from waeup.kofa.widgets.htmlwidget import HTMLDisplayWidget
    6868from waeup.kofa.authentication import get_principal_role_manager
    69 from waeup.kofa.utils.helpers import get_user_account, msave
     69from waeup.kofa.utils.helpers import get_user_account
    7070from waeup.kofa.mandates.mandate import PasswordMandate
    7171
     
    157157    return
    158158
     159# Save function used for save methods in pages
     160def msave(view, **data):
     161    changed_fields = view.applyData(view.context, **data)
     162    # Turn list of lists into single list
     163    if changed_fields:
     164        changed_fields = reduce(lambda x,y: x+y, changed_fields.values())
     165    fields_string = ' + '.join(changed_fields)
     166    view.flash(_('Form has been saved.'))
     167    ob_class = view.__implemented__.__name__.replace('waeup.kofa.','')
     168    if fields_string:
     169        grok.getSite().logger.info('%s - saved: %s' % (ob_class, fields_string))
     170    return
     171
    159172#
    160173# Login/logout and language switch pages...
     
    373386    def entries(self):
    374387        return ()
    375 
    376 class ReindexPage(UtilityView, grok.View):
    377     """ Reindex view.
    378 
    379     Reindexes a catalog. For managers only.
    380     """
    381     grok.context(IUniversity)
    382     grok.name('reindex')
    383     grok.require('waeup.managePortal')
    384 
    385     def update(self,ctlg=None):
    386         if ctlg is None:
    387             self.flash('No catalog name provided.')
    388             return
    389         cat = queryUtility(ICatalog, name='%s_catalog' % ctlg)
    390         if cat is None:
    391             self.flash('%s_catalog does not exist' % ctlg)
    392             return
    393         self.context.logger.info(
    394             'Catalog `%s_catalog` re-indexing started.' % ctlg)
    395         cat.updateIndexes()
    396         no_of_entries = cat.values()[0].documentCount()
    397         self.flash('%d %s re-indexed.' % (no_of_entries,ctlg))
    398         self.context.logger.info(
    399             'Re-indexing of %d objects finished.' % no_of_entries)
    400         return
    401 
    402     def render(self):
    403         self.redirect(self.url(self.context, '@@index'))
    404         return
    405388
    406389#
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r8984 r9011  
    18681868        self.assertTrue('An email with' in self.browser.contents)
    18691869
    1870     def test_reindex(self):
    1871         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    1872         self.browser.open('http://localhost/app/reindex')
    1873         self.assertTrue('No catalog name provided' in self.browser.contents)
    1874         self.browser.open('http://localhost/app/reindex?ctlg=xyz')
    1875         self.assertTrue('xyz_catalog does not exist' in self.browser.contents)
    1876         cat = queryUtility(ICatalog, name='students_catalog')
    1877         results = cat.searchResults(student_id=(None, None))
    1878         self.assertEqual(len(results),1)
    1879         cat.clear()
    1880         results = cat.searchResults(student_id=(None, None))
    1881         self.assertEqual(len(results),0)
    1882         self.browser.open('http://localhost/app/reindex?ctlg=students')
    1883         self.assertTrue('1 students re-indexed' in self.browser.contents)
    1884         results = cat.searchResults(student_id=(None, None))
    1885         self.assertEqual(len(results),1)
    1886 
    18871870    def test_change_current_mode(self):
    18881871        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py

    r8739 r9011  
    683683        writer.writerow(row)
    684684    return tmp_path
    685 
    686 # Save function used for save methods in pages
    687 def 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     fields_string = ' + '.join(changed_fields)
    693     view.flash(_('Form has been saved.'))
    694     ob_class = view.__implemented__.__name__.replace('waeup.kofa.','')
    695     if fields_string:
    696         grok.getSite().logger.info('%s - saved: %s' % (ob_class, fields_string))
    697     return
Note: See TracChangeset for help on using the changeset viewer.