def get_tags(self): self.__connect() self.curs.execute(TAG_QUERY) tags = self.curs.fetchall() print "Deleting all tags" Tag.objects.all().delete() print "Adding tags" for tag in tags: t = Tag(**tag) t.save() print "Deleting tag hierarchy" TagHierarchy.objects.all().delete() print "Adding tag hierarchy" self.curs.execute(TAG_HIERARCHY_QUERY) tag_hierarchy = self.curs.fetchall() for t in tag_hierarchy: tag = Tag.objects.get(old_id=t.get('tid', None)) if not t.get('parent') == 0: parent = Tag.objects.get(old_id=t.get('parent', None)) else: parent = None t = TagHierarchy(tag=tag, parent=parent) t.save() self.__disconnect()
def tag_handler(tags): new_tags = [] if tags: tag_list = map(lambda tag: str(tag.strip()), tags.split(',')) tag_objects = Tag.objects.all() if tag_objects: for tag_object in tag_objects: found = False for tag in tag_list: if tag == str(tag_object.name).strip(): new_tags.append(tag_object) found = True break if not found: tag_instance = Tag(name=tag) tag_instance.save() new_tags.append(tag_instance) else: for tag in tag_list: tag_instance = Tag(name=tag) tag_instance.save() new_tags.append(tag_instance) return new_tags
def get_tags(self): self.__connect() self.curs.execute(TAG_QUERY) tags = self.curs.fetchall() print "Deleting all tags" Tag.objects.all().delete() print "Adding tags" for tag in tags: print tag t = Tag(**tag) t.name = my_decoder(t.name) t.description = my_decoder(t.description) t.save() print "Deleting tag hierarchy" TagHierarchy.objects.all().delete() print "Adding tag hierarchy" self.curs.execute(TAG_HIERARCHY_QUERY) tag_hierarchy = self.curs.fetchall() for t in tag_hierarchy: tag = Tag.objects.get(old_id=t.get('tid', None)) if not t.get('parent') == 0: parent = Tag.objects.get(old_id=t.get('parent', None)) else: parent = None t = TagHierarchy(tag=tag, parent=parent) t.save() # Tag export to CSV #self.__write_tags_to_csv(tags) self.__disconnect()