Small code cleanups

Add keyword arguments.

Replace get_queryset with get_object_list.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-02-05 05:49:47 -04:00
parent 71c2a7773e
commit a4ef6b3e8a
6 changed files with 23 additions and 34 deletions

View File

@@ -28,4 +28,4 @@ def get_form_media_js(form):
@register.simple_tag
def get_icon(icon_path):
return import_string(icon_path).render()
return import_string(dotted_path=icon_path).render()

View File

@@ -34,7 +34,7 @@ class CommentEventsTestCase(CommentsTestMixin, GenericDocumentViewTestCase):
self.assertEqual(event.verb, event_document_comment_created.id)
self.assertEqual(event.action_object, self.document)
self.assertEqual(event.target, self.test_comment)
self.assertEqual(event.actor, self.user)
self.assertEqual(event.actor, self._test_case_user)
def test_comment_deleted_event_no_permissions(self):
self._create_comment()
@@ -58,4 +58,4 @@ class CommentEventsTestCase(CommentsTestMixin, GenericDocumentViewTestCase):
self.assertEqual(event.verb, event_document_comment_deleted.id)
self.assertEqual(event.target, self.document)
self.assertEqual(event.actor, self.user)
self.assertEqual(event.actor, self._test_case_user)

View File

@@ -26,18 +26,15 @@ class DocumentCommentCreateView(ExternalObjectMixin, SingleObjectCreateView):
fields = ('comment',)
model = Comment
def get_document(self):
return self.get_external_object()
def get_extra_context(self):
return {
'object': self.get_document(),
'title': _('Add comment to document: %s') % self.get_document(),
'object': self.external_object,
'title': _('Add comment to document: %s') % self.external_object,
}
def get_instance_extra_data(self):
return {
'document': self.get_document(), 'user': self.request.user,
'document': self.external_object, 'user': self.request.user,
}
def get_post_action_redirect(self):
@@ -63,14 +60,14 @@ class DocumentCommentDeleteView(SingleObjectDeleteView):
def get_extra_context(self):
return {
'object': self.get_object().document,
'title': _('Delete comment: %s?') % self.get_object(),
'object': self.object.document,
'title': _('Delete comment: %s?') % self.object,
}
def get_post_action_redirect(self):
return reverse(
viewname='comments:comments_for_document', kwargs={
'document_id': self.get_object().document.pk
'document_id': self.object.document.pk
}
)
@@ -80,25 +77,22 @@ class DocumentCommentListView(ExternalObjectMixin, SingleObjectListView):
external_object_permission = permission_comment_view
external_object_pk_url_kwarg = 'document_id'
def get_document(self):
return self.get_external_object()
def get_extra_context(self):
return {
'hide_link': True,
'hide_object': True,
'no_results_icon': icon_comments_for_document,
'no_results_external_link': link_comment_add.resolve(
RequestContext(self.request, {'object': self.get_document()})
RequestContext(self.request, {'object': self.external_object})
),
'no_results_text': _(
'Document comments are timestamped text entries from users. '
'They are great for collaboration.'
),
'no_results_title': _('There are no comments'),
'object': self.get_document(),
'title': _('Comments for document: %s') % self.get_document(),
'object': self.external_object,
'title': _('Comments for document: %s') % self.external_object,
}
def get_source_queryset(self):
return self.get_document().comments.all()
return self.external_object.comments.all()

View File

@@ -104,7 +104,7 @@ class DocumentPageNavigationBase(ExternalObjectMixin, RedirectView):
try:
previous_url = self.get_object().get_absolute_url()
except AttributeError:
previous_url = reverse(setting_home_view.value)
previous_url = reverse(viewname=setting_home_view.value)
parsed_url = furl(url=previous_url)

View File

@@ -387,13 +387,13 @@ class DocumentUpdatePageCountView(MultipleObjectConfirmActionView):
)
def get_extra_context(self):
queryset = self.get_queryset()
queryset = self.get_object_list()
result = {
'title': ungettext(
'Recalculate the page count of the selected document?',
'Recalculate the page count of the selected documents?',
queryset.count()
singular='Recalculate the page count of the selected document?',
plural='Recalculate the page count of the selected documents?',
number=queryset.count()
)
}
@@ -439,13 +439,13 @@ class DocumentTransformationsClearView(MultipleObjectConfirmActionView):
)
def get_extra_context(self):
queryset = self.get_queryset()
queryset = self.get_object_list()
result = {
'title': ungettext(
'Clear all the page transformations for the selected document?',
'Clear all the page transformations for the selected document?',
queryset.count()
singular='Clear all the page transformations for the selected document?',
plural='Clear all the page transformations for the selected document?',
number=queryset.count()
)
}
@@ -668,7 +668,7 @@ class FavoriteAddView(MultipleObjectConfirmActionView):
)
def get_extra_context(self):
queryset = self.get_queryset()
queryset = self.get_object_list()
return {
'submit_label': _('Add'),

View File

@@ -225,12 +225,8 @@ class TagListView(SingleObjectListView):
}
def get_source_queryset(self):
#return self.get_tag_queryset()
return Tag.objects.all()
#def get_tag_queryset(self):
# return Tag.objects.all()
class TagDocumentListView(ExternalObjectMixin, DocumentListView):
external_object_class = Tag
@@ -279,7 +275,6 @@ class DocumentTagListView(ExternalObjectMixin, TagListView):
)
return context
#def get_tag_queryset(self):
def get_source_queryset(self):
return self.get_external_object().get_tags(
permission=permission_tag_view, user=self.request.user