redirectory.libs_int.importers.csv_importer module

CSV Importer

The CSV Importer takes care of importing CSV files containing Redirect Rules and adding them into the SQL database of the management pod.

The behaviour:

  1. If a rule in the CSV already exists it is going to be ignored.
  2. If a syntax/parsing error occurs somewhere in the CSV file the whole import is marked as failed and all of the changes to the database are roll backed.
class redirectory.libs_int.importers.csv_importer.CSVImporter(csv_byte_file_in: werkzeug.datastructures.FileStorage)[source]

Bases: object

A new CSVImporter is created for every import and the data of the CSV file is passed as a parameter in the constructor of the class.

csv_reader = None

Reader object used to parse the CSV file

data_template = {'destination': None, 'destination_is_rewrite': None, 'domain': None, 'domain_is_regex': None, 'path': None, 'path_is_regex': None, 'weight': None}

This is the template that the CSV is checked against. Every row of the CSV must match this template otherwise the whole import will fail

import_into_db()[source]

Imports all the rules in the given csv file into the database as RedirectRules. If a rule is a duplicate it will be skipped. If there is an error in parsing the csv then all the changes will be roll backed and the whole import will be marked as fail.