Changeset 6917 for main


Ignore:
Timestamp:
21 Oct 2011, 08:46:51 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement function delSubobjects for deleting objects in containers.

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

Legend:

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

    r6907 r6917  
    352352  >>> browser.open('http://localhost/myuniversity/faculties/manage')
    353353  >>> browser.getControl("Remove selected", index=0).click()
    354   >>> 'No faculty selected' in browser.contents
     354  >>> 'No item selected' in browser.contents
    355355  True
    356356  >>> browser.open('http://localhost/myuniversity/faculties/manage')
     
    500500  >>> browser.open('http://localhost/myuniversity/faculties/TF/manage')
    501501  >>> browser.getControl("Remove selected", index=0).click()
    502   >>> 'No department selected' in browser.contents
     502  >>> 'No item selected' in browser.contents
    503503  True
    504504  >>> browser.open('http://localhost/myuniversity/faculties/TF/manage')
     
    670670  >>> browser.getLink('Manage department').click()
    671671  >>> browser.getControl('Remove selected courses').click()
    672   >>> 'No course selected' in browser.contents
     672  >>> 'No item selected' in browser.contents
    673673  True
    674674
     
    820820
    821821  >>> browser.getControl('Remove selected certificates').click()
    822   >>> 'No certificate selected' in browser.contents
     822  >>> 'No item selected' in browser.contents
    823823  True
    824824
     
    992992  True
    993993  >>> browser.getControl('Remove selected course referrers').click()
    994   >>> 'No course referrer selected' in browser.contents
     994  >>> 'No item selected' in browser.contents
    995995  True
    996996  >>> browser.getControl(name='val_id').getControl(value='COURSE1_200').selected = True
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r6916 r6917  
    4343from waeup.sirp.authentication import get_principal_role_manager
    4444
    45 
    4645grok.context(IWAeUPObject)
    4746grok.templatedir('templates')
     
    9089    return
    9190
     91def delSubobjects(view, redirect, tab=None, subcontainer=None):
     92    form = view.request.form
     93    if form.has_key('val_id'):
     94        child_id = form['val_id']
     95    else:
     96        view.flash('No item selected.')
     97        if tab:
     98            view.redirect(view.url(view.context, redirect)+'#tab-%s' % tab)
     99        else:
     100            view.redirect(view.url(view.context, redirect))
     101        return
     102    if not isinstance(child_id, list):
     103        child_id = [child_id]
     104    deleted = []
     105    for id in child_id:
     106        try:
     107            if subcontainer:
     108                container = getattr(view.context, subcontainer, None)
     109                del container[id]
     110            else:
     111                del view.context[id]
     112            deleted.append(id)
     113        except:
     114            view.flash('Could not delete %s: %s: %s' % (
     115                    id, sys.exc_info()[0], sys.exc_info()[1]))
     116    if len(deleted):
     117        view.flash('Successfully removed: %s' % ', '.join(deleted))
     118    if tab:
     119        view.redirect(view.url(view.context, redirect)+'#tab-%s' % tab)
     120    else:
     121        view.redirect(view.url(view.context, redirect))
     122    return
     123
    92124#
    93125# Login/logout pages...
     
    432464    tabtwoactions = [
    433465        'Add session configuration',
    434         'Remove selected sesson configurations']
     466        'Remove selected']
    435467
    436468    form_fields = grok.AutoFields(IConfigurationContainer)
     
    462494
    463495    # ToDo: Show warning message before deletion
    464     @grok.action('Remove selected sesson configurations')
    465     def delSubobjects(self, **data):
    466         form = self.request.form
    467         if form.has_key('val_id'):
    468             child_id = form['val_id']
    469         else:
    470             self.flash('No item selected.')
    471             self.redirect(self.url(self.context, '@@index')+'#tab-2')
    472             return
    473         if not isinstance(child_id, list):
    474             child_id = [child_id]
    475         deleted = []
    476         for id in child_id:
    477             try:
    478                 del self.context[id]
    479                 deleted.append(id)
    480             except:
    481                 self.flash('Could not delete %s: %s: %s' % (
    482                         id, sys.exc_info()[0], sys.exc_info()[1]))
    483         if len(deleted):
    484             self.flash('Successfully removed: %s' % ', '.join(deleted))
    485         self.redirect(self.url(self.context, '@@index')+'#tab-2')
     496    @grok.action('Remove selected')
     497    def delSessonConfigurations(self, **data):
     498        delSubobjects(self, redirect='@@index', tab='2')
    486499        return
    487500
     
    10421055    @grok.action('Remove selected')
    10431056    def delFaculties(self, **data):
    1044         form = self.request.form
    1045         if form.has_key('val_id'):
    1046             child_id = form['val_id']
    1047         else:
    1048             self.flash('No faculty selected.')
    1049             self.redirect(self.url(self.context, '@@manage')+'#tab-1')
    1050             return
    1051         if not isinstance(child_id, list):
    1052             child_id = [child_id]
    1053         deleted = []
    1054         for id in child_id:
    1055             try:
    1056                 del self.context[id]
    1057                 deleted.append(id)
    1058             except:
    1059                 self.flash('Could not delete %s: %s: %s' % (
    1060                         id, sys.exc_info()[0], sys.exc_info()[1]))
    1061         if len(deleted):
    1062             self.flash('Successfully removed: %s' % ', '.join(deleted))
    1063         self.redirect(self.url(self.context, '@@manage')+'#tab-1')
     1057        delSubobjects(self, redirect='@@manage', tab='1')
    10641058        return
    10651059
     
    11651159    # ToDo: Show warning message before deletion
    11661160    @grok.action('Remove selected')
    1167     def delSubobjects(self, **data):
    1168         form = self.request.form
    1169         if form.has_key('val_id'):
    1170             child_id = form['val_id']
    1171         else:
    1172             self.flash('No department selected.')
    1173             self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    1174             return
    1175         if not isinstance(child_id, list):
    1176             child_id = [child_id]
    1177         deleted = []
    1178         for id in child_id:
    1179             try:
    1180                 del self.context[id]
    1181                 deleted.append(id)
    1182             except:
    1183                 self.flash('Could not delete %s: %s: %s' % (
    1184                         id, sys.exc_info()[0], sys.exc_info()[1]))
    1185         if len(deleted):
    1186             self.flash('Successfully removed: %s' % ', '.join(deleted))
    1187         self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     1161    def delDepartments(self, **data):
     1162        delSubobjects(self, redirect='@@manage', tab='2')
    11881163        return
    11891164
     
    13441319    @grok.action('Remove selected courses')
    13451320    def delCourses(self, **data):
    1346         form = self.request.form
    1347         if form.has_key('val_id'):
    1348             child_id = form['val_id']
    1349         else:
    1350             self.flash('No course selected.')
    1351             self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    1352             return
    1353         if not isinstance(child_id, list):
    1354             child_id = [child_id]
    1355         deleted = []
    1356         for id in child_id:
    1357             try:
    1358                 del self.context.courses[id]
    1359                 deleted.append(id)
    1360             except:
    1361                 self.flash('Could not delete %s: %s: %s' % (
    1362                         id, sys.exc_info()[0], sys.exc_info()[1]))
    1363         if len(deleted):
    1364             self.flash('Successfully removed: %s' % ', '.join(deleted))
    1365         self.redirect(self.url(self.context, u'@@manage')+'#tab-2')
     1321        delSubobjects(
     1322            self, redirect='@@manage', tab='2', subcontainer='courses')
    13661323        return
    13671324
    13681325    @grok.action('Remove selected certificates')
    13691326    def delCertificates(self, **data):
    1370         form = self.request.form
    1371         if form.has_key('val_id'):
    1372             child_id = form['val_id']
    1373         else:
    1374             self.flash('No certificate selected.')
    1375             self.redirect(self.url(self.context, '@@manage')+'#tab-3')
    1376             return
    1377         if not isinstance(child_id, list):
    1378             child_id = [child_id]
    1379         deleted = []
    1380         for id in child_id:
    1381             try:
    1382                 del self.context.certificates[id]
    1383                 deleted.append(id)
    1384             except:
    1385                 self.flash('Could not delete %s: %s: %s' % (
    1386                         id, sys.exc_info()[0], sys.exc_info()[1]))
    1387         if len(deleted):
    1388             self.flash('Successfully removed: %s' % ', '.join(deleted))
    1389         self.redirect(self.url(self.context, u'@@manage')+'#tab-3')
     1327        delSubobjects(
     1328            self, redirect='@@manage', tab='3', subcontainer='certificates')
    13901329        return
    13911330
     
    16071546    @grok.action('Remove selected course referrers')
    16081547    def delCertificateCourses(self, **data):
    1609         form = self.request.form
    1610         if form.has_key('val_id'):
    1611             child_id = form['val_id']
    1612         else:
    1613             self.flash('No course referrer selected.')
    1614             self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    1615             return
    1616         if not isinstance(child_id, list):
    1617             child_id = [child_id]
    1618         deleted = []
    1619         for id in child_id:
    1620             try:
    1621                 del self.context[id]
    1622                 deleted.append(id)
    1623             except:
    1624                 self.flash('Could not delete %s: %s: %s' % (
    1625                         id, sys.exc_info()[0], sys.exc_info()[1]))
    1626         if len(deleted):
    1627             self.flash('Successfully removed: %s' % ', '.join(deleted))
    1628         self.redirect(self.url(self.context, u'@@manage')+'#tab-2')
    1629         return
    1630 
     1548        delSubobjects(self, redirect='@@manage', tab='2')
     1549        return
    16311550
    16321551    @grok.action('Add course referrer', validator=NullValidator)
Note: See TracChangeset for help on using the changeset viewer.