Changeset 6828


Ignore:
Timestamp:
29 Sep 2011, 06:37:15 (13 years ago)
Author:
Henrik Bettermann
Message:

Catch double headers already in import step 2. Do not show table if double headers occur.

Create warning messages in views and use flash method to render warnings.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r6688 r6828  
    540540        result = []
    541541        num = 0
     542        if not self.reader:
     543            return
    542544        for row in self.reader:
    543545            if num > 4:
     
    572574        return parts[1]
    573575
     576    def getWarnings(self):
     577        import sys
     578        result = []
     579        try:
     580            headerfields = self.getPreviewHeader()
     581            headerfields_clean = list(set(headerfields))
     582            if len(headerfields) > len(headerfields_clean):
     583                result.append(
     584                    "Double headers: each column name may only appear once. ")
     585        except:
     586            fatal = '%s' % sys.exc_info()[1]
     587            result.append(fatal)
     588        if result:
     589            warnings = ""
     590            for line in result:
     591                warnings += line + '<br />'
     592            warnings += 'Replace imported file!'
     593            return warnings
     594        return False
     595
    574596    def update(self, mode=None, importer=None,
    575597               back1=None, cancel=None, proceed=None):
     
    596618            return
    597619        self.fullpath = os.path.join(self.context.storage, self.filename)
    598         self.reader = csv.DictReader(open(self.fullpath, 'rb'))
     620        warnings = self.getWarnings()
     621        if not warnings:
     622            self.reader = csv.DictReader(open(self.fullpath, 'rb'))
     623        else:
     624            self.reader = ()
     625            self.flash(warnings)
    599626
    600627class DatacenterImportStep3(WAeUPPage):
     
    659686            fatal = '%s' % sys.exc_info()[1]
    660687            result.append(fatal)
    661         return result
     688        if result:
     689            warnings = ""
     690            for line in result:
     691                warnings += line + '<br />'
     692            warnings += 'Edit headers or replace imported file!'
     693            return warnings
     694        return False
    662695
    663696    @property
     
    689722            self.redirect(self.url(self.context, '@@import4'))
    690723            return
    691 
    692724        self.importer = getUtility(IBatchProcessor, name=self.importername)
    693725        self.reader = csv.DictReader(open(self.fullpath, 'rb'))
     726        warnings = self.getWarnings()
     727        if warnings:
     728            self.flash(warnings)
    694729
    695730class DatacenterImportStep4(WAeUPPage):
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/batching.py

    r6824 r6828  
    9292                    "Need at least columns %s for import!" %
    9393                    ', '.join(["'%s'" % x for x in req]))
    94         # Check for double fields...
     94        # Check for double fields. Cannot happen because this error is
     95        # already catched in views
    9596        not_ignored_fields = [x for x in headerfields
    9697                              if not x.startswith('--')]
Note: See TracChangeset for help on using the changeset viewer.