Make document type available names list, available in document edit view

This commit is contained in:
Roberto Rosario
2011-02-06 23:20:16 -04:00
parent c0989f016f
commit 7da543f7d3
3 changed files with 23 additions and 14 deletions

View File

@@ -20,14 +20,15 @@ class DocumentForm(forms.ModelForm):
super(DocumentForm, self).__init__(*args, **kwargs) super(DocumentForm, self).__init__(*args, **kwargs)
if 'initial' in kwargs: if 'initial' in kwargs:
if 'document_type' in kwargs['initial']: if 'document_type' in kwargs['initial']:
if 'document_type' in self.fields:
#To allow merging with DocumentForm_edit
self.fields['document_type'].widget = forms.HiddenInput() self.fields['document_type'].widget = forms.HiddenInput()
filenames_qs = kwargs['initial']['document_type'].documenttypefilename_set.filter(enabled=True) filenames_qs = kwargs['initial']['document_type'].documenttypefilename_set.filter(enabled=True)
if filenames_qs.count() > 0: if filenames_qs.count() > 0:
self.fields['new_filename'] = forms.ModelChoiceField( self.fields['document_type_available_filenames'] = forms.ModelChoiceField(
queryset=filenames_qs, queryset=filenames_qs,
required=False, required=False,
label=_(u'Rename file')) label=_(u'Document type available filenames'))
class Meta: class Meta:
model = Document model = Document
@@ -39,11 +40,12 @@ class DocumentForm_view(DetailForm):
exclude = ('file',) exclude = ('file',)
class DocumentForm_edit(forms.ModelForm): class DocumentForm_edit(DocumentForm):
class Meta: class Meta:
model = Document model = Document
exclude = ('file','document_type') exclude = ('file', 'document_type')
new_filename = forms.CharField(label=_(u'New filename'), required=False)
new_filename = forms.CharField(label=_(u'New document filename'), required=False)
class DocumentTypeSelectForm(forms.Form): class DocumentTypeSelectForm(forms.Form):

View File

@@ -72,9 +72,9 @@ def upload_document_with_type(request, document_type_id, multiple=True):
form = DocumentForm(request.POST, request.FILES, initial={'document_type':document_type}) form = DocumentForm(request.POST, request.FILES, initial={'document_type':document_type})
if form.is_valid(): if form.is_valid():
instance = form.save() instance = form.save()
if 'new_filename' in form.cleaned_data: if 'document_type_available_filenames' in form.cleaned_data:
if form.cleaned_data['new_filename']: if form.cleaned_data['document_type_available_filenames']:
instance.file_filename = form.cleaned_data['new_filename'].filename instance.file_filename = form.cleaned_data['document_type_available_filenames'].filename
instance.save() instance.save()
_save_metadata(request.GET, instance) _save_metadata(request.GET, instance)
@@ -161,7 +161,7 @@ def document_delete(request, document_id):
def document_edit(request, document_id): def document_edit(request, document_id):
document = get_object_or_404(Document, pk=document_id) document = get_object_or_404(Document, pk=document_id)
if request.method == 'POST': if request.method == 'POST':
form = DocumentForm_edit(request.POST) form = DocumentForm_edit(request.POST, initial={'document_type':document.document_type})
if form.is_valid(): if form.is_valid():
try: try:
document.delete_fs_links() document.delete_fs_links()
@@ -170,6 +170,12 @@ def document_edit(request, document_id):
return HttpResponseRedirect(reverse('document_list')) return HttpResponseRedirect(reverse('document_list'))
document.file_filename = form.cleaned_data['new_filename'] document.file_filename = form.cleaned_data['new_filename']
print form.cleaned_data
if 'document_type_available_filenames' in form.cleaned_data:
if form.cleaned_data['document_type_available_filenames']:
document.file_filename = form.cleaned_data['document_type_available_filenames'].filename
document.save() document.save()
try: try:
@@ -181,7 +187,8 @@ def document_edit(request, document_id):
messages.success(request, _(u'Document edited and filesystem links updated.')) messages.success(request, _(u'Document edited and filesystem links updated.'))
return HttpResponseRedirect(reverse('document_list')) return HttpResponseRedirect(reverse('document_list'))
else: else:
form = DocumentForm_edit(instance=document, initial={'new_filename':document.file_filename}) form = DocumentForm_edit(instance=document, initial={
'new_filename':document.file_filename, 'document_type':document.document_type})
return render_to_response('generic_form.html', { return render_to_response('generic_form.html', {
'form':form, 'form':form,

View File

@@ -8,6 +8,7 @@
* Raise exception instead of returning error msg - DONE * Raise exception instead of returning error msg - DONE
* Option to delete source staging file after upload - DONE * Option to delete source staging file after upload - DONE
* Jquery upload document upload form with ajax widget - NOT NEEDED (commit: b0f31f2a8f82ff0daca081005f2fcae3f5573df5) * Jquery upload document upload form with ajax widget - NOT NEEDED (commit: b0f31f2a8f82ff0daca081005f2fcae3f5573df5)
* Rename dropbox from document edit view - DONE
* Document list filtering by metadata * Document list filtering by metadata
* Filterform date filtering widget * Filterform date filtering widget
* Validate GET data before saving file * Validate GET data before saving file
@@ -19,7 +20,6 @@
* Change to model signal * Change to model signal
* Allow document type to be changed in document edit view * Allow document type to be changed in document edit view
* Implement single sign on or LDAP for intranets * Implement single sign on or LDAP for intranets
* Rename dropbox from document edit view
* Ability to rename staging file during upload * Ability to rename staging file during upload
* Encrypting storage backend * Encrypting storage backend
* Indicate in generic list which document don't exist in storage backend * Indicate in generic list which document don't exist in storage backend