Hide the document type field if document type is specified in the form's initial values
This commit is contained in:
@@ -27,7 +27,11 @@
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% else %}
|
||||
{% for field in form %}
|
||||
{% for field in form.hidden_fields %}
|
||||
{{ field }}
|
||||
{% endfor %}
|
||||
|
||||
{% for field in form.visible_fields %}
|
||||
<div class="group">
|
||||
{% if field.errors %}<div class="fieldWithErrors">{% endif %}
|
||||
<label class="label">{{ field.label_tag }}{% if field.field.required and not read_only %} ({% trans 'required' %}){% endif %}</label>
|
||||
|
||||
@@ -13,7 +13,14 @@ from models import Document, DocumentType, DocumentTypeMetadataType
|
||||
|
||||
from documents.conf.settings import AVAILABLE_FUNCTIONS
|
||||
|
||||
|
||||
class DocumentForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DocumentForm, self).__init__(*args, **kwargs)
|
||||
if 'initial' in kwargs:
|
||||
if 'document_type' in kwargs['initial']:
|
||||
self.fields['document_type'].widget = forms.HiddenInput()
|
||||
|
||||
class Meta:
|
||||
model = Document
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ def upload_document_with_type(request, document_type_id, multiple=True):
|
||||
def document_view(request, document_id):
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
form = DocumentForm_view(instance=document, extra_fields=[
|
||||
{'label':_(u'Document type'), 'field':'document_type'},
|
||||
{'label':_(u'Filename'), 'field':'file_filename'},
|
||||
{'label':_(u'File extension'), 'field':'file_extension'},
|
||||
{'label':_(u'File mimetype'), 'field':'file_mimetype'},
|
||||
|
||||
Reference in New Issue
Block a user