Skip to content

Commit

Permalink
Merge pull request #37 from diging/develop
Browse files Browse the repository at this point in the history
new version
  • Loading branch information
jdamerow authored Jan 3, 2025
2 parents c3be2ca + 8ef519e commit 8e449c0
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 969 deletions.
28 changes: 0 additions & 28 deletions annotations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,34 +169,6 @@ def label_from_instance(self, obj):
"""
return obj.uri

def to_python(self, value):
if value in self.empty_values:
return None
try:
key = 'uri'
py_value = self.queryset.get(**{key: value})
except self.queryset.model.DoesNotExist:
import goat
goat.GOAT = settings.GOAT
goat.GOAT_APP_TOKEN = settings.GOAT_APP_TOKEN
concept = goat.Concept.retrieve(identifier=value)

data = dict(
uri=value,
label=concept.data['name'],
description=concept.data['description'],
)
ctype_data = concept.data['concept_type']#
if ctype_data:
data.update({'typed': Type.objects.get_or_create(uri=ctype_data['identifier'])[0]})

py_value = Concept.objects.create(**data)

return py_value
except (ValueError, TypeError):
raise ValidationError(self.error_messages['invalid_choice'], code='invalid_choice')
return py_value


class TemplateChoiceField(forms.ChoiceField):
def label_from_instance(self, obj):
Expand Down
1 change: 1 addition & 0 deletions annotations/templates/annotations/repository_ioerror.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
There was a problem communicating with the remote repository that contains
this content. Please go back, and try again. If this problem persists,
please contact an <a href="mailto:erick.peirson@asu.edu">administrator</a>.
<p><strong>Error:</strong> {{ error }}</p>
</p>
</div>

Expand Down
62 changes: 45 additions & 17 deletions annotations/views/repository_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from external_accounts.decorators import citesphere_authenticated
from annotations.utils import get_pagination_metadata

import traceback

def _get_params(request):
# The request may include parameters that should be passed along to the
# repository -- at this point, this is just for pagination.
Expand Down Expand Up @@ -79,7 +81,14 @@ def repository_collections(request, repository_id):
manager = RepositoryManager(user=request.user, repository=repository)
project_id = request.GET.get('project_id')

collections = manager.groups() # Fetch collections
try:
collections = manager.groups() # Fetch collections
except CitesphereAPIError as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': str(e)}, status=500)
except Exception as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': 'An unexpected error occurred'}, status=500)

context = {
'collections': collections,
Expand All @@ -102,12 +111,16 @@ def repository_collection(request, repository_id, group_id):
page = int(request.GET.get('page', 1))

try:
response_data = manager.collections(groupId=group_id)
response_data = manager.collections(group_id=group_id)
group_info = response_data.get('group')
collections = response_data.get('collections', [])
group_texts = manager.group_items(groupId=group_id, page=page)
except IOError:
return render(request, 'annotations/repository_ioerror.html', {}, status=500)
group_texts = manager.group_items(group_id=group_id, page=page)
except CitesphereAPIError as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': str(e)}, status=500)
except Exception as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': 'An unexpected error occurred'}, status=500)

project_id = request.GET.get('project_id')

Expand Down Expand Up @@ -135,7 +148,6 @@ def repository_collection(request, repository_id, group_id):
return render(request, 'annotations/repository_collection.html', context)



@citesphere_authenticated
def repository_browse(request, repository_id):
params = _get_params(request)
Expand All @@ -145,8 +157,12 @@ def repository_browse(request, repository_id):
project_id = request.GET.get('project_id')
try:
resources = manager.list(**params)
except IOError:
return render(request, 'annotations/repository_ioerror.html', {}, status=500)
except CitesphereAPIError as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': str(e)}, status=500)
except Exception as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': 'An unexpected error occurred'}, status=500)

base_url = reverse('repository_browse', args=(repository_id,))
base_params = {}
Expand All @@ -160,7 +176,6 @@ def repository_browse(request, repository_id):
'manager': manager,
'title': 'Browse repository %s' % repository.name,
'project_id': project_id,
'manager': manager,
'resources': resources['resources'],
}
previous_page, next_page = _get_pagination(resources, base_url, base_params)
Expand All @@ -172,7 +187,6 @@ def repository_browse(request, repository_id):
return render(request, 'annotations/repository_browse.html', context)



@citesphere_authenticated
def repository_search(request, repository_id):
repository = get_object_or_404(Repository, pk=repository_id)
Expand Down Expand Up @@ -270,8 +284,12 @@ def repository_collection_texts(request, repository_id, group_id, group_collecti

try:
texts = manager.collection_items(group_id, group_collection_id, page=page)
except Exception as e:
except CitesphereAPIError as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': str(e)}, status=500)
except Exception as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': 'An unexpected error occurred'}, status=500)

# retrieve items per page from settings and calculate pagination metadata from util function
items_per_page = settings.PAGINATION_PAGE_SIZE
Expand Down Expand Up @@ -308,8 +326,12 @@ def repository_text_import(request, repository_id, group_id, text_key, project_i

try:
result = manager.item(group_id, text_key)
except IOError:
return render(request, 'annotations/repository_ioerror.html', {}, status=500)
except CitesphereAPIError as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': str(e)}, status=500)
except Exception as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': 'An unexpected error occurred'}, status=500)

item_details = result.get('item', {}).get('details', {})
giles_text = result.get('item', {}).get('text', [])
Expand Down Expand Up @@ -352,8 +374,12 @@ def repository_text_content(request, repository_id, text_id, content_id):
try:
content = manager.content(id=int(content_id))
resource = manager.resource(id=int(text_id))
except IOError:
return render(request, 'annotations/repository_ioerror.html', {}, status=500)
except CitesphereAPIError as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': str(e)}, status=500)
except Exception as e:
print(traceback.format_exc())
return render(request, 'annotations/repository_ioerror.html', {'error': 'An unexpected error occurred'}, status=500)

content_type = content.get('content_type', None)
from annotations import annotators
Expand All @@ -370,8 +396,10 @@ def repository_text_content(request, repository_id, text_id, content_id):
if part_of_id:
try:
master = manager.resource(id=int(part_of_id))
except IOError:
return render(request, 'annotations/repository_ioerror.html', {}, status=500)
except CitesphereAPIError as e:
return render(request, 'annotations/repository_ioerror.html', {'error': str(e)}, status=500)
except Exception as e:
return render(request, 'annotations/repository_ioerror.html', {'error': 'An unexpected error occurred'}, status=500)
master_resource, _ = Text.objects.get_or_create(uri=master['uri'],
defaults={
'title': master.get('title'),
Expand Down
Empty file removed giles/__init__.py
Empty file.
122 changes: 0 additions & 122 deletions giles/functions.py

This file was deleted.

24 changes: 0 additions & 24 deletions giles/migrations/0001_initial.py

This file was deleted.

Empty file removed giles/migrations/__init__.py
Empty file.
14 changes: 0 additions & 14 deletions giles/models.py

This file was deleted.

Loading

0 comments on commit 8e449c0

Please sign in to comment.