Beispiel #1
0
def klassview(klass):
    form = DateForm()
    if form.validate_on_submit():
        # POST
        _d = form.dateofissue.data.isoformat()
        pdfBytes = makeSheets(
            _schoolyear,
            _d,
            klass,
            #TODO check list not empty ...
            pids=request.form.getlist('Pupil'))
        return send_file(io.BytesIO(pdfBytes),
                         attachment_filename='Mantel_%s.pdf' % klass,
                         mimetype='application/pdf',
                         as_attachment=True)
    # GET
    p = Pupils(_schoolyear)
    pdlist = p.classPupils(klass)
    klasses = [k for k in p.classes() if k >= '01' and k < '13']
    return render_template('text_cover_klass.html',
                           form=form,
                           schoolyear=str(_schoolyear),
                           klass=klass,
                           klasses=klasses,
                           pupils=[(pd['PID'], pd.name()) for pd in pdlist])
Beispiel #2
0
def textCover():
    p = Pupils(_schoolyear)
    klasses = [k for k in p.classes() if k >= '01' and k < '13']
    #TODO: Maybe a validity test for text report classes?
    #TODO: dateofissue
    return render_template(
        'text_cover_entry.html',
        schoolyear=str(_schoolyear),
        dateofissue=Dates.dateConv(_date),
        klasses=klasses)  #['01', '01K', '02', '02K', '03', '03K']
Beispiel #3
0
def migratePupils (schoolyear):
    """Read the pupil data from the previous year and build a preliminary
    database table for the current (new) year, migrating the class
    names according to <CONF.MISC.MIGRATE_CLASS>
    """
    # Get pupil data from previous year
    pdb = Pupils (schoolyear-1)
    # Maximum year number for various streams:
    maxyear = {}
    try:
        for x in CONF.MISC.STREAM_MAX_YEAR:
            k, v = x.split (':')
            maxyear [k] = v
    except:
        REPORT.Fail (_BAD_STREAM_MAX_YEAR, val=x)
    rows = []
    for c_old in pdb.classes ():
        # Increment the year part of the class name
        try:
            cnum = int (c_old [:2]) + 1
            ctag = c_old [2:]
        except:
            REPORT.Fail (_BADCLASSNAME, klass=c_old)
        c_new = '%02d%s' % (cnum, ctag)
        for prow in pdb.classPupils (c_old):
            left = False
            if prow ['EXIT_D']:
                # If there is an exit date, assume the pupil has left.
                left = True

            else:
                try:
                    mxy = maxyear [prow ['STREAM']]
                except:
                    mxy = maxyear ['']
                if cnum > int (mxy):
                    left = True

            if left:
                REPORT.Info (_PUPIL_LEFT, klass=c_old, name=prow.name ())
                continue

            prow ['CLASS'] = c_new
            rows.append (prow)

    # Create the database table PUPILS from the loaded pupil data.
    db = DB (schoolyear, flag='CANCREATE')
    # Use (CLASS, PSORT) as primary key, with additional index on PID.
    # This makes quite a small db (without rowid).
    db.makeTable2 ('PUPILS', PupilData.fields (), data=rows,
            force=True,
            pk=('CLASS', 'PSORT'), index=('PID',))
Beispiel #4
0
def klasses():
    """View: select school-class (single report generation).
    """
    schoolyear = session['year']
    # Collect list of school-classes.
    # Accept all classes here, then – when it turns out that the class
    # has no possible templates – show a message indicating this state
    # of affairs.
    pupils = Pupils(schoolyear)
    # List the classes with the oldest pupils first, as these are more
    # likely to need grades.
    klasslist = sorted(pupils.classes(), reverse=True)
    return render_template(os.path.join(_BPNAME, 'klasses.html'),
                           heading=_HEADING,
                           klasses=klasslist)
Beispiel #5
0
def index():
    schoolyear = session['year']
    form = DateForm()
    if form.validate_on_submit():
        # POST
        # Store date of issue
        _date = form.getDate()
        db = DB(schoolyear)
        db.setInfo('TEXT_DATE_OF_ISSUE', _date)

    # GET
    form.defaultIssueDate(schoolyear)
    p = Pupils(schoolyear)
    _kmap = CONF.TEXT.REPORT_TEMPLATES['Mantelbogen']
    klasses = []
    for k in p.classes():
        klass = Klass(k)
        if klass.match_map(_kmap):
            klasses.append(str(klass))
    return render_template(os.path.join(_BPNAME, 'index.html'),
                           form=form,
                           heading=_HEADING,
                           klasses=klasses)
Beispiel #6
0
def pupil(pid):
    """View: select report type and [edit-existing vs. new] for single report.

    All existing report dates for this pupil will be presented for
    selection.
    If there are no existing dates for this pupil, the only option is to
    construct a new one.
    Also a report type can be selected. The list might include invalid
    types as it is difficult at this stage (considering potential changes
    of stream or even school-class) to determine exactly which ones are
    valid.
    """
    class _Form(FlaskForm):
        KLASS = SelectField("Klasse")
        STREAM = SelectField("Maßstab")
        EDITNEW = SelectField("Ausgabedatum")
        RTYPE = SelectField("Zeugnistyp")

    schoolyear = session['year']
    # Get pupil data
    pupils = Pupils(schoolyear)
    pdata = pupils.pupil(pid)
    pname = pdata.name()
    klass = pdata.getKlass(withStream=True)
    # Get existing dates.
    db = DB(schoolyear)
    rows = db.select('GRADES', PID=pid)
    dates = [_NEWDATE]
    for row in db.select('GRADES', PID=pid):
        dates.append(row['TERM'])
    # If the stream, or even school-class have changed since an
    # existing report, the templates and available report types may be
    # different. To keep it simple, a list of all report types from the
    # configuration file GRADES.REPORT_TEMPLATES is presented for selection.
    # An invalid choice can be flagged at the next step.
    # If there is a mismatch between school-class/stream of the pupil as
    # selected on this page and that of the existing GRADES entry, a
    # warning can be shown at the next step.
    rtypes = [
        rtype for rtype in CONF.GRADES.REPORT_TEMPLATES if rtype[0] != '_'
    ]

    kname = klass.klass
    stream = klass.stream
    form = _Form(KLASS=kname, STREAM=stream, RTYPE=_DEFAULT_RTYPE)
    form.KLASS.choices = [(k, k) for k in reversed(pupils.classes())]
    form.STREAM.choices = [(s, s) for s in CONF.GROUPS.STREAMS]
    form.EDITNEW.choices = [(d, d) for d in dates]
    form.RTYPE.choices = [(t, t) for t in rtypes]

    if form.validate_on_submit():
        # POST
        klass = Klass.fromKandS(form.KLASS.data, form.STREAM.data)
        rtag = form.EDITNEW.data
        rtype = form.RTYPE.data
        kmap = CONF.GRADES.REPORT_TEMPLATES[rtype]
        tfile = klass.match_map(kmap)
        if tfile:
            return redirect(
                url_for('bp_grades.make1',
                        pid=pid,
                        kname=klass,
                        rtag=rtag,
                        rtype=rtype))
        else:
            flash(
                "Zeugnistyp '%s' nicht möglich für Gruppe %s" % (rtype, klass),
                "Error")

    # GET
    return render_template(os.path.join(_BPNAME, 'pupil.html'),
                           form=form,
                           heading=_HEADING,
                           klass=kname,
                           pname=pname)