Changeset 1804 for WAeUP_SRP


Ignore:
Timestamp:
22 May 2007, 17:55:24 (18 years ago)
Author:
joachim
Message:

fix for #205, add more widgets for import_data

Location:
WAeUP_SRP/trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/PatchCatalogToolXMLAdapter.py

    r1629 r1804  
    4848    if not_found:
    4949        self._logger.info("%s modified." % na[1][1])
    50         #self._initProperties(node)
    51         #self._initObjects(node)
     50        self._initProperties(node)
     51        self._initObjects(node)
    5252        if new_indexes and len(self.context()) == 0: #disable creation of new indexes if records in the table
    5353            self._initIndexes(node)
  • WAeUP_SRP/trunk/WAeUPTool.py

    r1798 r1804  
    698698                              'nationality',
    699699                              'lga',
     700                              'birthday',
    700701                              )
    701702                              },
     
    893894                dm = DataModel(item, adapters,context=self)
    894895                logger.info('%s starts import from %s.csv' % (member,filename))
    895                 import_keys = item.keys()
    896                 diff_set = set(import_keys).difference(set(schema.keys()))
    897                 if diff_set:
    898                     logger.error('%s not in schema.' % diff_set)
    899                     return
    900                 diff_set = set(import_keys).difference(set(layout.keys()))
    901                 if diff_set:
    902                     logger.error('%s not in layout.' % diff_set)
    903                     return
     896                import_keys = [k for k in item.keys() if not k.startswith('ignore')]
     897                diff2schema = set(import_keys).difference(set(schema.keys()))
     898                diff2layout = set(import_keys).difference(set(layout.keys()))
     899                if diff2schema:
     900                    em = "not ignorable key(s) %s found in heading" % diff2schema
     901                    return em
    904902                s = ','.join(['"%s"' % fn for fn in import_keys])
    905903                open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write(s + ',"Error"'+ '\n')
     
    912910            error_string = ""
    913911            for k in import_keys:
     912                # if k == "birthday":
     913                #     from pdb import set_trace; set_trace()
    914914                if not validators[k](ds):
    915915                    error_string += " %s : %s" % (k,ds.getError(k))
  • WAeUP_SRP/trunk/Widgets.py

    r1793 r1804  
    175175###)
    176176
     177class WAeUPSessionWidget(CPSSelectWidget): ###(
     178    """WAeUP Session widget."""
     179    meta_type = 'WAeUP Session Widget'
     180
     181    def _getSessions(self):
     182        current_year = DateTime().year()
     183        d = {'xx': 'unknown'}
     184        for y in range(current_year - 9,current_year + 1):
     185            d['%s' % str(y)[-2:]] = '%4d/%4d' % (y,y+1)
     186        return d
     187
     188    def validate(self, datastructure, **kw):
     189        """Validate datastructure and update datamodel."""
     190        widget_id = self.getWidgetId()
     191        value = datastructure[widget_id]
     192        try:
     193            v = str(value)
     194        except ValueError:
     195            datastructure.setError(widget_id, "'%s' not a valid session key" % value)
     196            return 0
     197       
     198        if len(v) == 1:
     199            v = value = '0%c' % v
     200        elif not value:
     201            v = value = self.getSessionId()[-2:]
     202        #import pdb;pdb.set_trace()
     203        sessions = self._getSessions()
     204        if not sessions.has_key(value):
     205            datastructure.setError(widget_id, "'%s' not a valid session key" % v)
     206            return 0
     207        if self.is_required and not len(v):
     208            datastructure.setError(widget_id, "session key required")
     209            return 0
     210
     211        datamodel = datastructure.getDataModel()
     212        datamodel[self.fields[0]] = v
     213        return 1
     214
     215    def render(self, mode, datastructure, **kw):
     216        """Render in mode from datastructure."""
     217        value = datastructure[self.getWidgetId()]
     218        sessions = self._getSessions()
     219        if mode == 'view':
     220            return escape(sessions.get(value, value))
     221        elif mode == 'edit':
     222            html_widget_id = self.getHtmlWidgetId()
     223            res = renderHtmlTag('select', name=html_widget_id, id=html_widget_id)
     224            in_selection = 0
     225            vocabulary_items = sessions.items()
     226            if self.sorted:
     227                vocabulary_items.sort(key=operator.itemgetter(1))
     228            for k, v in vocabulary_items:
     229                kw = {'value': k, 'contents': v}
     230                if value == k:
     231                    kw['selected'] = 'selected'
     232                    in_selection = 1
     233                res += renderHtmlTag('option', **kw)
     234            if value and not in_selection:
     235                kw = {'value': value, 'contents': 'invalid: '+ str(value),
     236                      'selected': 'selected'}
     237                res += renderHtmlTag('option', **kw)
     238            res += '</select>'
     239            return res
     240        raise RuntimeError('unknown mode %s' % mode)
     241
     242InitializeClass(WAeUPSessionWidget)
     243
     244widgetRegistry.register(WAeUPSessionWidget)
     245
     246###)
     247
     248class WAeUPLevelWidget(CPSSelectWidget): ###(
     249    """WAeUP Level Widget."""
     250    meta_type = 'WAeUP Level Widget'
     251
     252    def _getLevels(self):
     253        d = {'999':'unknown'}
     254        for y in range(100,800,100):
     255            d['%s' % str(y)] = 'Year %1d (%3d Level)' % (y/100,y)
     256        return d
     257
     258    def validate(self, datastructure, **kw):
     259        """Validate datastructure and update datamodel."""
     260        widget_id = self.getWidgetId()
     261        value = datastructure[widget_id]
     262        try:
     263            v = str(value)
     264        except ValueError:
     265            datastructure.setError(widget_id, "'%s' not a valid level key" % value)
     266            return 0
     267       
     268        if not value:
     269            v = value = '100'
     270        #import pdb;pdb.set_trace()
     271        levels = self._getLevels()
     272        if not levels.has_key(value):
     273            datastructure.setError(widget_id, "'%s' not a valid level" % v)
     274            return 0
     275        if self.is_required and not len(v):
     276            datastructure.setError(widget_id, "level key required")
     277            return 0
     278
     279        datamodel = datastructure.getDataModel()
     280        datamodel[self.fields[0]] = v
     281        return 1
     282
     283    def render(self, mode, datastructure, **kw):
     284        """Render in mode from datastructure."""
     285        value = datastructure[self.getWidgetId()]
     286        levels = self._getLevels()
     287        if mode == 'view':
     288            return escape(levels.get(value, value))
     289        elif mode == 'edit':
     290            html_widget_id = self.getHtmlWidgetId()
     291            res = renderHtmlTag('select', name=html_widget_id, id=html_widget_id)
     292            in_selection = 0
     293            vocabulary_items = levels.items()
     294            if self.sorted:
     295                vocabulary_items.sort(key=operator.itemgetter(1))
     296            for k, v in vocabulary_items:
     297                kw = {'value': k, 'contents': v}
     298                if value == k:
     299                    kw['selected'] = 'selected'
     300                    in_selection = 1
     301                res += renderHtmlTag('option', **kw)
     302            if value and not in_selection:
     303                kw = {'value': value, 'contents': 'invalid: '+ str(value),
     304                      'selected': 'selected'}
     305                res += renderHtmlTag('option', **kw)
     306            res += '</select>'
     307            return res
     308        raise RuntimeError('unknown mode %s' % mode)
     309
     310InitializeClass(WAeUPLevelWidget)
     311
     312widgetRegistry.register(WAeUPLevelWidget)
     313
     314###)
     315
     316class WAeUPVerdictWidget(CPSSelectWidget): ###(
     317    """WAeUP Verdict widget."""
     318    meta_type = 'WAeUP Verdict Widget'
     319
     320    # XXX make a menu for the vocabulary.
     321    vocabulary = 'verdicts'
     322    translated = False
     323    sorted = False
     324
     325    # Associating the widget label with an input area to improve the widget
     326    # accessibility.
     327    has_input_area = True
     328
     329    def _getVerdicts(self,datastructure):
     330        voc = getattr(self.portal_vocabularies,self.vocabulary)
     331        d = {}
     332        for k,v in voc.items():
     333            d[k] = v
     334        return d
     335
     336    def validate(self, datastructure, **kw):
     337        """Validate datastructure and update datamodel."""
     338        widget_id = self.getWidgetId()
     339        value = datastructure[widget_id]
     340        try:
     341            v = str(value)
     342        except ValueError:
     343            datastructure.setError(widget_id, "'%s' not a valid verdict key" % value)
     344            return 0
     345        #import pdb;pdb.set_trace()
     346        verdicts = self._getVerdicts(datastructure)
     347        if not value:
     348            v = value = verdicts['N/A']
     349        if not verdicts.has_key(value):
     350            datastructure.setError(widget_id, "'%s' not a valid verdict key" % v)
     351            return 0
     352        if self.is_required and not len(v):
     353            datastructure.setError(widget_id, "verdict required")
     354            return 0
     355
     356        datamodel = datastructure.getDataModel()
     357        datamodel[self.fields[0]] = v
     358        return 1
     359
     360    def render(self, mode, datastructure, **kw):
     361        """Render in mode from datastructure."""
     362        value = datastructure[self.getWidgetId()]
     363        verdicts = self._getVerdicts(datastructure)
     364        if mode == 'view':
     365            return escape(verdicts.get(value, value))
     366        elif mode == 'edit':
     367            html_widget_id = self.getHtmlWidgetId()
     368            res = renderHtmlTag('select', name=html_widget_id, id=html_widget_id)
     369            in_selection = 0
     370            vocabulary_items = verdicts.items()
     371            if self.sorted:
     372                vocabulary_items.sort(key=operator.itemgetter(1))
     373            for k, v in vocabulary_items:
     374                kw = {'value': k, 'contents': v}
     375                if value == k:
     376                    kw['selected'] = 'selected'
     377                    in_selection = 1
     378                res += renderHtmlTag('option', **kw)
     379            if value and not in_selection:
     380                kw = {'value': value, 'contents': 'invalid: '+ str(value),
     381                      'selected': 'selected'}
     382                res += renderHtmlTag('option', **kw)
     383            res += '</select>'
     384            return res
     385        raise RuntimeError('unknown mode %s' % mode)
     386
     387InitializeClass(WAeUPVerdictWidget)
     388
     389widgetRegistry.register(WAeUPVerdictWidget)
     390
     391###)
     392
    177393class WAeUPReservedRoomsWidget(CPSStringWidget): ###(
    178394    """ WAeUPReservedRooms Widget"""
     
    298514        """Validate datastructure and update datamodel."""
    299515        valid = CPSStringWidget.validate(self, datastructure, **kw)
    300         #import pdb;pdb.set_trace()
    301516        jamb_nr_catalog = getattr(self,self.catalog)
    302517        widget_id = self.getWidgetId()
     
    390605###)
    391606
    392 class WAeUPSexWidget(CPSBooleanWidget):
     607class WAeUPSexWidget(CPSBooleanWidget): ###(
    393608    """WAeUP sex widget."""
    394609    meta_type = 'WAeUP Sex Widget'
     
    418633
    419634widgetRegistry.register(WAeUPSexWidget)
     635
     636###)
    420637
    421638class MatricNoWidget(CPSStringWidget): ###(
     
    9151132        return meth(mode=mode, datastructure=datastructure, **img_info)
    9161133
    917 ###)
    918 
    919 
    920 
    9211134InitializeClass(WAeUPImageWidget)
    9221135
    9231136widgetRegistry.register(WAeUPImageWidget)
     1137###)
    9241138
    9251139
  • WAeUP_SRP/trunk/__init__.py

    r1737 r1804  
    2020import PatchCPSStackingDirectoryStorageAdapter
    2121import PatchBasicWidgetsCPSStringWidget
     22import PatchExtendedWidgetsCPSDateTimeWidget
    2223import PatchBasicWidgetsUnprepare
    2324# Only for CPS 3.4.1. In 3.4.2 and later this should be fixed.
  • WAeUP_SRP/trunk/profiles/default/layouts/import_student.xml

    r1786 r1804  
    114114  <property name="hidden_readonly_layout_modes"/>
    115115 </widget>
    116  <widget name="entry_mode" meta_type="Select Widget">
     116<widget name="birthday" meta_type="DateTime Widget">
     117 <property name="title">Birthday</property>
     118 <property name="fields">
     119  <element value="birthday"/>
     120 </property>
     121 <property name="label">Birthday</property>
     122 <property name="label_edit">Birthday</property>
     123 <property name="readonly_layout_modes"/>
     124 <property name="hidden_layout_modes"/>
     125 <property name="hidden_readonly_layout_modes"/>
     126 <property name="view_format">iso8601</property>
     127 <property name="time_setting">False</property>
     128 <property name="time_hour_default">00</property>
     129</widget>
     130  <widget name="entry_mode" meta_type="Select Widget">
    117131  <property name="title">Entry Mode</property>
    118132  <property name="fields">
     
    138152  <property name="vocabulary">entry_modes</property>
    139153 </widget>
    140  <widget name="current_session" meta_type="Select Widget">
     154 <widget name="current_session" meta_type="WAeUP Session Widget">
    141155  <property name="title">Current Session</property>
    142156  <property name="fields">
     
    152166  <property name="vocabulary">sessions</property>
    153167 </widget>
    154  <widget name="current_level" meta_type="Select Widget">
     168 <widget name="current_level" meta_type="WAeUP Level Widget">
    155169  <property name="title">Current Level</property>
    156170  <property name="fields">
     
    166180  <property name="vocabulary">courselevel</property>
    167181 </widget>
    168  <widget name="current_verdict" meta_type="Select Widget">
     182 <widget name="current_verdict" meta_type="WAeUP Verdict Widget">
    169183  <property name="title">Current Verdict</property>
    170184  <property name="fields">
  • WAeUP_SRP/trunk/profiles/default/schemas/import_student.xml

    r1786 r1804  
    66 <field name="lastname" meta_type="CPS String Field"/>
    77 <field name="sex" meta_type="CPS String Field"/>
     8 <field name="birthday" meta_type="CPS String Field"/>
    89 <field name="matric_no" meta_type="CPS String Field"/>
    910 <field name="jamb_reg_no" meta_type="CPS String Field"/>
Note: See TracChangeset for help on using the changeset viewer.