Changeset 17764


Ignore:
Timestamp:
11 May 2024, 19:56:39 (8 months ago)
Author:
Henrik Bettermann
Message:

Add RefereeEntryConverter?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/converters.py

    r16818 r17764  
    2929from zope.schema.interfaces import IList
    3030from waeup.kofa.interfaces import (
    31     IObjectConverter, IResultEntryField, IFieldConverter, SubjectSource,
     31    IObjectConverter, IResultEntryField, IRefereeEntryField,
     32    IFieldConverter, SubjectSource,
    3233    GradeSource, DELETION_MARKER, IGNORE_MARKER)
    3334from waeup.kofa.schema.interfaces import IPhoneNumber
    3435from waeup.kofa.schoolgrades import ResultEntry
     36from waeup.kofa.refereeentries import RefereeEntry
    3537
    3638class ExtendedCheckBoxWidget(CheckBoxWidget):
     
    203205            "%ssubject" % (prefix): s_token,
    204206            "%sgrade" % (prefix): g_token,
     207            }
     208        return result
     209
     210class RefereeEntryConverter(grok.Adapter):
     211    grok.context(IRefereeEntryField)
     212    grok.implements(IFieldConverter)
     213
     214    def request_data(self, name, value, schema_field, prefix='',
     215                     mode='create'):
     216        """Turn CSV values into RefereeEntry-compatible form data.
     217        See ResultEntryConverter.
     218        """
     219        try:
     220            entry = RefereeEntry.from_string(value)
     221            name, email, email_sent = entry.name, entry.email, entry.email_sent
     222        except:
     223            return {prefix: value}
     224        result = {
     225            "%sname" % (prefix): name,
     226            "%semail" % (prefix): email,
    205227            }
    206228        return result
Note: See TracChangeset for help on using the changeset viewer.