Ignore:
Timestamp:
17 Dec 2012, 08:06:52 (12 years ago)
Author:
Henrik Bettermann
Message:

Move filter students pages to students package.

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

Legend:

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

    r9743 r9806  
    6262    get_users_with_role)
    6363
    64 from waeup.kofa.students.catalog import search as searchstudents
    65 from waeup.kofa.students.catalog import StudentQueryResultItem
    6664from waeup.kofa.university.catalog import search
    6765from waeup.kofa.university.vocabularies import course_levels
     
    18811879            yield(dict(url=url, name=key, container=val))
    18821880
    1883 class FilterStudentsInDepartmentPage(KofaPage):
    1884     """Page that filters and lists students.
    1885     """
    1886     grok.context(IDepartment)
    1887     grok.require('waeup.showStudents')
    1888     grok.name('students')
    1889     grok.template('filterstudentspage')
    1890     pnav = 1
    1891     session_label = _('in session')
    1892     level_label = _('at level')
    1893 
    1894     def label(self):
    1895         return 'Students in %s ...' % self.context.longtitle()
    1896 
    1897     def _set_session_values(self):
    1898         vocab_terms = academic_sessions_vocab.by_value.values()
    1899         self.sessions = sorted(
    1900             [(x.title, x.token) for x in vocab_terms], reverse=True)
    1901         self.sessions += [('All Sessions', 'all')]
    1902         return
    1903 
    1904     def _set_level_values(self):
    1905         vocab_terms = course_levels.by_value.values()
    1906         self.levels = sorted(
    1907             [(x.title, x.token) for x in vocab_terms])
    1908         self.levels += [('All Levels', 'all')]
    1909         return
    1910 
    1911     def _searchCatalog(self, session, level):
    1912         if level not in (10, 999, None):
    1913             start_level = 100 * (level // 100)
    1914             end_level = start_level + 90
    1915         else:
    1916             start_level = end_level = level
    1917         cat = queryUtility(ICatalog, name='students_catalog')
    1918         students = cat.searchResults(
    1919             current_session=(session, session),
    1920             current_level=(start_level, end_level),
    1921             depcode=(self.context.code, self.context.code)
    1922             )
    1923         hitlist = []
    1924         for student in students:
    1925             hitlist.append(StudentQueryResultItem(student, view=self))
    1926         return hitlist
    1927 
    1928     def update(self, SHOW=None, session=None, level=None):
    1929         datatable.need()
    1930         self.parent_url = self.url(self.context.__parent__)
    1931         self._set_session_values()
    1932         self._set_level_values()
    1933         self.hitlist = []
    1934         self.session_default = session
    1935         self.level_default = level
    1936         if SHOW is not None:
    1937             if session != 'all':
    1938                 self.session = int(session)
    1939                 self.session_string = '%s %s/%s' % (
    1940                     self.session_label, self.session, self.session+1)
    1941             else:
    1942                 self.session = None
    1943                 self.session_string = _('in any session')
    1944             if level != 'all':
    1945                 self.level = int(level)
    1946                 self.level_string = '%s %s' % (self.level_label, self.level)
    1947             else:
    1948                 self.level = None
    1949                 self.level_string = _('at any level')
    1950             self.hitlist = self._searchCatalog(self.session, self.level)
    1951             if not self.hitlist:
    1952                 self.flash(_('No student found.'))
    1953         return
    1954 
    1955 class FilterStudentsInCertificatePage(FilterStudentsInDepartmentPage):
    1956     """Page that filters and lists students.
    1957     """
    1958     grok.context(ICertificate)
    1959 
    1960     def label(self):
    1961         return 'Students studying %s ...' % self.context.longtitle()
    1962 
    1963     def _searchCatalog(self, session, level):
    1964         if level not in (10, 999, None):
    1965             start_level = 100 * (level // 100)
    1966             end_level = start_level + 90
    1967         else:
    1968             start_level = end_level = level
    1969         cat = queryUtility(ICatalog, name='students_catalog')
    1970         students = cat.searchResults(
    1971             current_session=(session, session),
    1972             current_level=(start_level, end_level),
    1973             certcode=(self.context.code, self.context.code)
    1974             )
    1975         hitlist = []
    1976         for student in students:
    1977             hitlist.append(StudentQueryResultItem(student, view=self))
    1978         return hitlist
    1979 
    1980 class FilterStudentsInCoursePage(FilterStudentsInDepartmentPage):
    1981     """Page that filters and lists students.
    1982     """
    1983     grok.context(ICourse)
    1984 
    1985     def label(self):
    1986         return 'Students registered for %s ...' % self.context.longtitle()
    1987 
    1988     def _searchCatalog(self, session, level):
    1989         if level not in (10, 999, None):
    1990             start_level = 100 * (level // 100)
    1991             end_level = start_level + 90
    1992         else:
    1993             start_level = end_level = level
    1994         cat = queryUtility(ICatalog, name='coursetickets_catalog')
    1995         coursetickets = cat.searchResults(
    1996             session=(session, session),
    1997             level=(start_level, end_level),
    1998             code=(self.context.code, self.context.code)
    1999             )
    2000         hitlist = []
    2001         for ticket in coursetickets:
    2002             # XXX: If students have registered the same courses twice
    2003             # they will be listed twice.
    2004             hitlist.append(StudentQueryResultItem(ticket.student, view=self))
    2005         return hitlist
    2006 
    20071881class DepartmentManageFormPage(KofaEditFormPage):
    20081882    """Manage the basic properties of a `Department` instance.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r9804 r9806  
    5252    FriendlyDatetimeDisplayWidget)
    5353from waeup.kofa.mandates.mandate import PasswordMandate
     54from waeup.kofa.university.interfaces import (
     55    IDepartment, ICertificate, ICourse)
    5456from waeup.kofa.university.department import (
    5557    VirtualDepartmentExportJobContainer,)
     
    6769    IBedTicket, IStudentsUtils, IStudentRequestPW
    6870    )
    69 from waeup.kofa.students.catalog import search, StudentsQuery
     71from waeup.kofa.students.catalog import search, StudentQueryResultItem
    7072from waeup.kofa.students.export import EXPORTER_NAMES
    7173from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket
     
    25032505        return
    25042506
     2507class FilterStudentsInDepartmentPage(KofaPage):
     2508    """Page that filters and lists students.
     2509    """
     2510    grok.context(IDepartment)
     2511    grok.require('waeup.showStudents')
     2512    grok.name('students')
     2513    grok.template('filterstudentspage')
     2514    pnav = 1
     2515    session_label = _('in session')
     2516    level_label = _('at level')
     2517
     2518    def label(self):
     2519        return 'Students in %s ...' % self.context.longtitle()
     2520
     2521    def _set_session_values(self):
     2522        vocab_terms = academic_sessions_vocab.by_value.values()
     2523        self.sessions = sorted(
     2524            [(x.title, x.token) for x in vocab_terms], reverse=True)
     2525        self.sessions += [('All Sessions', 'all')]
     2526        return
     2527
     2528    def _set_level_values(self):
     2529        vocab_terms = course_levels.by_value.values()
     2530        self.levels = sorted(
     2531            [(x.title, x.token) for x in vocab_terms])
     2532        self.levels += [('All Levels', 'all')]
     2533        return
     2534
     2535    def _searchCatalog(self, session, level):
     2536        if level not in (10, 999, None):
     2537            start_level = 100 * (level // 100)
     2538            end_level = start_level + 90
     2539        else:
     2540            start_level = end_level = level
     2541        cat = queryUtility(ICatalog, name='students_catalog')
     2542        students = cat.searchResults(
     2543            current_session=(session, session),
     2544            current_level=(start_level, end_level),
     2545            depcode=(self.context.code, self.context.code)
     2546            )
     2547        hitlist = []
     2548        for student in students:
     2549            hitlist.append(StudentQueryResultItem(student, view=self))
     2550        return hitlist
     2551
     2552    def update(self, SHOW=None, session=None, level=None):
     2553        datatable.need()
     2554        self.parent_url = self.url(self.context.__parent__)
     2555        self._set_session_values()
     2556        self._set_level_values()
     2557        self.hitlist = []
     2558        self.session_default = session
     2559        self.level_default = level
     2560        if SHOW is not None:
     2561            if session != 'all':
     2562                self.session = int(session)
     2563                self.session_string = '%s %s/%s' % (
     2564                    self.session_label, self.session, self.session+1)
     2565            else:
     2566                self.session = None
     2567                self.session_string = _('in any session')
     2568            if level != 'all':
     2569                self.level = int(level)
     2570                self.level_string = '%s %s' % (self.level_label, self.level)
     2571            else:
     2572                self.level = None
     2573                self.level_string = _('at any level')
     2574            self.hitlist = self._searchCatalog(self.session, self.level)
     2575            if not self.hitlist:
     2576                self.flash(_('No student found.'))
     2577        return
     2578
     2579class FilterStudentsInCertificatePage(FilterStudentsInDepartmentPage):
     2580    """Page that filters and lists students.
     2581    """
     2582    grok.context(ICertificate)
     2583
     2584    def label(self):
     2585        return 'Students studying %s ...' % self.context.longtitle()
     2586
     2587    def _searchCatalog(self, session, level):
     2588        if level not in (10, 999, None):
     2589            start_level = 100 * (level // 100)
     2590            end_level = start_level + 90
     2591        else:
     2592            start_level = end_level = level
     2593        cat = queryUtility(ICatalog, name='students_catalog')
     2594        students = cat.searchResults(
     2595            current_session=(session, session),
     2596            current_level=(start_level, end_level),
     2597            certcode=(self.context.code, self.context.code)
     2598            )
     2599        hitlist = []
     2600        for student in students:
     2601            hitlist.append(StudentQueryResultItem(student, view=self))
     2602        return hitlist
     2603
     2604class FilterStudentsInCoursePage(FilterStudentsInDepartmentPage):
     2605    """Page that filters and lists students.
     2606    """
     2607    grok.context(ICourse)
     2608
     2609    def label(self):
     2610        return 'Students registered for %s ...' % self.context.longtitle()
     2611
     2612    def _searchCatalog(self, session, level):
     2613        if level not in (10, 999, None):
     2614            start_level = 100 * (level // 100)
     2615            end_level = start_level + 90
     2616        else:
     2617            start_level = end_level = level
     2618        cat = queryUtility(ICatalog, name='coursetickets_catalog')
     2619        coursetickets = cat.searchResults(
     2620            session=(session, session),
     2621            level=(start_level, end_level),
     2622            code=(self.context.code, self.context.code)
     2623            )
     2624        hitlist = []
     2625        for ticket in coursetickets:
     2626            # XXX: If students have registered the same courses twice
     2627            # they will be listed twice.
     2628            hitlist.append(StudentQueryResultItem(ticket.student, view=self))
     2629        return hitlist
     2630
    25052631class DepartmentExportJobContainerOverview(KofaPage):
    25062632    """Page that filters and lists students.
Note: See TracChangeset for help on using the changeset viewer.