Skip to content

Commit

Permalink
Merge pull request #1228 from laws-africa/tasks
Browse files Browse the repository at this point in the history
Tasks
  • Loading branch information
longhotsummer authored Jan 19, 2021
2 parents ca833d9 + 2d9b245 commit 8b007df
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
6 changes: 3 additions & 3 deletions indigo/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def resolve(self, exact):
escaped = prefix.replace("'", "\\'")
# find the attachment with this id
results = list(self.document.doc.main.xpath(f"./a:attachments/a:attachment[@eId='{escaped}']", namespaces={'a': self.document.doc.namespace}))
if results:
if len(results):
component = results[0]
else:
component = self.document.doc.main
Expand All @@ -44,14 +44,14 @@ def resolve(self, exact):
while anchor_id:
escaped = anchor_id.replace("'", "\\'")
elems = component.xpath(f".//a:*[@eId='{escaped}']", namespaces={'a': self.document.doc.namespace})
if elems:
if len(elems):
self.resolve_element(elems[0])
break
elif anchor_id in ['preface', 'preamble']:
# HACK HACK HACK
# We sometimes use 'preamble' and 'preface' even though they aren't IDs
elems = component.xpath(f".//a:{escaped}", namespaces={'a': self.document.doc.namespace})
if elems:
if len(elems):
self.resolve_element(elems[0])
break

Expand Down
19 changes: 17 additions & 2 deletions indigo_api/tests/test_annotations_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,29 @@ def test_cant_change_logged_out(self):
def test_create_annotation_task(self):
response = self.client.post('/api/documents/10/annotations', {
'text': 'hello',
'anchor_id': 'section.1',
'anchor_id': 'sec_1',
})

assert_equal(response.status_code, 201)
note_id = response.data['id']

response = self.client.post('/api/documents/10/annotations/%s/task' % note_id)
assert_equal(response.status_code, 201)
assert_equal(response.data['title'], '"section.1": hello')
assert_equal(response.data['title'], '"Section 1.": hello')
assert_equal(response.data['state'], 'open')
assert_is_none(response.data.get('anchor_id'))

def test_create_annotation_task_anchor_missing(self):
response = self.client.post('/api/documents/10/annotations', {
'text': 'hello',
# sec_99 doesn't exist
'anchor_id': 'sec_99',
})
assert_equal(response.status_code, 201)
note_id = response.data['id']

response = self.client.post('/api/documents/10/annotations/%s/task' % note_id)
assert_equal(response.status_code, 201)
assert_equal(response.data['title'], '"sec_99": hello')
assert_equal(response.data['state'], 'open')
assert_is_none(response.data.get('anchor_id'))
4 changes: 2 additions & 2 deletions indigo_app/templates/indigo_api/_task_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ <h5>
<li class="activity-item">
{% if anchor.element %}
Here is
<a href="{% url 'document' doc_id=task.document.pk %}?toc={{ anchor.toc_entry.qualified_id|default:'' }}&anntn={{ task.annotation.id }}">{{ anchor.toc_entry.title }}</a>
<a href="{% url 'document' doc_id=task.document.pk %}?toc={{ anchor.toc_entry.qualified_id|default:'' }}&anntn={{ task.annotation.id }}">{{ anchor.toc_entry.title|default:anchor.anchor_id }}</a>
as it appears currently
{% if not anchor.exact_match %}(<b>{{ anchor.anchor_id }}</b> may have been moved or removed){% endif %}
<div class="sheet-outer"
{% if anchor.selectors or not anchor.is_toc_element %}data-highlight="{{ anchor.target|jsonify|escape }}"{% endif %}>
<div class="sheet-inner is-fragment">
<div class="akoma-ntoso country-{{ anchor.document.country }}">{{ anchor.toc_element_html|safe }}</div>
<div class="akoma-ntoso country-{{ anchor.document.country }}">{{ anchor.toc_element_html|default:anchor.element_html|safe }}</div>
</div>
</div>
{% else %}
Expand Down
22 changes: 12 additions & 10 deletions indigo_app/views/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def record_workflow_actions(self, task, new_workflows):
target=workflow, place_code=task.place.place_code)


class SingleTaskViewBase(TaskViewBase):
model = Task

def get_queryset(self):
return super().get_queryset().filter(country=self.country, locality=self.locality)


class TaskListView(TaskViewBase, ListView):
context_object_name = 'tasks'
model = Task
Expand Down Expand Up @@ -92,9 +99,8 @@ def get_context_data(self, **kwargs):
return context


class TaskDetailView(TaskViewBase, DetailView):
class TaskDetailView(SingleTaskViewBase, DetailView):
context_object_name = 'task'
model = Task

def get_context_data(self, **kwargs):
context = super(TaskDetailView, self).get_context_data(**kwargs)
Expand Down Expand Up @@ -213,13 +219,12 @@ def get_success_url(self):
return reverse('task_detail', kwargs={'place': self.kwargs['place'], 'pk': self.object.pk})


class TaskEditView(TaskViewBase, UpdateView):
class TaskEditView(SingleTaskViewBase, UpdateView):
# permissions
permission_required = ('indigo_api.change_task',)

context_object_name = 'task'
form_class = TaskForm
model = Task

def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
Expand Down Expand Up @@ -273,13 +278,12 @@ def get_context_data(self, **kwargs):
return context


class TaskChangeStateView(TaskViewBase, View, SingleObjectMixin):
class TaskChangeStateView(SingleTaskViewBase, View, SingleObjectMixin):
# permissions
permission_required = ('indigo_api.change_task',)

change = None
http_method_names = ['post']
model = Task

def post(self, request, *args, **kwargs):
task = self.get_object()
Expand Down Expand Up @@ -331,13 +335,12 @@ def get_redirect_url(self):
return reverse('task_detail', kwargs={'place': self.kwargs['place'], 'pk': self.kwargs['pk']})


class TaskAssignView(TaskViewBase, View, SingleObjectMixin):
class TaskAssignView(SingleTaskViewBase, View, SingleObjectMixin):
# permissions
permission_required = ('indigo_api.change_task',)

unassign = False
http_method_names = ['post']
model = Task

def post(self, request, *args, **kwargs):
task = self.get_object()
Expand Down Expand Up @@ -367,12 +370,11 @@ def get_redirect_url(self):
return reverse('task_detail', kwargs={'place': self.kwargs['place'], 'pk': self.kwargs['pk']})


class TaskChangeWorkflowsView(TaskViewBase, View, SingleObjectMixin):
class TaskChangeWorkflowsView(SingleTaskViewBase, View, SingleObjectMixin):
# permissions
permission_required = ('indigo_api.change_task',)

http_method_names = ['post']
model = Task

def post(self, request, *args, **kwargs):
task = self.get_object()
Expand Down

0 comments on commit 8b007df

Please sign in to comment.