source: waeup/trunk/src/waeup/student/studentcontainer.py @ 4791

Last change on this file since 4791 was 4789, checked in by uli, 15 years ago

Merge changes from ulif-layout back into trunk (finally).

  • Property svn:eol-style set to native
File size: 1.6 KB
RevLine 
[3526]1import grok
[3529]2import os
[4083]3from zope.component.interfaces import IFactory
4from zope.interface import implementedBy
[3827]5from waeup.interfaces import IStudentContainer
[3529]6from waeup.utils import importexport as csv
[3526]7
[3951]8class StudentContainer(grok.Container):
[3526]9    """
10    The node containing the student models
11    """
[3827]12
13    grok.implements(IStudentContainer)
14   
[4083]15class StudentContainerFactory(grok.GlobalUtility):
16    """A factory for faculty containers.
17    """
18    grok.implements(IFactory)
19    grok.name(u'waeup.StudentContainer')
20    title = u"Create a new student container.",
21    description = u"This factory instantiates new student containers."
22
23    def __call__(self):
24        return StudentContainer()
25
26    def getInterfaces(self):
27        return implementedBy(StudentContainer)
[3827]28   
[3527]29class Import(grok.View):
30    def render(self):
[3547]31        #XXX TODO: Make import form to choose csv-file
[3527]32        t = [0]
[3529]33        src = os.path.join(os.path.dirname(__file__), '..', 'tests',
[3551]34                           'TestData','Students.csv')
[3527]35        inputfile = file(src, "r")
36        num = 0
37        headers, rows = csv.readFile(inputfile)
38        for i in rows:
[3529]39             s = fromCsv(i)
[3527]40             self.context[str(num)] = s
41             num += 1
[3529]42             if num > 100:
43                 break
[3527]44        return "%s new Students added in %s" % (num, t[0])
45
46class Export(grok.View):   
47    def render(self):
[3547]48        #XXX TODO: Make export form to choose csv-file
[3527]49        t = [0]
50        result = []
51        for s in self.context.values():
52             result.append(s.getCsv())
53        csv.writeFile(result)
54        return "yeah %s" % t[0]
Note: See TracBrowser for help on using the repository browser.