def get_awm_record(self, cleaned_data): system_user = User.objects.get(username='******') url = cleaned_data['url'] publisher = 'Australian War Memorial' website_type = SourceType.objects.get(label='website') webpage_type = SourceType.objects.get(label='webpage') if 'roll_of_honour' in url: collection, created = Source.objects.get_or_create( title='Roll of Honour', publisher=publisher, source_type=website_type, url='http://www.awm.gov.au/research/people/roll_of_honour/', defaults={'added_by': system_user} ) awm = RollClient() elif 'embarkation' in url: collection, created = Source.objects.get_or_create( title='First World War Embarkation Roll', publisher=publisher, source_type=website_type, url='http://www.awm.gov.au/research/people/nominal_rolls/first_world_war_embarkation/', defaults={'added_by': system_user} ) awm = EmbarkationClient() elif 'wounded_and_missing' in url: collection, created = Source.objects.get_or_create( title='First World War Red Cross Wounded and Missing', publisher=publisher, source_type=website_type, url='http://www.awm.gov.au/research/people/wounded_and_missing/', defaults={'added_by': system_user} ) awm = RedCrossClient() elif 'honours_and_awards' in url: collection, created = Source.objects.get_or_create( title='Honours and Awards', publisher=publisher, source_type=website_type, url='http://www.awm.gov.au/research/people/honours_and_awards/', defaults={'added_by': system_user} ) awm = HonoursClient() details = awm.get_details(url=url) cleaned_data['details'] = details cleaned_data['title'] = details['title'] cleaned_data['source_type'] = webpage_type cleaned_data['collection'] = collection cleaned_data['url'] = url if 'title' in self._errors: del self._errors['title'] if 'source_type' in self._errors: del self._errors['source_type'] return cleaned_data
def get_awm_item(roll, url): url = re.sub(r'person\.asp\/', 'person.asp?p=', url) url = url.replace('http:/w', 'http://w') if 'roll_of_honour' in roll: awm = RollClient() elif 'embarkation' in roll: awm = EmbarkationClient() elif 'wounded_and_missing' in roll: awm = RedCrossClient() elif 'honours_and_awards' in roll: awm = HonoursClient() result = awm.get_details(url=url) return jsonify({'result': result})
def get_awm_record(self, cleaned_data): system_user = User.objects.get(username='******') url = cleaned_data['url'] publisher = 'Australian War Memorial' website_type = SourceType.objects.get(label='website') webpage_type = SourceType.objects.get(label='webpage') awm = None collection = None if 'roll_of_honour' in url: collection, created = Source.objects.get_or_create( title='Roll of Honour', publisher=publisher, source_type=website_type, url='http://www.awm.gov.au/research/people/roll_of_honour/', defaults={'added_by': system_user} ) awm = RollClient() elif 'embarkation' in url: collection, created = Source.objects.get_or_create( title='First World War Embarkation Roll', publisher=publisher, source_type=website_type, url='http://www.awm.gov.au/research/people/nominal_rolls/first_world_war_embarkation/', defaults={'added_by': system_user} ) awm = EmbarkationClient() elif 'wounded_and_missing' in url: collection, created = Source.objects.get_or_create( title='First World War Red Cross Wounded and Missing', publisher=publisher, source_type=website_type, url='http://www.awm.gov.au/research/people/wounded_and_missing/', defaults={'added_by': system_user} ) awm = RedCrossClient() elif 'honours_and_awards' in url: collection, created = Source.objects.get_or_create( title='Honours and Awards', publisher=publisher, source_type=website_type, url='http://www.awm.gov.au/research/people/honours_and_awards/', defaults={'added_by': system_user} ) awm = HonoursClient() if awm is None: self.add_error('url', 'Not a valid AWM url.') return cleaned_data try: details = awm.get_details(url=url) except URLError as e: self._errors['url'] = self.error_class(['Error accessing the url. Error: "{}"'.format(e.reason)]) return cleaned_data except Exception as e: self._errors['url'] = self.error_class(['Error accessing the url. Error: "{}"'.format(e)]) return cleaned_data cleaned_data['details'] = details cleaned_data['title'] = details['title'] cleaned_data['source_type'] = webpage_type cleaned_data['collection'] = collection cleaned_data['url'] = url if 'title' in self._errors: del self._errors['title'] if 'source_type' in self._errors: del self._errors['source_type'] return cleaned_data