def setUp(self): self.maxDiff = None this_folder = os.path.abspath(os.path.dirname(__file__)) dummy_db_json = os.path.join(this_folder, 'dummy_db.json') self.dummy_items = json.loads(open(dummy_db_json, 'r').read()) dummy_slugs = os.path.join(this_folder, 'dummy_slugs.json') dummy_slugs = json.loads(open(dummy_slugs, 'r').read()) for i in dummy_slugs: b = Slug(**i) b.save() Dispensed.objects.create(**{ 'total_approved': 1444, 'total_dispensed': 864, 'dispensed_by_plenary': 23, 'dispensed_by_spokesmen': 12, 'dispensed_others': 11, })
def setUp(self): self.maxDiff = None this_folder = os.path.abspath(os.path.dirname(__file__)) dummy_db_json = os.path.join(this_folder, 'dummy_db.json') self.dummy_items = json.loads(open(dummy_db_json, 'r').read()) dummy_slugs = os.path.join(this_folder, 'dummy_slugs.json') dummy_slugs = json.loads(open(dummy_slugs, 'r').read()) for i in dummy_slugs: b = Slug(**i) b.save() Dispensed.objects.create( **{ 'total_approved': 1444, 'total_dispensed': 864, 'dispensed_by_plenary': 23, 'dispensed_by_spokesmen': 12, 'dispensed_others': 11, })
def handle(self, *args, **options): all_current_slugs = [ i["slug"] for i in Slug.objects.all().values("slug") ] person_names_bundled = Proyecto.objects.all().values("congresistas") all_names = [] for item in person_names_bundled: names = item["congresistas"].split(";") all_names += [i.strip() for i in names] for name in set(all_names): ascii_name = convert_to_ascii(name) slug = slugify(name) if slug not in all_current_slugs: s = Slug( ascii=ascii_name, nombre=name, slug=slug, ) s.save() print("Created slug for {!r}".format(name))