Ignore:
Timestamp:
5 Apr 2018, 15:30:08 (7 years ago)
Author:
Henrik Bettermann
Message:

Add ticket level and session filter to CourseTicketExporter.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig.pt

    r12971 r14984  
    5050    </option>
    5151  </select>
    52   <br />
     52
    5353  <span id="payment_dates" style="display: none;">
     54    <br />
    5455    <label for="mode" i18n:translate="">
    5556      Payment Date
     
    6566    <br />
    6667  </span>
     68
     69
     70  <span id="ct_data" style="display: none;">
     71    <br />
     72    <label for="mode" i18n:translate="">
     73      Course Ticket Level
     74    </label>
     75    <select name="ct_level" class="form-control half">
     76      <option tal:repeat="item view/levels"
     77              tal:attributes="value python:item[1]">
     78        <span tal:replace="python: item[0]">200</span>
     79      </option>
     80    </select>
     81    <br />
     82    <label for="mode" i18n:translate="">
     83      Course Ticket Session
     84    </label>
     85    <select name="ct_session" class="form-control half">
     86      <option tal:repeat="item view/sessions"
     87              tal:attributes="value python:item[1]">
     88        <span tal:replace="python: item[0]">2012/2013</span>
     89      </option>
     90    </select>
     91    <br />
     92  </span>
    6793  <br />
     94
    6895  <input type="submit" name="START"  i18n:translate=""
    6996    value="Create CSV file"
     
    77104          document.getElementById('exporter').value == 'studentunpaidpayments') {
    78105          document.getElementById('payment_dates').style.display = 'block';
     106          document.getElementById('ct_data').style.display = 'none';
     107      } else if (document.getElementById('exporter').value == 'coursetickets')  {
     108          document.getElementById('ct_data').style.display = 'block';
     109          document.getElementById('payment_dates').style.display = 'none';
    79110      } else {
     111          document.getElementById('ct_data').style.display = 'none';
    80112          document.getElementById('payment_dates').style.display = 'none';
    81113      }
    82114  }
    83115</script>
     116
  • main/waeup.kofa/trunk/src/waeup/kofa/students/export.py

    r14957 r14984  
    5757    """Get course tickets of `students`.
    5858    If code is passed through, filter course tickets
    59     which belong to this course code and meets level
    60     and level_session.
     59    which belong to this course code and meet level=level
     60    and level_session=level_session.
     61    If not, but ct_level and ct_session
     62    are passed through, filter course tickets
     63    which meet level==ct_level and level_session==ct_session.
    6164    """
    6265    tickets = []
    6366    code = kw.get('code', None)
    6467    level = kw.get('level', None)
    65     level_session = kw.get('session', None)
     68    session = kw.get('session', None)
     69    ct_level = kw.get('ct_level', None)
     70    ct_session = kw.get('ct_session', None)
    6671    if code is None:
    6772        for level_obj in get_levels(students):
    6873            for ticket in level_obj.values():
     74                if ct_level not in ('all', None):
     75                    if level_obj.level in (10, 999, None)  \
     76                        and int(ct_level) != level_obj.level:
     77                        continue
     78                    if level_obj.level not in range(
     79                        int(ct_level), int(ct_level)+100, 10):
     80                        continue
     81                if ct_session not in ('all', None) and \
     82                    int(ct_session) != level_obj.level_session:
     83                    continue
    6984                tickets.append(ticket)
    7085    else:
     
    7388                if ticket.code != code:
    7489                    continue
    75                 if level is not None:
    76                     level = int(level)
     90                if level not in ('all', None):
    7791                    if level_obj.level in (10, 999, None)  \
    7892                        and int(level) != level_obj.level:
    7993                        continue
    80                     if level_obj.level not in range(level, level+100, 10):
     94                    if level_obj.level not in range(
     95                        int(level), int(level)+100, 10):
    8196                        continue
    82                 if level_session is not None and \
    83                     int(level_session) != level_obj.level_session:
     97                if session not in ('all', None) and \
     98                    int(session) != level_obj.level_session:
    8499                    continue
    85100                tickets.append(ticket)
     
    101116            if not ticket.editable_by_lecturer:
    102117                continue
    103             if level is not None:
    104                 level = int(level)
     118            if level not in ('all', None):
    105119                if level_obj.level in (10, 999, None)  \
    106120                    and int(level) != level_obj.level:
    107121                    continue
    108                 if level_obj.level not in range(level, level+100, 10):
     122                if level_obj.level not in range(int(level), int(level)+100, 10):
    109123                    continue
    110             if level_session is not None and \
     124            if level_session not in ('all', None) and \
    111125                int(level_session) != level_obj.level_session:
    112126                continue
     
    211225        except KeyError:
    212226            pass
     227        try:
     228            del kw['ct_level']
     229            del kw['ct_session']
     230        except KeyError:
     231            pass
    213232        query = StudentsQuery(**kw)
    214233        return query.query()
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r14642 r14984  
    680680
    681681        exporter = CourseTicketExporter()
    682         exporter.export_filtered(
    683             self.student, self.outfile)
     682        exporter.export_filtered(self.student, self.outfile)
    684683        result = open(self.outfile, 'rb').read()
    685684        self.assertEqual(
     
    691690            'Anna M. Tester\r\n'
    692691            )
    693         # if the coursetickets catalog is used to filter students
     692        # We can set the course tickets level and level_session without code
     693        # (used in the datacenter)
     694        notify(grok.ObjectModifiedEvent(self.student['studycourse']['100']['CRS1']))
     695        exporter.export_filtered(self.student, self.outfile, ct_level='100',
     696            ct_session='2012')
     697        result = open(self.outfile, 'rb').read()
     698        self.assertEqual(
     699            result,
     700            'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,'
     701            'mandatory,outstanding,passmark,score,semester,title,student_id,certcode,'
     702            'display_fullname\r\n'
     703            '1,1,CRS1,,100,DEP1,FAC1,100,2012,0,0,100,,2,Course 1,A111111,CERT1,'
     704            'Anna M. Tester\r\n'
     705            )
     706        # 'all' does select all
     707        notify(grok.ObjectModifiedEvent(self.student['studycourse']['100']['CRS1']))
     708        exporter.export_filtered(self.student, self.outfile, ct_level='all',
     709            ct_session='2012')
     710        result = open(self.outfile, 'rb').read()
     711        self.assertEqual(
     712            result,
     713            'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,'
     714            'mandatory,outstanding,passmark,score,semester,title,student_id,certcode,'
     715            'display_fullname\r\n'
     716            '1,1,CRS1,,100,DEP1,FAC1,100,2012,0,0,100,,2,Course 1,A111111,CERT1,'
     717            'Anna M. Tester\r\n'
     718            )
     719        # Level 200 tickets do not exist.
     720        notify(grok.ObjectModifiedEvent(self.student['studycourse']['100']['CRS1']))
     721        exporter.export_filtered(self.student, self.outfile, ct_level='200')
     722        result = open(self.outfile, 'rb').read()
     723        self.assertEqual(
     724            result,
     725            'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,'
     726            'mandatory,outstanding,passmark,score,semester,title,student_id,certcode,'
     727            'display_fullname\r\n'
     728                        )
     729        # Session 2013 tickets do not exist.
     730        notify(grok.ObjectModifiedEvent(self.student['studycourse']['100']['CRS1']))
     731        exporter.export_filtered(self.student, self.outfile,
     732            ct_level='all', ct_session='2013')
     733        result = open(self.outfile, 'rb').read()
     734        self.assertEqual(
     735            result,
     736            'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,'
     737            'mandatory,outstanding,passmark,score,semester,title,student_id,certcode,'
     738            'display_fullname\r\n'
     739            )
     740        # If the coursetickets catalog is used to filter students
    694741        # and (course) code is not None
    695742        # only course tickets which belong to this course are exported
Note: See TracChangeset for help on using the changeset viewer.