Fix document add metadata view and form to work when there are no documents in the view.
ie: when the user has no permissions.
This commit is contained in:
@@ -117,12 +117,16 @@ class DocumentAddMetadataForm(forms.Form):
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
document_type = kwargs.pop('document_type')
|
||||
queryset = kwargs.pop(
|
||||
'queryset', MetadataType.objects.get_for_document_type(
|
||||
document_type=document_type
|
||||
document_type = kwargs.pop('document_type', None)
|
||||
|
||||
if document_type:
|
||||
queryset = kwargs.pop(
|
||||
'queryset', MetadataType.objects.get_for_document_type(
|
||||
document_type=document_type
|
||||
)
|
||||
)
|
||||
)
|
||||
else:
|
||||
queryset = MetadataType.objects.none()
|
||||
|
||||
super(DocumentAddMetadataForm, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from django.core.exceptions import ValidationError
|
||||
from django.core.urlresolvers import reverse, reverse_lazy
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.http import urlencode
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext
|
||||
|
||||
@@ -74,7 +75,10 @@ class DocumentMetadataAddView(MultipleObjectFormActionView):
|
||||
urlencode(
|
||||
{
|
||||
'id_list': ','.join(
|
||||
queryset.value_list('pk', flat=True)
|
||||
map(
|
||||
force_text,
|
||||
queryset.values_list('pk', flat=True)
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
@@ -110,9 +114,15 @@ class DocumentMetadataAddView(MultipleObjectFormActionView):
|
||||
|
||||
def get_form_extra_kwargs(self):
|
||||
queryset = self.get_queryset()
|
||||
result = {
|
||||
'document_type': queryset.first().document_type,
|
||||
}
|
||||
|
||||
result = {}
|
||||
|
||||
if queryset.count():
|
||||
result.update(
|
||||
{
|
||||
'document_type': queryset.first().document_type,
|
||||
}
|
||||
)
|
||||
|
||||
if queryset.count() == 1:
|
||||
result.update(
|
||||
|
||||
Reference in New Issue
Block a user