def add_to_db(self, entry, image_folder): new_branch = Branch() new_branch.name = entry[0] new_branch.start_year = entry[1] if entry[2] != "Current": new_branch.end_year = entry[2] if entry[3] and entry[3][-4:] != ".pdf": try: new_branch.floor_plan = File(open(image_folder + "/" + entry[3])) except IOError: self.stderr.write("Image %s not found for branch %s.\n" % (entry[3], new_branch.name)) return else: if entry[3] and entry[3][-4:] == ".pdf": self.stderr.write("PDF floorplan for %s.\n" % new_branch.name) return else: self.stderr.write("No floor plan specified for %s. Skipping\n" % new_branch.name) return new_branch.longitude = entry[4] new_branch.latitude = entry[5] if entry[6]: new_branch.description = entry[6] else: self.stderr.write("No description for %s" % new_branch.name) return new_branch.save()
def save_branch(name, description, start_year, end_year, longitude, latitude): branch = Branch() branch.name = name branch.description = description branch.start_year = start_year branch.end_year = end_year branch.floor_plan = " " branch.longitude = longitude branch.latitude = latitude branch.save() return branch