Ignore:
Timestamp:
25 Aug 2011, 12:01:37 (13 years ago)
Author:
Henrik Bettermann
Message:

Add students_catalog and search facilities.

File:
1 edited

Legend:

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

    r6622 r6626  
    4545from waeup.sirp.browser.resources import datepicker, tabs, datatable
    4646from waeup.sirp.browser.viewlets import (
    47     ManageActionButton, PrimaryNavTab, LeftSidebarLink
     47    ManageActionButton, PrimaryNavTab, LeftSidebarLink, AddActionButton,
    4848    )
    4949from waeup.sirp.image.browser.widget import (
     
    6767    Student,
    6868    )
     69from waeup.sirp.students.catalog import search
    6970
    7071class StudentsTab(PrimaryNavTab):
     
    8485        return self.view.application_url('students')
    8586
    86 class StudentsContainerPage(WAeUPDisplayFormPage):
    87     """The standard view for regular student containers.
     87class StudentsContainerPage(WAeUPPage):
     88    """The standard view for student containers.
    8889    """
    8990    grok.context(IStudentsContainer)
     
    9293    grok.template('studentscontainerpage')
    9394
    94     form_fields = grok.AutoFields(IStudentsContainer)
    95     #form_fields['description'].custom_widget = ReSTDisplayWidget
    96 
    9795    @property
    9896    def title(self):
     
    103101        return self.title
    104102
    105 class StudentssContainerManageActionButton(ManageActionButton):
     103    def update(self, *args, **kw):
     104        datatable.need()
     105        form = self.request.form
     106        self.hitlist = []
     107        if 'searchterm' in form and form['searchterm']:
     108            self.searchterm = form['searchterm']
     109            self.searchtype = form['searchtype']
     110        elif 'old_searchterm' in form:
     111            self.searchterm = form['old_searchterm']
     112            self.searchtype = form['old_searchtype']
     113        else:
     114            if 'search' in form:
     115                self.flash('Empty search string.')
     116            return
     117        self.hitlist = search(query=self.searchterm,
     118            searchtype=self.searchtype, view=self)
     119        if not self.hitlist:
     120            self.flash('No student found.')
     121        return
     122
     123class StudentsContainerManageActionButton(ManageActionButton):
    106124    grok.order(1)
    107125    grok.context(IStudentsContainer)
     
    110128    text = 'Manage students'
    111129
    112 class StudentsContainerManagePage(WAeUPDisplayFormPage):
    113     """The standard view for regular student containers.
     130
     131class StudentsContainerManagePage(WAeUPPage):
     132    """The manage page for student containers.
    114133    """
    115134    grok.context(IStudentsContainer)
    116135    grok.name('manage')
    117136    grok.require('waeup.manageStudents')
    118     grok.template('studentscontainerpage')
    119 
    120     form_fields = grok.AutoFields(IStudentsContainer)
     137    grok.template('studentscontainermanagepage')
    121138
    122139    @property
     
    128145        return self.title
    129146
    130     @grok.action('Add student', validator=NullValidator)
    131     def addStudent(self, **data):
    132         self.redirect(self.url(self.context, 'addstudent'))
     147    def update(self, *args, **kw):
     148        datatable.need()
     149        form = self.request.form
     150        self.hitlist = []
     151        if 'searchterm' in form and form['searchterm']:
     152            self.searchterm = form['searchterm']
     153            self.searchtype = form['searchtype']
     154        elif 'old_searchterm' in form:
     155            self.searchterm = form['old_searchterm']
     156            self.searchtype = form['old_searchtype']
     157        else:
     158            if 'search' in form:
     159                self.flash('Empty search string.')
     160            return
     161        #import pdb; pdb.set_trace()
     162        if not 'entries' in form:
     163            self.hitlist = search(query=self.searchterm,
     164                searchtype=self.searchtype, view=self)
     165            if not self.hitlist:
     166                self.flash('No student found.')
     167            return
     168        entries = form['entries']
     169        if isinstance(entries, basestring):
     170            entries = [entries]
     171        deleted = []
     172        for entry in entries:
     173            if 'remove' in form:
     174                del self.context[entry]
     175                deleted.append(entry)
     176        self.hitlist = search(query=self.searchterm,
     177            searchtype=self.searchtype, view=self)
     178        if len(deleted):
     179            self.flash('Successfully removed: %s' % ', '.join(deleted))
    133180        return
     181
     182class StudentsContainerAddActionButton(AddActionButton):
     183    grok.order(1)
     184    grok.context(IStudentsContainer)
     185    grok.view(StudentsContainerManagePage)
     186    grok.require('waeup.manageStudents')
     187    text = 'Add student'
     188    target = 'addstudent'
    134189
    135190class StudentAddFormPage(WAeUPAddFormPage):
     
    155210            self.flash('The student id chosen already exists.')
    156211            return
     212        self.flash('Student record created.')
    157213        self.redirect(self.url(self.context[student_id], 'index'))
    158214        return
Note: See TracChangeset for help on using the changeset viewer.