예제 #1
0
    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
예제 #2
0
    def test_clean_up_name2(self):
        #ARRANGE
        name_1_raw = u"  Karina   Hluhovs'ka  "  # teacher from Go Yoga studio
        name_1_expected = u'Karina Hluhovska'

        name_2_raw = '  Jennifer A. '
        name_2_expected = 'Jennifer A'

        name_3_raw = u'Grace (Sangeet Kaur) Kim (12)'
        name_3_expected = u'Grace (Sangeet Kaur) Kim'

        name_4_raw = u" Ambyr D'Amato "  # Loom Studios
        name_4_expected = u'Ambyr DAmato'

        name_5_raw = u"  TBA . "
        name_5_expected = u''

        name_6_raw = u"  Blossoming Teachers "
        name_6_expected = u''

        name_7_raw = u" * * "
        name_7_expected = u''

        name_8_raw = u" YTTP "
        name_8_expected = u''

        name_9_raw = u"    "
        name_9_expected = u''

        name_10_raw = u" "
        name_10_expected = u''

        name_11_raw = u" To Be Determined "
        name_11_expected = u''

        #ACT
        name_1_clean = Instructor.clean_up_name(name_1_raw)
        name_2_clean = Instructor.clean_up_name(name_2_raw)
        name_3_clean = Instructor.clean_up_name(name_3_raw)
        name_4_clean = Instructor.clean_up_name(name_4_raw)
        name_5_clean = Instructor.clean_up_name(name_5_raw)
        name_6_clean = Instructor.clean_up_name(name_6_raw)
        name_7_clean = Instructor.clean_up_name(name_7_raw)
        name_8_clean = Instructor.clean_up_name(name_8_raw)
        name_9_clean = Instructor.clean_up_name(name_9_raw)
        name_10_clean = Instructor.clean_up_name(name_10_raw)
        name_11_clean = Instructor.clean_up_name(name_11_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)
        self.assertEqual(name_5_clean, name_5_expected)
        self.assertEqual(name_6_clean, name_6_expected)
        self.assertEqual(name_7_clean, name_7_expected)
        self.assertEqual(name_8_clean, name_8_expected)
        self.assertEqual(name_9_clean, name_9_expected)
        self.assertEqual(name_10_clean, name_10_expected)
        self.assertEqual(name_11_clean, name_11_expected)
예제 #3
0
    def test_clean_up_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'

        name_5_raw = u"Carrie Gaynor @ 520 Packett's Landing"
        name_5_expected = u'Carrie Gaynor'

        name_6_raw = u"  "
        name_6_expected = u''

        name_7_raw = u" TEACHER "
        name_7_expected = u''

        name_8_raw = u" Teacher   TEACHER  "  # bikram yoga harlem
        name_8_expected = u''

        name_9_raw = u"  Staff  "
        name_9_expected = u''

        name_10_raw = u"  Staff   staff  "
        name_10_expected = u''

        name_11_raw = u"  STAFF   MEMBER  "  # Atmananda Yoga Sequence
        name_11_expected = u''

        name_12_raw = u"    GOLDEN  BRIDGE   STAFF "
        #name_12_raw = u" Lotus STAFF "
        name_12_expected = u''

        name_13_raw = u"  STAFF  "
        name_13_expected = u''

        #ACT
        name_1_clean = Instructor.clean_up_name(name_1_raw)
        name_2_clean = Instructor.clean_up_name(name_2_raw)
        name_3_clean = Instructor.clean_up_name(name_3_raw)
        name_4_clean = Instructor.clean_up_name(name_4_raw)
        name_5_clean = Instructor.clean_up_name(name_5_raw)
        name_6_clean = Instructor.clean_up_name(name_6_raw)
        name_7_clean = Instructor.clean_up_name(name_7_raw)
        name_8_clean = Instructor.clean_up_name(name_8_raw)
        name_9_clean = Instructor.clean_up_name(name_9_raw)
        name_10_clean = Instructor.clean_up_name(name_10_raw)
        name_11_clean = Instructor.clean_up_name(name_11_raw)
        name_12_clean = Instructor.clean_up_name(name_12_raw)
        name_13_clean = Instructor.clean_up_name(name_13_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)
        self.assertEqual(name_5_clean, name_5_expected)
        self.assertEqual(name_6_clean, name_6_expected)
        self.assertEqual(name_7_clean, name_7_expected)
        self.assertEqual(name_8_clean, name_8_expected)
        self.assertEqual(name_9_clean, name_9_expected)
        self.assertEqual(name_10_clean, name_10_expected)
        self.assertEqual(name_11_clean, name_11_expected)
        self.assertEqual(name_12_clean, name_12_expected)
        self.assertEqual(name_13_clean, name_13_expected)