def account_name(context): """ Generates a name for a sub-account. The passed context is one of these SWS models: Campus, College, Department, Curriculum """ name = titleize(context.full_name) if isinstance(context, Curriculum): name = re.sub(r"(\(?(UW )?Bothell( Campus)?\)?|Bth)$", "", name) name = re.sub(r"(\(?(UW )?Tacoma( Campus)?\)?|T)$", "", name) name = re.sub(r"[\s-]+$", "", name) name += " [{}]".format(context.label) return name
def section_long_name(section): name = '{curr_abbr} {course_num} {section_id} {quarter} {year}'.format( curr_abbr=section.curriculum_abbr, course_num=section.course_number, section_id=section.section_id, quarter=section.term.quarter[:2].capitalize(), year=str(section.term.year)[-2:]) if (section.course_title_long is not None and len(section.course_title_long)): name = '{name}: {title}'.format( name=name, title=titleize(section.course_title_long)) if section.is_independent_study: for person in section.get_instructors(): if person.uwregid == section.independent_study_instructor_regid: name = '{name} ({user_fullname})'.format( name=name, user_fullname=person.get_formatted_name('{first} {last}')) break return name
def test_titleize(self): self.assertRaises(TypeError, titleize, None) self.assertEquals(titleize(123), '123') self.assertEquals(titleize(''), '') self.assertEquals(titleize('the'), 'The') self.assertEquals(titleize('THE'), 'The') self.assertEquals(titleize('the xml'), 'The XML') self.assertEquals(titleize('the xml'), 'The XML') self.assertEquals(titleize('the:xml'), 'The:XML') self.assertEquals(titleize('the-xml'), 'The-XML') self.assertEquals(titleize('the.xml'), 'The.XML') self.assertEquals(titleize('the&xml'), 'The&XML') self.assertEquals(titleize('the i'), 'The I') self.assertEquals(titleize('THE II'), 'The II') self.assertEquals(titleize('THE Iii'), 'The III') self.assertEquals(titleize('THE Iv'), 'The IV') self.assertEquals(titleize('the (now)'), 'The (Now)') self.assertEquals(titleize('joe\'s xml'), 'Joe\'s XML') self.assertEquals(titleize('xml/Xml'), 'XML/XML') self.assertEquals(titleize('the "xml"'), 'The "XML"') self.assertEquals(titleize('the "now"'), 'The "Now"')