def fullactivation(self):
     types = getPortalTypes(self)
     self.replicabletypes.update(
         dict(
             [(t, self.getTypeSchematas(t)) 
              for t in types])
     )
 def getTypeFields(self, type):
     """
     """
     fields_and_labels = [("parent", "Parent folder"), ("id", "Identifier"), ("type", "Content type")]
     types = {}
     try:
         attool = getToolByName(self.context, "archetype_tool")
         types = getPortalTypes(self.context)
     except Exception, e:
         pass
Example #3
0
 def getTypeFields(self, type):
     """
     """
     fields_and_labels = [('parent', 'Parent folder'), ('id', 'Identifier'),
                          ('type', 'Content type')]
     types = {}
     try:
         attool = getToolByName(self.context, 'archetype_tool')
         types = getPortalTypes(self.context)
     except Exception, e:
         pass
 def getTypeSchematas(self, type):
     """
     """
     attool = getToolByName(self, 'archetype_tool')
     pt = getPortalTypes(self)
     if pt.has_key(type):
         (package, name) = pt[type]
         t = attool.lookupType(package, name)
         return  t['klass'].schema.getSchemataNames()
     else:
         return []
Example #5
0
 def getTypeSchematas(self, type):
     """
     """
     attool = getToolByName(self, 'archetype_tool')
     pt = getPortalTypes(self)
     if pt.has_key(type):
         (package, name) = pt[type]
         t = attool.lookupType(package, name)
         return t['klass'].schema.getSchemataNames()
     else:
         return []
 def getTypeFields(self, type):
     """
     """
     fields_and_labels = [('parent', 'Parent folder'),
                          ('id'    , 'Identifier'),
                          ('type'  , 'Content type')]
     types = {}
     try:
         attool = getToolByName(self.context, 
                                'archetype_tool')
         types = getPortalTypes(self.context)
     except Exception, e:
         pass
    def _csvimport(
        self,
        csvfile,
        encoding,
        delimiter,
        stringdelimiter,
        datetimeformat,
        conflict_winner,
        wf_transition,
        zip,
        vocabularyvalue,
        count_created,
        count_modified,
        errors,
        ignore_content_errors=False,
        plain_format=None,
        partial_commit_number=0,
        loops=0,
        status=None,
    ):
        if status is None:
            status = {}
        csvfile.seek(0)
        # get portal types
        types = getPortalTypes(self.context)

        # read parameters
        csvtool = getToolByName(self.context, "portal_csvreplicatatool")
        if plain_format is None:
            plain_format = csvtool.getPlainFormat()
        if encoding is None:
            encoding = csvtool.getEncoding()
        if delimiter is None:
            delimiter = csvtool.getDelimiter()
        if stringdelimiter is None:
            stringdelimiter = csvtool.getStringdelimiter()
        if datetimeformat is None:
            # datetimeformat = csvtool.getDateTimeFormat()
            datetimeformat = "%Y-%m-%d"
        self.datetimeformat = datetimeformat
        self.vocabularyvalue = vocabularyvalue

        # read csv
        reader = csv.reader(csvfile, delimiter=delimiter, quotechar=stringdelimiter)
        #                                 ,
        #                                 quoting=csv.QUOTE_NONNUMERIC)
        line = 1
        # parse header
        head = reader.next()
        export_folder = head[0]
        export_date_str = str(head[1])
        export_date = None
        if not plain_format:
            export_date = strcsv_to_datetime(export_date_str)

        # parse content
        specific_fields = None
        label_line = False
        needs_another_loop = False
        offset = 0
        if plain_format:
            offset = 2

        if plain_format:
            specific_fields = head[offset + 3 :]
        # rows = [r for r in reader]
        # for row in rows:
        for idx, row in enumerate(reader):
            # if plain_format and (line ==3):
            #    export_date = strcsv_to_datetime(row[1])
            line = line + 1
            if not label_line:
                # read type fields
                if (row[0] == "parent") and not plain_format:
                    specific_fields = row[offset + 3 :]
                    # next line must not be considered (labels line)
                    label_line = True
                # read values
                else:
                    try:
                        # labels
                        if plain_format and (line == 2):
                            raise IgnoreLineException()
                        if plain_format:
                            ignore_content_errors = True
                        (is_new, is_modified, incomplete) = self.importObject(
                            row[offset:],
                            specific_fields,
                            types[row[offset + 2]],
                            conflict_winner,
                            export_date,
                            wf_transition,
                            zip,
                            encoding=encoding,
                            ignore_content_errors=ignore_content_errors,
                            plain_format=plain_format,
                            loops=loops,
                            status=status,
                        )
                        if bool(is_new):
                            count_created = count_created + 1
                        elif bool(is_modified):
                            count_modified = count_modified + 1
                        if incomplete:
                            needs_another_loop = True
                        if partial_commit_number:
                            if idx % partial_commit_number == 0:
                                transaction.commit()
                    except IgnoreLineException, e:
                        pass

                    except csvreplicataConflictException, e:
                        # errors.append("Conflict on line " + \
                        # str(line)+": %s" % (e))

                        # here content is modified during a second
                        # (or more) parsing "
                        pass

                    except csvreplicataBrokenReferenceException, e:
                        needs_another_loop = True

                    except csvreplicataNonExistentContainer, e:
                        needs_another_loop = True
Example #8
0
    def _csvimport(self,
                   csvfile,
                   encoding,
                   delimiter,
                   stringdelimiter,
                   datetimeformat,
                   conflict_winner,
                   wf_transition,
                   zip,
                   vocabularyvalue,
                   count_created,
                   count_modified,
                   errors,
                   ignore_content_errors=False,
                   plain_format=None,
                   partial_commit_number=0,
                   loops=0,
                   status=None):
        if status is None:
            status = {}
        csvfile.seek(0)
        # get portal types
        types = getPortalTypes(self.context)

        # read parameters
        csvtool = getToolByName(self.context, "portal_csvreplicatatool")
        if plain_format is None:
            plain_format = csvtool.getPlainFormat()
        if encoding is None:
            encoding = csvtool.getEncoding()
        if delimiter is None:
            delimiter = csvtool.getDelimiter()
        if stringdelimiter is None:
            stringdelimiter = csvtool.getStringdelimiter()
        if datetimeformat is None:
            #datetimeformat = csvtool.getDateTimeFormat()
            datetimeformat = "%Y-%m-%d"
        self.datetimeformat = datetimeformat
        self.vocabularyvalue = vocabularyvalue

        # read csv
        reader = csv.reader(csvfile,
                            delimiter=delimiter,
                            quotechar=stringdelimiter)
        #                                 ,
        #                                 quoting=csv.QUOTE_NONNUMERIC)
        line = 1
        # parse header
        head = reader.next()
        export_folder = head[0]
        export_date_str = str(head[1])
        export_date = None
        if not plain_format:
            export_date = strcsv_to_datetime(export_date_str)

        # parse content
        specific_fields = None
        label_line = False
        needs_another_loop = False
        offset = 0
        if plain_format:
            offset = 2

        if plain_format:
            specific_fields = head[offset + 3:]
        #rows = [r for r in reader]
        #for row in rows:
        for idx, row in enumerate(reader):
            #if plain_format and (line ==3):
            #    export_date = strcsv_to_datetime(row[1])
            line = line + 1
            if not label_line:
                # read type fields
                if (row[0] == "parent") and not plain_format:
                    specific_fields = row[offset + 3:]
                    # next line must not be considered (labels line)
                    label_line = True
                # read values
                else:
                    try:
                        # labels
                        if plain_format and (line == 2):
                            raise IgnoreLineException()
                        if plain_format: ignore_content_errors = True
                        (is_new, is_modified, incomplete) = \
                                self.importObject(
                                    row[offset:],
                                    specific_fields,
                                    types[row[offset+2]],
                                    conflict_winner,
                                    export_date,
                                    wf_transition,
                                    zip,
                                    encoding=encoding,
                                    ignore_content_errors=ignore_content_errors,
                                    plain_format=plain_format,
                                    loops=loops,
                                    status = status,
                                )
                        if bool(is_new):
                            count_created = count_created + 1
                        elif bool(is_modified):
                            count_modified = count_modified + 1
                        if incomplete:
                            needs_another_loop = True
                        if partial_commit_number:
                            if idx % partial_commit_number == 0:
                                transaction.commit()
                    except IgnoreLineException, e:
                        pass

                    except csvreplicataConflictException, e:
                        #errors.append("Conflict on line " + \
                        #str(line)+": %s" % (e))

                        # here content is modified during a second
                        # (or more) parsing "
                        pass

                    except csvreplicataBrokenReferenceException, e:
                        needs_another_loop = True

                    except csvreplicataNonExistentContainer, e:
                        needs_another_loop = True
 def getPortalTypeNames(self):
     """
     """
     l = getPortalTypes(self).keys()
     l.sort()
     return [(k, k) for k in l]
Example #10
0
 def fullactivation(self):
     types = getPortalTypes(self)
     self.replicabletypes.update(
         dict([(t, self.getTypeSchematas(t)) for t in types]))
Example #11
0
 def getPortalTypeNames(self):
     """
     """
     l = getPortalTypes(self).keys()
     l.sort()
     return [(k, k) for k in l]