def test_convert_to_url_name(self): #ARRANGE name_1_raw = u'Leslie Lewis (3)' name_1_expected = 'leslie-lewis' name_2_raw = 'Leslie Lewis (3)' name_2_expected = 'leslie-lewis' name_3_raw = u' lulu ekiert ' name_3_expected = u'lulu-ekiert' name_4_raw = u'Aimee McCabe - Karr' name_4_expected = u'aimee-mccabe-karr' #ACT name_1_clean = Instructor.convert_to_url_name(name_1_raw) name_2_clean = Instructor.convert_to_url_name(name_2_raw) name_3_clean = Instructor.convert_to_url_name(name_3_raw) name_4_clean = Instructor.convert_to_url_name(name_4_raw) #ASSERT self.assertEqual(name_1_clean, name_1_expected) self.assertEqual(name_2_clean, name_2_expected) self.assertEqual(name_3_clean, name_3_expected) self.assertEqual(name_4_clean, name_4_expected)
def instr(self, event): """ @type event: Event """ if event.instructor: url = reverse('admin:%s_%s_changelist' % ("schyoga", "instructor")) url = url + "?id=" + str(event.instructor_id) return format_html('<a href="{0}" target="_blank" title="{0}"><span class="glyphicon glyphicon-user"></span></a>', url) instructor_name = event.instructor_name if not instructor_name: return if Instructor.clean_up_name(instructor_name) == '': return instructor_name_url = Instructor.convert_to_url_name(instructor_name) studio_id = event.studio_id state_name_url = event.studio.state_name_url add_url = reverse('admin:%s_%s_add' % ("schyoga", "instructor")) add_url = add_url +('?name_url=%s&instructor_name=%s&aliases=%s&state_name_url=%s&studios=%s'% (instructor_name_url,instructor_name,instructor_name,state_name_url,studio_id)) add_link='<a href="'+add_url+'" target="_blank" title="Add: '+instructor_name+'"><span class="glyphicon glyphicon-floppy-disk"></span> Add New</a>' matching_instructors = Instructor.objects.all().filter(aliases__icontains=instructor_name) if matching_instructors: result = "" for instr in matching_instructors: result = result+self.__build_html_link_to_instructor(instr, event) return result+add_link #instructor_sub_names = instructor_name.split(" ") instructor_sub_names = re.split(' |-',instructor_name) print ('divided/SPLIT name '+instructor_name+' into '+repr(instructor_sub_names)) query = Q() if len(instructor_sub_names) > 1: #print "count is: "+repr(instructor_sub_names[0])+" "+repr(instructor_sub_names[1]) #TODO: add loop here to search by all subnames, not just first two for sub_name in instructor_sub_names: query = query | Q(aliases__icontains=sub_name) #query = query | Q(aliases__icontains=instructor_sub_names[0]) #query = query | Q(aliases__contains=instructor_sub_names[1]) matching_instructors = Instructor.objects.all().filter(query) if matching_instructors: #link_url = reverse('admin:%s_%s_add' % ("schyoga", "instructor")) result = "" for instr in matching_instructors: result = result+self.__build_html_link_to_instructor(instr, event) return result+add_link return add_link