def push_mapping( self, mapping_type, effective_date, timestamp, content_file ): global db Mapping.set_db(db) mapping= Mapping( timestamp= timestamp, mapping_type= mapping_type, effective_date= effective_date, ) db.save_doc( mapping ) if content_file is not None: mapping.put_attachment( content_file, name="content", content_type="text/csv" ) return mapping
def upload_mapping(mapping_type, effective_date, filename): """Upload a specific mapping file with a given effective date. The effective date must be a datetime.date object. :param mapping_type: "vehicle", "route" or "stop" mapping type :param effective_date: datetime.date at which this mapping becomes effective. Mappings remain effective until a mapping with a later effective date is pushed and validated. :param filename: a file to read and push. """ Mapping.set_db(settings.db) mapping = Mapping( timestamp=datetime.datetime.fromtimestamp(os.path.getmtime(filename)), effective_date=effective_date, mapping_type=mapping_type, ) settings.db.save_doc(mapping) with open(filename, "r") as source: mapping.put_attachment(source, name="content", content_type="text/csv") return mapping