def get_cwgc_record(self, cleaned_data): system_user = User.objects.get(username='******') url = cleaned_data['url'] publisher = 'Commonwealth War Graves Commission' website_type = SourceType.objects.get(label='website') webpage_type = SourceType.objects.get(label='webpage') cwgc = CWGCClient() url = cleaned_data['url'] details = cwgc.get_details(url) collection, created = Source.objects.get_or_create( title='Find War Dead', publisher=publisher, source_type=website_type, url='http://www.cwgc.org/find-war-dead.aspx', defaults={'added_by': system_user} ) cleaned_data['details'] = details cleaned_data['title'] = 'Find War Dead – {}'.format(details['name'].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_cwgc_record(self, cleaned_data): system_user = User.objects.get(username='******') url = cleaned_data['url'] publisher = 'Commonwealth War Graves Commission' website_type = SourceType.objects.get(label='website') webpage_type = SourceType.objects.get(label='webpage') cwgc = CWGCClient() try: details = cwgc.get_details(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 collection, created = Source.objects.get_or_create( title='Find War Dead', publisher=publisher, source_type=website_type, url='http://www.cwgc.org/find-war-dead.aspx', defaults={'added_by': system_user} ) cleaned_data['details'] = details cleaned_data['title'] = 'Find War Dead – {}'.format(details['name'].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_cwgc_item(url): url = url.replace(' ', '%20') url = url.replace('http:/w', 'http://w') cwgc = CWGCClient() result = cwgc.get_details(url) return jsonify({'result': result})