source: main/waeup.sirp/branches/ulif-paster/src/waeup/sirp/student/studentcontainer.py @ 11102

Last change on this file since 11102 was 4920, checked in by uli, 15 years ago

Make unit tests run again with the new package layout.

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1import grok
2import os
3from zope.component.interfaces import IFactory
4from zope.interface import implementedBy
5from waeup.sirp.interfaces import IStudentContainer
6from waeup.sirp.utils import importexport as csv
7
8class StudentContainer(grok.Container):
9    """
10    The node containing the student models
11    """
12
13    grok.implements(IStudentContainer)
14   
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)
28   
29class Import(grok.View):
30    def render(self):
31        #XXX TODO: Make import form to choose csv-file
32        t = [0]
33        src = os.path.join(os.path.dirname(__file__), '..', 'tests',
34                           'TestData','Students.csv')
35        inputfile = file(src, "r")
36        num = 0
37        headers, rows = csv.readFile(inputfile)
38        for i in rows:
39             s = fromCsv(i)
40             self.context[str(num)] = s
41             num += 1
42             if num > 100:
43                 break
44        return "%s new Students added in %s" % (num, t[0])
45
46class Export(grok.View):   
47    def render(self):
48        #XXX TODO: Make export form to choose csv-file
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.