import grok import os from zope.component.interfaces import IFactory from zope.interface import implementedBy from waeup.sirp.interfaces import IStudentContainer from waeup.sirp.utils import importexport as csv class StudentContainer(grok.Container): """ The node containing the student models """ grok.implements(IStudentContainer) class StudentContainerFactory(grok.GlobalUtility): """A factory for faculty containers. """ grok.implements(IFactory) grok.name(u'waeup.StudentContainer') title = u"Create a new student container.", description = u"This factory instantiates new student containers." def __call__(self): return StudentContainer() def getInterfaces(self): return implementedBy(StudentContainer) class Import(grok.View): def render(self): #XXX TODO: Make import form to choose csv-file t = [0] src = os.path.join(os.path.dirname(__file__), '..', 'tests', 'TestData','Students.csv') inputfile = file(src, "r") num = 0 headers, rows = csv.readFile(inputfile) for i in rows: s = fromCsv(i) self.context[str(num)] = s num += 1 if num > 100: break return "%s new Students added in %s" % (num, t[0]) class Export(grok.View): def render(self): #XXX TODO: Make export form to choose csv-file t = [0] result = [] for s in self.context.values(): result.append(s.getCsv()) csv.writeFile(result) return "yeah %s" % t[0]