Ignore:
Timestamp:
11 Jul 2012, 09:27:23 (12 years ago)
Author:
Henrik Bettermann
Message:

Add UserProcessor? for batch importing/processing of user accounts.

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

Legend:

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

    r8757 r8973  
    2121from zope.event import notify
    2222from zope.component import getUtility, getUtilitiesFor
     23from zope.component.interfaces import IFactory
    2324from zope.interface import Interface
    2425from zope.schema import getFields
     
    3536from waeup.kofa.interfaces import (ILocalRoleSetEvent,
    3637    IUserAccount, IAuthPluginUtility, IPasswordValidator,
    37     IKofaPrincipal, IKofaPrincipalInfo, IKofaPluggable)
     38    IKofaPrincipal, IKofaPrincipalInfo, IKofaPluggable,
     39    IBatchProcessor)
     40from waeup.kofa.utils.batching import BatchProcessor
    3841
    3942def setup_authentication(pau):
     
    363366                obj, local_role, user_name, granted=False))
    364367    return
     368
     369class UserAccountFactory(grok.GlobalUtility):
     370    """A factory for user accounts.
     371
     372    This factory is only needed for imports.
     373    """
     374    grok.implements(IFactory)
     375    grok.name(u'waeup.UserAccount')
     376    title = u"Create a user.",
     377    description = u"This factory instantiates new user account instances."
     378
     379    def __call__(self, *args, **kw):
     380        return Account(name=None, password='')
     381
     382    def getInterfaces(self):
     383        return implementedBy(Account)
     384
     385class UserProcessor(BatchProcessor):
     386    """A batch processor for IUserAccount objects.
     387    """
     388    grok.implements(IBatchProcessor)
     389    grok.provides(IBatchProcessor)
     390    grok.context(Interface)
     391    util_name = 'userprocessor'
     392    grok.name(util_name)
     393
     394    name = u'User Processor'
     395    iface = IUserAccount
     396
     397    location_fields = ['name',]
     398    factory_name = 'waeup.UserAccount'
     399
     400    mode = None
     401
     402    def parentsExist(self, row, site):
     403        return 'users' in site.keys()
     404
     405    def entryExists(self, row, site):
     406        return row['name'] in site['users'].keys()
     407
     408    def getParent(self, row, site):
     409        return site['users']
     410
     411    def getEntry(self, row, site):
     412        if not self.entryExists(row, site):
     413            return None
     414        parent = self.getParent(row, site)
     415        return parent.get(row['name'])
     416
     417    def addEntry(self, obj, row, site):
     418        parent = self.getParent(row, site)
     419        parent.addAccount(obj)
     420        return
     421
    365422
    366423class UsersPlugin(grok.GlobalUtility):
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/batchprocessing.txt

    r8947 r8973  
    9999    'Student Payment Processor', 'Student Processor',
    100100    'StudentStudyCourse Processor (update only)',
    101     'StudentStudyLevel Processor', 'Verdict Processor (update only)']
     101    'StudentStudyLevel Processor',
     102    'User Processor',
     103    'Verdict Processor (update only)']
    102104
    103105    >>> importerselect.getControl('Faculty Processor').selected = True
     
    420422    ...File:...mycertcourses_zope.mgr.csv...
    421423
     424Batch processing users
     425======================
     426
     427    >>> browser.open('http://localhost/app/datacenter')
     428
     429Prepare a CSV file for certificate courses:
     430
     431    >>> open('users.csv', 'wb').write(
     432    ... """name,title,public_name,email,phone,local_roles
     433    ... uli,Uli Fouquet,Chief Developer,uli@abc.de,+49-234-567
     434    ... henrik, Henrik Bettermann,Admin,henrik@abc.de,+49-234-567,['waeup.PortalManager']
     435    ... """)
     436
     437Upload the file:
     438
     439    >>> import cStringIO
     440    >>> browser.getLink('Upload CSV file').click()
     441    >>> filecontents = cStringIO.StringIO(
     442    ...   open('users.csv', 'rb').read())
     443    >>> filewidget = browser.getControl(name='uploadfile:file')
     444    >>> filewidget.add_file(filecontents, 'text/plain', 'users.csv')
     445    >>> browser.getControl(name='SUBMIT').click()
     446
     447Step 1: start batch processing:
     448
     449    >>> browser.getLink('Batch processing').click()
     450    >>> button = lookup_submit_value(
     451    ...   'select', 'users_zope.mgr.csv', browser)
     452    >>> button.click()
     453
     454Step 2: select a processor and mode:
     455
     456    >>> importerselect = browser.getControl(name='importer')
     457    >>> importerselect.getControl('User Processor').selected = True
     458    >>> modeselect = browser.getControl(name='mode')
     459    >>> modeselect.getControl(value='create').selected = True
     460    >>> browser.getControl('Proceed to step 3').click()
     461
     462Step 3: Fix headerlines
     463
     464We get informed that there are no problems with the current header:
     465
     466    >>> print browser.contents
     467    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     468    ...
     469    Header fields OK
     470    ...
     471
     472The submit button is enabled:
     473
     474    >>> browser.getControl('Perform import').disabled
     475    False
     476
     477    >>> browser.getControl('Perform import').click()
     478
     479Step 4: See import results
     480
     481The import was successful:
     482
     483    >>> print browser.contents
     484    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     485    ...Successfully processed 2 rows...
     486    ...Batch processing finished...
     487    ...File:...users_zope.mgr.csv...
    422488
    423489Pending files
     
    551617    >>> sorted(os.listdir(dc_path + '/finished'))
    552618    ['certificates_zope.mgr.create.finished.csv', ...,
    553      'newfaculties_zope.mgr.create.finished.csv',
    554      'newfaculties_zope.mgr.csv']
     619    'users_zope.mgr.create.finished.csv', 'users_zope.mgr.csv']
    555620
    556621
Note: See TracChangeset for help on using the changeset viewer.