示例#1
0
    def import_worksheet(self, worksheet):
        location_type = worksheet.worksheet.title

        if location_type not in defined_location_types(self.domain):
            self.results.append(_(
                "Location with type {location_type} not found, this worksheet \
                will not be imported"
                ).format(
                    location_type=location_type
                )
            )
        else:
            for loc in worksheet:
                if loc['site_code'] and loc['site_code'] in self.seen_site_codes:
                    self.results.append(_(
                        "Location {name} with site code {site_code} could not \
                        be imported due to duplicated site codes in the excel \
                        file"
                    ).format(
                        name=loc['name'],
                        site_code=loc['site_code']
                    ))
                else:
                    if loc['site_code']:
                        self.seen_site_codes.add(loc['site_code'])

                    self.results.append(import_location(
                        self.domain,
                        location_type,
                        loc,
                        self.parent_child_map
                    )['message'])
                self.excel_importer.add_progress()
示例#2
0
def import_locations(domain, worksheet, update_existing=False, task=None):
    fields = worksheet.headers

    data = list(worksheet)

    hierarchy_fields = []
    loc_types = defined_location_types(domain)
    for field in fields:
        if field in loc_types:
            hierarchy_fields.append(field)
        else:
            break
    property_fields = fields[len(hierarchy_fields):]

    if not hierarchy_fields:
        yield 'missing location hierarchy-related fields in left columns. aborting import'
        return

    loc_cache = LocationCache(domain)
    for index, loc in enumerate(data):
        if task:
            DownloadBase.set_progress(task, index, len(data))

        for m in import_location(domain, loc, hierarchy_fields, property_fields, update_existing, loc_cache):
            yield m
示例#3
0
def import_locations(domain, worksheets, task=None):
    processed = 0
    total_rows = sum(ws.worksheet.get_highest_row() for ws in worksheets)

    for worksheet in worksheets:
        location_type = worksheet.worksheet.title
        if location_type not in defined_location_types(domain):
            yield "location with type %s not found, this worksheet will not be imported" % location_type
        else:
            data = list(worksheet)

            for loc in data:
                yield import_location(domain, location_type, loc)['message']
                if task:
                    processed += 1
                    DownloadBase.set_progress(task, processed, total_rows)
示例#4
0
def import_locations(domain, worksheets, task=None):
    processed = 0
    total_rows = sum(ws.worksheet.get_highest_row() for ws in worksheets)

    for worksheet in worksheets:
        location_type = worksheet.worksheet.title
        if location_type not in defined_location_types(domain):
            yield "location with type %s not found, this worksheet will not be imported" % location_type
        else:
            data = list(worksheet)

            for loc in data:
                yield import_location(domain, location_type, loc)['message']
                if task:
                    processed += 1
                    DownloadBase.set_progress(task, processed, total_rows)
示例#5
0
def import_locations(domain, f, update_existing=False):
    r = csv.DictReader(f)
    data = list(r)

    fields = r.fieldnames
    hierarchy_fields = []
    loc_types = defined_location_types(domain)
    for field in fields:
        if field in loc_types:
            hierarchy_fields.append(field)
        else:
            break
    property_fields = fields[len(hierarchy_fields):]

    if not hierarchy_fields:
        yield 'missing location hierarchy-related fields in left columns. aborting import'
        return

    loc_cache = LocationCache(domain)
    for loc in data:
        for m in import_location(domain, loc, hierarchy_fields, property_fields, update_existing, loc_cache):
            yield m
示例#6
0
    def import_worksheet(self, worksheet):
        location_type = worksheet.worksheet.title

        if location_type not in defined_location_types(self.domain):
            self.results.append(_(
                "Location with type {location_type} not found, this worksheet \
                will not be imported"
                ).format(
                    location_type=location_type
                )
            )
        else:
            for loc in worksheet:
                if 'site_code' in loc:
                    # overwrite this value in the dict so we don't
                    # ever accidentally use a randomly capitalized veersion
                    loc['site_code'] = loc['site_code'].lower()

                if 'site_code' in loc and loc['site_code'] in self.seen_site_codes:
                    self.results.append(_(
                        "Location {name} with site code {site_code} could not \
                        be imported due to duplicated site codes in the excel \
                        file"
                    ).format(
                        name=loc['name'],
                        site_code=loc['site_code']
                    ))
                else:
                    if 'site_code' in loc:
                        self.seen_site_codes.add(loc['site_code'])

                    self.results.append(import_location(
                        self.domain,
                        location_type,
                        loc,
                        self.parent_child_map
                    )['message'])
                self.excel_importer.add_progress()
示例#7
0
    def import_worksheet(self, worksheet):
        location_type = worksheet.worksheet.title

        if location_type not in defined_location_types(self.domain):
            self.results.append(
                _("Location with type {location_type} not found, this worksheet \
                will not be imported").format(location_type=location_type))
        else:
            for loc in worksheet:
                if loc['site_code'] and loc[
                        'site_code'] in self.seen_site_codes:
                    self.results.append(
                        _("Location {name} with site code {site_code} could not \
                        be imported due to duplicated site codes in the excel \
                        file").format(name=loc['name'],
                                      site_code=loc['site_code']))
                else:
                    if loc['site_code']:
                        self.seen_site_codes.add(loc['site_code'])

                    self.results.append(
                        import_location(self.domain, location_type, loc,
                                        self.parent_child_map)['message'])
                self.excel_importer.add_progress()
 def get_terminal(self):
     relationships = loc_util.parent_child(self.domain)
     loc_types = loc_util.defined_location_types(self.domain)
     for loc_type in loc_types:
         if not relationships.get(loc_type):
             return loc_type
示例#9
0
def get_terminal(domain):
    relationships = loc_util.parent_child(domain)
    loc_types = loc_util.defined_location_types(domain)
    for loc_type in loc_types:
        if not relationships.get(loc_type):
            return loc_type
示例#10
0
 def options(self):
     return [{
         'text': k,
         'val': k
     } for k in defined_location_types(self.domain)]
示例#11
0
 def options(self):
     return [(k, k) for k in defined_location_types(self.domain)]
示例#12
0
 def options(self):
     return [{'text': k, 'val': k} for k in defined_location_types(self.domain)]
示例#13
0
 def options(self):
     return [(k, k) for k in defined_location_types(self.domain)]