Пример #1
0
 def worksheets(self):
     """The gspread Worksheets recognized by any of the interpreters."""
     l = []
     for worksheet in self.spreadsheet.worksheets():
         try:
             InterpreterFactory.make_interpreter(self, worksheet.title)
             l.append(worksheet)
         except InterpreterNotFound:
             pass  # worksheet not recognized
     return l
Пример #2
0
 def worksheets(self):
     '''The gspread Worksheets recognized by any of the interpreters.'''
     l = []
     for worksheet in self.spreadsheet.worksheets():
         try:
             InterpreterFactory.make_interpreter(self, worksheet.title)
             l.append(worksheet)
         except InterpreterNotFound:
             pass  # worksheet not recognized
     return l
Пример #3
0
    def simulate(self, worksheet_name):
        """
        Receives a worksheet name, parses it, and returns a list of annotated
        dicts with errors and warnings.

        Example:

            ish = Importsheet(name='Schools Mapping', project=p, ...)
            ish.simulate('organization')
        """
        worksheet = self.spreadsheet.worksheet(worksheet_name)
        worksheet_interpreter = InterpreterFactory.make_interpreter(self, worksheet.title)
        worksheet_interpreter.parse()
        return worksheet_interpreter
Пример #4
0
    def simulate(self, worksheet_name):
        '''
        Receives a worksheet name, parses it, and returns a list of annotated
        dicts with errors and warnings.

        Example:

            ish = Importsheet(name='Schools Mapping', project=p, ...)
            ish.simulate('organization')
        '''
        worksheet = self.spreadsheet.worksheet(worksheet_name)
        worksheet_interpreter = InterpreterFactory.make_interpreter(
            self, worksheet.title)
        worksheet_interpreter.parse()
        return worksheet_interpreter
Пример #5
0
    def insert(self, worksheet_name):
        """
        Imports data from each one of the worksheets in the spreadsheet.

        Example:

            ish = Importsheet(name='Schools Mapping', project=p, ...)
            ish.insert()
        """

        worksheet = self.spreadsheet.worksheet(worksheet_name)
        interpreter = InterpreterFactory.make_interpreter(self, worksheet.title)
        success = interpreter.insert()
        if success:
            # link objects to importsheet and to project
            for obj in interpreter.objects:
                self.project.save_related_object(obj)
                self.save_related_object(obj)
                obj.save()
            self.inserted = True
            self.save()

        return success
Пример #6
0
    def insert(self, worksheet_name):
        '''
        Imports data from each one of the worksheets in the spreadsheet.

        Example:

            ish = Importsheet(name='Schools Mapping', project=p, ...)
            ish.insert()
        '''

        worksheet = self.spreadsheet.worksheet(worksheet_name)
        interpreter = InterpreterFactory.make_interpreter(
            self, worksheet.title)
        success = interpreter.insert()
        if success:
            # link objects to importsheet and to project
            for obj in interpreter.objects:
                self.project.save_related_object(obj)
                self.save_related_object(obj)
                obj.save()
            self.inserted = True
            self.save()

        return success