Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #247 from editorsnotes/restore-transcripts
Browse files Browse the repository at this point in the history
Restore transcript editing, fix zotero editing bug
  • Loading branch information
ptgolden committed Oct 21, 2014
2 parents 0d352e2 + db2e216 commit 0c4751b
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v0.8.5
=======
* Add transcript link to Document API serializer
* Add 'Add/Edit Transcript' button to Document editing view
* Hide Note and Attachment fields from Zotero editing form

v0.8.4
=======
* Allow draggable widgets to work on tablets
Expand Down
1 change: 0 additions & 1 deletion editorsnotes/admin/templates/admin_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{% load display staticfiles %}

{% block js %}
<script src="{% static "function/zotero.jquery.js" %}"></script>
<script src="{% static "function/admin-bootstrap-base.js" %}"></script>
{% if form.media %}{{ form.media.js }}{% endif %}
{% endblock %}
Expand Down
16 changes: 8 additions & 8 deletions editorsnotes/admin/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ def get_context_data(self, **kwargs):
context['bootstrap'] = 'null';
return context

class BaseAdminView(ProcessInlineFormsetsView, ProjectSpecificMixin,
ModelFormMixin, BreadcrumbMixin, TemplateResponseMixin):
class BaseAdminView(ProjectSpecificMixin, BreadcrumbMixin, ModelFormMixin,
TemplateResponseMixin, ProcessInlineFormsetsView):
def get_form_kwargs(self):
kwargs = super(ModelFormMixin, self).get_form_kwargs()
if hasattr(self, 'object') and self.object:
kwargs.update({'instance': self.object})
else:
has_project_field = all([
hasattr(self.model, 'project'),
hasattr(self.model.project, 'field'),
hasattr(self.model.project.field, 'related'),
self.model.project.field.related.parent_model == Project
])
has_project_field = (
hasattr(self.model, 'project')
and hasattr(self.model.project, 'field')
and hasattr(self.model.project.field, 'related')
and self.model.project.field.related.parent_model == Project
)
if has_project_field:
# Then create an instance with the project already set
instance = self.model(project=self.project)
Expand Down
9 changes: 9 additions & 0 deletions editorsnotes/admin/views/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,12 @@ def save_footnote_formset_form(self, form):
a = transcript.content.cssselect('a.footnote[href$="%s"]' % stamp)[0]
a.attrib['href'] = footnote.get_absolute_url()
transcript.save()
def get_breadcrumb(self):
breadcrumbs = (
(self.document.project.name, self.document.project.get_absolute_url()),
('Documents', reverse('all_documents_view',
kwargs={'project_slug': self.project.slug})),
(self.document.as_text(), self.document.get_absolute_url()),
('Edit transcript', None)
)
return breadcrumbs
2 changes: 1 addition & 1 deletion editorsnotes/api/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from documents import DocumentSerializer, ScanSerializer
from documents import DocumentSerializer, ScanSerializer, TranscriptSerializer
from topics import TopicSerializer
from notes import NoteSerializer
21 changes: 18 additions & 3 deletions editorsnotes/api/serializers/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

from lxml import etree
from rest_framework import serializers
from rest_framework.reverse import reverse

from editorsnotes.main.models import Document, Citation, Scan
from editorsnotes.main.models import Document, Citation, Scan, Transcript

from .base import (RelatedTopicSerializerMixin, ProjectSpecificItemMixin,
URLField, ProjectSlugField, HyperlinkedProjectItemField)
Expand Down Expand Up @@ -37,9 +38,10 @@ class Meta:

class DocumentSerializer(RelatedTopicSerializerMixin, ProjectSpecificItemMixin,
serializers.ModelSerializer):
url = URLField()
project = ProjectSlugField()
transcript = serializers.SerializerMethodField('get_transcript_url')
zotero_data = ZoteroField(required=False)
url = URLField()
scans = ScanSerializer(many=True, required=False, read_only=True)
def get_validation_exclusions(self):
# TODO: This can be removed in future versions of django rest framework.
Expand All @@ -49,10 +51,23 @@ def get_validation_exclusions(self):
exclusions = super(DocumentSerializer, self).get_validation_exclusions()
exclusions.remove('zotero_data')
return exclusions
def get_transcript_url(self, obj):
if not obj.has_transcript():
return None
return reverse('api:api-transcripts-detail',
args=(obj.project.slug, obj.id),
request=self.context.get('request', None))
class Meta:
model = Document
fields = ('id', 'description', 'url', 'project', 'last_updated',
'scans', 'related_topics', 'zotero_data',)
'scans', 'transcript', 'related_topics', 'zotero_data',)

class TranscriptSerializer(serializers.ModelSerializer):
url = URLField(lookup_arg_attrs=('document.project.slug', 'document.id'))
document = HyperlinkedProjectItemField(
required=True, view_name='api:api-documents-detail')
class Meta:
model = Transcript

class CitationSerializer(serializers.ModelSerializer):
url = URLField('api:api-topic-citations-detail',
Expand Down
2 changes: 2 additions & 0 deletions editorsnotes/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
url(r'^documents/(?P<document_id>\d+)/scans/$', views.ScanList.as_view(), name='api-scans-list'),
url(r'^documents/(?P<document_id>\d+)/scans/(?P<scan_id>\d+)/$', views.ScanDetail.as_view(), name='api-scans-detail'),
url(r'^documents/(?P<document_id>\d+)/scans/normalize_order/$', views.NormalizeScanOrder.as_view(), name='api-scans-normalize-order'),

url(r'^documents/(?P<document_id>\d+)/transcript/$', views.Transcript.as_view(), name='api-transcripts-detail'),
)

urlpatterns = patterns('',
Expand Down
19 changes: 16 additions & 3 deletions editorsnotes/api/views/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from editorsnotes.main.models import Document, Scan
from editorsnotes.main.models import Document, Scan, Transcript

from .base import (BaseListAPIView, BaseDetailView, DeleteConfirmAPIView,
ElasticSearchListMixin, ProjectSpecificMixin)
from ..permissions import ProjectSpecificPermissions
from ..serializers import DocumentSerializer, ScanSerializer
from ..serializers import (DocumentSerializer, ScanSerializer,
TranscriptSerializer)

__all__ = ['DocumentList', 'DocumentDetail', 'DocumentConfirmDelete',
'ScanList', 'ScanDetail', 'NormalizeScanOrder']
'ScanList', 'ScanDetail', 'NormalizeScanOrder', 'Transcript']

class DocumentList(ElasticSearchListMixin, BaseListAPIView):
model = Document
Expand Down Expand Up @@ -90,3 +91,15 @@ def get_queryset(self):
document_qs = Document.objects.prefetch_related('scans__creator')
document = get_object_or_404(document_qs, id=document_id)
return document.scans.filter(id=scan_id)

class Transcript(BaseDetailView):
model = Transcript
serializer_class = TranscriptSerializer
def get_object(self, queryset=None):
transcript_qs = self.model.objects\
.select_related('document__project')\
.filter(
document__id=self.kwargs.get('document_id'),
document__project__slug=self.kwargs.get('project_slug')
)
return get_object_or_404(transcript_qs)
9 changes: 9 additions & 0 deletions editorsnotes_app/js/templates/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ <h3>Related topics</h3>
</div>

<div class="edit-section" id="document-scans"></div>

<% if (!doc.isNew()) { %>
<div class="edit-section">
<h3>Transcript</h3>
<% var transcript_url = doc.get('url').replace('/api/', '/') + 'transcript/edit/'; %>
<% var transcript_action = doc.get('transcript') ? 'Edit' : 'Add'; %>
<a target="_blank" class="btn" href="<%= transcript_url %>"><%= transcript_action %> transcript</a>
</div>
<% } %>
2 changes: 1 addition & 1 deletion editorsnotes_app/js/templates/zotero_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h5><%= i18n.translate(val).fetch() %></h5>
<input type="hidden" value="<%= val %>" />
</div>
<% } else if (key === 'tags') { %>
<% } else if (key === 'tags' || key === 'attachments' || key === 'notes') { %>
<% _(val).forEach(function (tag) { %>
<div class="zotero-entry" data-zotero-key="<%= key %>[]">
<input type="hidden" value="<%= tag.value %>" />
Expand Down

0 comments on commit 0c4751b

Please sign in to comment.