def test_get_individual_info_from_directory(self): self.maxDiff = None xml = """<?xml version="1.0" encoding="UTF-8"?> <responseData> <response>Success</response> <totalResults>1</totalResults> <individuals> <individual> <name>Scooter McDanger</name> <displayName>Scooter McDanger</displayName> <cnetid>scootermcdanger</cnetid> <chicagoid>12345678X</chicagoid> <contacts> <contact> <title>Programmer Analyst</title> <division> <name>Library</name> <resources> <directoryURL>https://directory.uchicago.edu/organizations/16?type=divisions</directoryURL> <xmlURL>https://directory.uchicago.edu/api/v2/divisions/16</xmlURL> </resources> </division> <email>[email protected]</email> <phone>(773) 702-1234</phone> <facultyExchange>JRL 220</facultyExchange> </contact> </contacts> <resources> <directoryURL>https://directory.uchicago.edu/individuals/12345678X</directoryURL> <xmlURL>https://directory.uchicago.edu/api/v2/individuals/12345678X</xmlURL> </resources> </individual> </individuals> </responseData> """ DirectoryUnit.objects.create( name = "Library", fullName = "Library", parentUnit = None, xmlUrl = "https://directory.uchicago.edu/api/v2/divisions/16" ) info = { 'cnetid': 'scootermcdanger', 'officialName': 'Scooter McDanger', 'displayName': 'Scooter McDanger', 'title_department_subdepartments': {'Programmer Analyst\nLibrary\nJRL 220\n773-702-1234'}, 'title_department_subdepartments_dicts': [{ 'department': DirectoryUnit.objects.get(name='Library'), 'title': 'Programmer Analyst', 'email': '*****@*****.**', 'facultyexchange': 'JRL 220', 'phone': '773-702-1234' }] } self.assertInfoEqual(get_individual_info_from_directory(xml), info)
def handle(self, *args, **options): """ The actual logic of the command. Subclasses must implement this method. It may return a Unicode string which will be printed to stdout. More: https://docs.djangoproject.com/en/1.8/howto/custom -management-commands/#django.core.management.BaseCommand.handle """ try: cnetid = options['cnetid'] except: sys.exit(1) staff_index_path = StaffIndexPage.objects.first().path staff_index_depth = StaffIndexPage.objects.first().depth staff_index_url = StaffIndexPage.objects.first().url staff_index_content_type_pk = ContentType.objects.get(model='staffindexpage').pk staff_content_type_pk = ContentType.objects.get(model='staffpage').pk xml_string = get_xml_from_directory_api('https://directory.uchicago.edu/api/v2/individuals/' + cnetid + '.xml') info = get_individual_info_from_directory(xml_string) next_available_path = get_available_path_under(staff_index_path) # Update a StaffPage # works with just 'title' set as a default. # setting path destroyed the staff index!!! # 'path': next_available_path if StaffPage.objects.filter(cnetid=info['cnetid']): sp, created = StaffPage.objects.update_or_create( cnetid=info['cnetid'], defaults = { 'title': info['displayName'], 'display_name': info['displayName'], 'official_name': info['officialName'], 'slug': make_slug(info['displayName']), 'url_path': '/loop/staff/' + make_slug(info['displayName']) + '/', 'depth': staff_index_depth + 1, }) StaffIndexPage.objects.first().fix_tree(destructive=False) else: StaffPage.objects.create( title=info['displayName'], slug=make_slug(info['displayName']), path=next_available_path, depth=len(next_available_path) // 4, numchild=0, url_path='/staff/' + make_slug(info['displayName']) + '/', cnetid=info['cnetid'], display_name=info['displayName'], official_name=info['officialName'], ) # Add new VCards for vcard in info['title_department_subdepartments_dicts']: faculty_exchange = '' if hasattr(vcard, 'facultyexchange'): faculty_exchange = vcard['facultyexchange'] email = '' if hasattr(vcard, 'email'): email = vcard['email'] phone_label = '' phone_number = '' if hasattr(vcard, 'phone'): phone_label = 'work' phone_number = vcard['phone'] v, created = StaffPagePageVCards.objects.get_or_create( title=vcard['title'], unit=DirectoryUnit.objects.get(pk=vcard['department']), faculty_exchange=faculty_exchange, email=email, phone_label=phone_label, phone_number=phone_number, page=StaffPage.objects.get(cnetid=cnetid)) # Delete unnecesary VCards for vcard in StaffPage.objects.get(cnetid=info['cnetid']).vcards.all(): d = { 'title': vcard.title, 'department': vcard.unit.id, 'facultyexchange': vcard.faculty_exchange, 'email': vcard.email, 'phone': vcard.phone_number } if not d in info['title_department_subdepartments_dicts']: vcard.delete() staff_page = StaffPage.objects.get(cnetid=info['cnetid']) staff_page.page_maintainer = staff_page staff_page.save()
def handle(self, *args, **options): """ The actual logic of the command. Subclasses must implement this method. It may return a Unicode string which will be printed to stdout. More: https://docs.djangoproject.com/en/1.8/howto/custom -management-commands/#django.core.management.BaseCommand.handle """ # api staff, wagtail staff api_staff = set(get_all_library_cnetids_from_directory()) wag_staff = set(get_all_library_cnetids_from_wagtail()) output = [] ''' # JEJ print( get_individual_info_from_directory('amybuckland') ) import sys sys.exit() ''' missing_in_api = wag_staff.difference(api_staff) if missing_in_api: output.append( "THE FOLLOWING STAFF APPEAR IN WAGTAIL, BUT NOT IN THE UNIVERSITY'S API:" ) output = output + list(missing_in_api) # if this happens, go into the user object and mark is_active False. missing_in_wagtail = api_staff.difference(wag_staff) if missing_in_wagtail: output.append( "THE FOLLOWING STAFF APPEAR IN THE UNIVERSITY'S API, BUT NOT IN WAGTAIL:" ) output = output + list(missing_in_wagtail) # if this happens, report that a new user needs to be created. for s in sorted(list(api_staff.intersection(wag_staff))): xml_string = xml_string = get_xml_from_directory_api( 'https://directory.uchicago.edu/api/v2/individuals/' + s + '.xml') api = get_individual_info_from_directory(xml_string) wag = get_individual_info_from_wagtail(s) if not api['officialName'] == wag['officialName']: output.append(s + "'s officialName is " + api['officialName'] + ", not " + wag['officialName']) if not api['displayName'] == wag['displayName']: output.append(s + "'s displayName is " + api['displayName'] + ", not " + wag['displayName']) # In the user management command, change the following things in the User object: # (note- in the User object, username = cnetid) # prompt a human for first_name, last_name. # In the StaffPage object, # check displayName and officialName. diffs = api['title_department_subdepartments'].difference( wag['title_department_subdepartments']) if diffs: output.append("THE FOLLOWING VCARDS APPEAR FOR " + s + " IN THE UNIVERSITY'S API, BUT NOT IN WAGTAIL:") for d in diffs: output.append(d) diffs = wag['title_department_subdepartments'].difference( api['title_department_subdepartments']) if diffs: output.append("THE FOLLOWING VCARDS APPEAR FOR " + s + " IN WAGTAIL, BUT NOT IN THE UNIVERSITY'S API:") for d in diffs: output.append(d) return "\n".join(output)
def handle(self, *args, **options): """ The actual logic of the command. Subclasses must implement this method. It may return a Unicode string which will be printed to stdout. More: https://docs.djangoproject.com/en/1.8/howto/custom -management-commands/#django.core.management.BaseCommand.handle """ # api staff, wagtail staff api_staff = set(get_all_library_cnetids_from_directory()) wag_staff = set(get_all_library_cnetids_from_wagtail()) output = [] ''' # JEJ print( get_individual_info_from_directory('amybuckland') ) import sys sys.exit() ''' missing_in_api = wag_staff.difference(api_staff) if missing_in_api: output.append("THE FOLLOWING STAFF APPEAR IN WAGTAIL, BUT NOT IN THE UNIVERSITY'S API:") output = output + list(missing_in_api) # if this happens, go into the user object and mark is_active False. missing_in_wagtail = api_staff.difference(wag_staff) if missing_in_wagtail: output.append("THE FOLLOWING STAFF APPEAR IN THE UNIVERSITY'S API, BUT NOT IN WAGTAIL:") output = output + list(missing_in_wagtail) # if this happens, report that a new user needs to be created. for s in sorted(list(api_staff.intersection(wag_staff))): xml_string = xml_string = get_xml_from_directory_api('https://directory.uchicago.edu/api/v2/individuals/' + s + '.xml') api = get_individual_info_from_directory(xml_string) wag = get_individual_info_from_wagtail(s) if not api['officialName'] == wag['officialName']: output.append(s + "'s officialName is " + api['officialName'] + ", not " + wag['officialName']) if not api['displayName'] == wag['displayName']: output.append(s + "'s displayName is " + api['displayName'] + ", not " + wag['displayName']) # In the user management command, change the following things in the User object: # (note- in the User object, username = cnetid) # prompt a human for first_name, last_name. # In the StaffPage object, # check displayName and officialName. diffs = api['title_department_subdepartments'].difference(wag['title_department_subdepartments']) if diffs: output.append("THE FOLLOWING VCARDS APPEAR FOR " + s + " IN THE UNIVERSITY'S API, BUT NOT IN WAGTAIL:") for d in diffs: output.append(d) diffs = wag['title_department_subdepartments'].difference(api['title_department_subdepartments']) if diffs: output.append("THE FOLLOWING VCARDS APPEAR FOR " + s + " IN WAGTAIL, BUT NOT IN THE UNIVERSITY'S API:") for d in diffs: output.append(d) return "\n".join(output)
def handle(self, *args, **options): """ The actual logic of the command. Subclasses must implement this method. It may return a Unicode string which will be printed to stdout. More: https://docs.djangoproject.com/en/1.8/howto/custom -management-commands/#django.core.management.BaseCommand.handle """ try: cnetid = options['cnetid'] except: sys.exit(1) staff_index_path = StaffIndexPage.objects.first().path staff_index_depth = StaffIndexPage.objects.first().depth staff_index_url = StaffIndexPage.objects.first().url staff_index_content_type_pk = ContentType.objects.get( model='staffindexpage').pk staff_content_type_pk = ContentType.objects.get(model='staffpage').pk xml_string = get_xml_from_directory_api( 'https://directory.uchicago.edu/api/v2/individuals/' + cnetid + '.xml') info = get_individual_info_from_directory(xml_string) next_available_path = get_available_path_under(staff_index_path) # Update a StaffPage # works with just 'title' set as a default. # setting path destroyed the staff index!!! # 'path': next_available_path if StaffPage.objects.filter(cnetid=info['cnetid']): sp, created = StaffPage.objects.update_or_create( cnetid=info['cnetid'], defaults={ 'title': info['displayName'], 'display_name': info['displayName'], 'official_name': info['officialName'], 'slug': make_slug(info['displayName']), 'url_path': '/loop/staff/' + make_slug(info['displayName']) + '/', 'depth': staff_index_depth + 1, }) StaffIndexPage.objects.first().fix_tree(destructive=False) else: StaffPage.objects.create( title=info['displayName'], slug=make_slug(info['displayName']), path=next_available_path, depth=len(next_available_path) // 4, numchild=0, url_path='/staff/' + make_slug(info['displayName']) + '/', cnetid=info['cnetid'], display_name=info['displayName'], official_name=info['officialName'], ) # Add new contact information. # for contact_info in info['title_department_subdepartments_dicts']: # add new email addresses, phone faculty exchange pairs, # telephone numbers. # Delete unnecesary contact information. staff_page = StaffPage.objects.get(cnetid=info['cnetid']) staff_page.page_maintainer = staff_page staff_page.save()