Added document detail view
This commit is contained in:
@@ -56,6 +56,11 @@ class DetailSelectMultiple(forms.widgets.SelectMultiple):
|
|||||||
return mark_safe(output + u'</ul>\n')
|
return mark_safe(output + u'</ul>\n')
|
||||||
|
|
||||||
|
|
||||||
|
class PlainWidget(forms.widgets.Widget):
|
||||||
|
def render(self, name, value, attrs=None):
|
||||||
|
return mark_safe(u'%s' % value)
|
||||||
|
|
||||||
|
|
||||||
class DetailForm(forms.ModelForm):
|
class DetailForm(forms.ModelForm):
|
||||||
def __init__(self, extra_fields=None, *args, **kwargs):
|
def __init__(self, extra_fields=None, *args, **kwargs):
|
||||||
super(DetailForm, self).__init__(*args, **kwargs)
|
super(DetailForm, self).__init__(*args, **kwargs)
|
||||||
@@ -66,6 +71,11 @@ class DetailForm(forms.ModelForm):
|
|||||||
#TODO: Add others result types <=> Field types
|
#TODO: Add others result types <=> Field types
|
||||||
if isinstance(result, models.query.QuerySet):
|
if isinstance(result, models.query.QuerySet):
|
||||||
self.fields[extra_field['field']]=forms.ModelMultipleChoiceField(queryset=result, label=label)
|
self.fields[extra_field['field']]=forms.ModelMultipleChoiceField(queryset=result, label=label)
|
||||||
|
else:
|
||||||
|
self.fields[extra_field['field']]=forms.CharField(
|
||||||
|
label=extra_field['label'],
|
||||||
|
initial=getattr(self.instance, extra_field['field'], None),
|
||||||
|
widget=PlainWidget)
|
||||||
|
|
||||||
for field_name, field in self.fields.items():
|
for field_name, field in self.fields.items():
|
||||||
if isinstance(field.widget, forms.widgets.SelectMultiple):
|
if isinstance(field.widget, forms.widgets.SelectMultiple):
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load styling %}
|
|
||||||
{% load generic_views_helpers %}
|
|
||||||
{% block title %} :: {% with "true" as read_only %}{% with "true" as striptags %}{% include "calculate_form_title.html" %}{% endwith %}{% endwith %}{% endblock %}
|
{% block title %} :: {% with "true" as read_only %}{% with "true" as striptags %}{% include "calculate_form_title.html" %}{% endwith %}{% endwith %}{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
{% block javascript %}
|
||||||
@@ -49,6 +48,7 @@
|
|||||||
{% with subtemplate.extra_columns as extra_columns %}
|
{% with subtemplate.extra_columns as extra_columns %}
|
||||||
{% with subtemplate.hide_object as hide_object %}
|
{% with subtemplate.hide_object as hide_object %}
|
||||||
{% with subtemplate.main_object as main_object %}
|
{% with subtemplate.main_object as main_object %}
|
||||||
|
{% with subtemplate.hide_link as hide_link %}
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{% include subtemplate.name %}
|
{% include subtemplate.name %}
|
||||||
</div>
|
</div>
|
||||||
@@ -57,6 +57,7 @@
|
|||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
{% endwith %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from django.core.urlresolvers import reverse
|
|||||||
|
|
||||||
from common.wizard import BoundFormWizard
|
from common.wizard import BoundFormWizard
|
||||||
from common.utils import urlquote
|
from common.utils import urlquote
|
||||||
|
from common.forms import DetailForm
|
||||||
|
|
||||||
from models import Document, DocumentType, DocumentTypeMetadataType
|
from models import Document, DocumentType, DocumentTypeMetadataType
|
||||||
|
|
||||||
@@ -15,7 +16,12 @@ from documents.conf.settings import AVAILABLE_FUNCTIONS
|
|||||||
class DocumentForm(forms.ModelForm):
|
class DocumentForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Document
|
model = Document
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentForm_view(DetailForm):
|
||||||
|
class Meta:
|
||||||
|
model = Document
|
||||||
|
exclude = ('file',)
|
||||||
|
|
||||||
class DocumentTypeSelectForm(forms.Form):
|
class DocumentTypeSelectForm(forms.Form):
|
||||||
document_type = forms.ModelChoiceField(queryset=DocumentType.objects.all())
|
document_type = forms.ModelChoiceField(queryset=DocumentType.objects.all())
|
||||||
@@ -23,14 +29,14 @@ class DocumentTypeSelectForm(forms.Form):
|
|||||||
|
|
||||||
class MetadataForm(forms.Form):
|
class MetadataForm(forms.Form):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(MetadataForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
#Set form fields initial values
|
||||||
if 'initial' in kwargs:
|
if 'initial' in kwargs:
|
||||||
self.metadata_type = kwargs['initial'].pop('metadata_type', None)
|
self.metadata_type = kwargs['initial'].pop('metadata_type', None)
|
||||||
super(MetadataForm, self).__init__(*args, **kwargs)
|
self.document_type = kwargs['initial'].pop('document_type', None)
|
||||||
self.fields['id'] = forms.CharField(label=_(u'id'), widget=forms.HiddenInput)
|
self.metadata_options = kwargs['initial'].pop('metadata_options', None)
|
||||||
self.fields['name'] = forms.CharField(label=_(u'Name'),
|
|
||||||
required=False, widget=forms.TextInput(attrs={'readonly':'readonly'}))
|
|
||||||
self.fields['value'] = forms.CharField(label=_(u'Value'))
|
|
||||||
if hasattr(self, 'metadata_type'):
|
|
||||||
self.fields['name'].initial=self.metadata_type.name
|
self.fields['name'].initial=self.metadata_type.name
|
||||||
self.fields['id'].initial=self.metadata_type.id
|
self.fields['id'].initial=self.metadata_type.id
|
||||||
if self.metadata_type.default:
|
if self.metadata_type.default:
|
||||||
@@ -38,7 +44,11 @@ class MetadataForm(forms.Form):
|
|||||||
self.fields['value'].initial = eval(self.metadata_type.default, AVAILABLE_FUNCTIONS)
|
self.fields['value'].initial = eval(self.metadata_type.default, AVAILABLE_FUNCTIONS)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
self.fields['value'].initial = err
|
self.fields['value'].initial = err
|
||||||
|
|
||||||
|
id = forms.CharField(label=_(u'id'), widget=forms.HiddenInput)
|
||||||
|
name = forms.CharField(label=_(u'Name'),
|
||||||
|
required=False, widget=forms.TextInput(attrs={'readonly':'readonly'}))
|
||||||
|
value = forms.CharField(label=_(u'Value'))
|
||||||
|
|
||||||
|
|
||||||
class DocumentCreateWizard(BoundFormWizard):
|
class DocumentCreateWizard(BoundFormWizard):
|
||||||
@@ -60,6 +70,8 @@ class DocumentCreateWizard(BoundFormWizard):
|
|||||||
for item in DocumentTypeMetadataType.objects.filter(document_type=self.document_type):
|
for item in DocumentTypeMetadataType.objects.filter(document_type=self.document_type):
|
||||||
initial.append({
|
initial.append({
|
||||||
'metadata_type':item.metadata_type,
|
'metadata_type':item.metadata_type,
|
||||||
|
'document_type':self.document_type,
|
||||||
|
'metadata_options':item,
|
||||||
})
|
})
|
||||||
self.initial = {1:initial}
|
self.initial = {1:initial}
|
||||||
if step == 1:
|
if step == 1:
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class Document(models.Model):
|
|||||||
file_mimetype = models.CharField(max_length=50, default="", editable=False)
|
file_mimetype = models.CharField(max_length=50, default="", editable=False)
|
||||||
file_filename = models.CharField(max_length=64, default="", editable=False)
|
file_filename = models.CharField(max_length=64, default="", editable=False)
|
||||||
file_extension = models.CharField(max_length=10, default="", editable=False)
|
file_extension = models.CharField(max_length=10, default="", editable=False)
|
||||||
date_added = models.DateTimeField("added", auto_now_add=True)
|
date_added = models.DateTimeField("added", auto_now_add=True)
|
||||||
date_updated = models.DateTimeField("updated", auto_now=True)
|
date_updated = models.DateTimeField("updated", auto_now=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -47,6 +47,10 @@ class Document(models.Model):
|
|||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.uuid
|
return self.uuid
|
||||||
|
|
||||||
|
@models.permalink
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return ('document_view', [self.id])
|
||||||
|
|
||||||
|
|
||||||
available_functions_string = (_(u' Available functions: %s') % ','.join(['%s()' % name for name, function in AVAILABLE_FUNCTIONS.items()])) if AVAILABLE_FUNCTIONS else ''
|
available_functions_string = (_(u' Available functions: %s') % ','.join(['%s()' % name for name, function in AVAILABLE_FUNCTIONS.items()])) if AVAILABLE_FUNCTIONS else ''
|
||||||
|
|
||||||
@@ -64,20 +68,17 @@ class MetadataType(models.Model):
|
|||||||
verbose_name = _(u'metadata type')
|
verbose_name = _(u'metadata type')
|
||||||
verbose_name_plural = _(u'metadata types')
|
verbose_name_plural = _(u'metadata types')
|
||||||
|
|
||||||
# @models.permalink
|
|
||||||
# def get_absolute_url(self):
|
|
||||||
# return ('state_list', [])
|
|
||||||
|
|
||||||
|
|
||||||
class DocumentTypeMetadataType(models.Model):
|
class DocumentTypeMetadataType(models.Model):
|
||||||
document_type = models.ForeignKey(DocumentType, verbose_name=_(u'document type'))
|
document_type = models.ForeignKey(DocumentType, verbose_name=_(u'document type'))
|
||||||
metadata_type = models.ForeignKey(MetadataType, verbose_name=_(u'metadata type'))
|
metadata_type = models.ForeignKey(MetadataType, verbose_name=_(u'metadata type'))
|
||||||
|
#create_directory = nmode
|
||||||
#override default
|
#override default
|
||||||
#create index dir? -bool
|
#create index dir? -bool
|
||||||
#required? -bool
|
#required? -bool
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return '%s <-> %s' %(self.document_type, self.metadata_type)
|
return unicode(self.metadata_type)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _(u'document type metadata type connector')
|
verbose_name = _(u'document type metadata type connector')
|
||||||
@@ -90,7 +91,7 @@ class DocumentMetadata(models.Model):
|
|||||||
value = models.TextField(blank=True, null=True, verbose_name=_(u'metadata value'))
|
value = models.TextField(blank=True, null=True, verbose_name=_(u'metadata value'))
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return '%s <-> %s' %(self.document, self.metadata_type)
|
return unicode(self.metadata_type)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _(u'document metadata')
|
verbose_name = _(u'document metadata')
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ urlpatterns = patterns('documents.views',
|
|||||||
url(r'^document/create/$', 'document_create', (), 'document_create'),
|
url(r'^document/create/$', 'document_create', (), 'document_create'),
|
||||||
#url(r'^document/upload/$', 'upload_document', (), 'upload_document'),
|
#url(r'^document/upload/$', 'upload_document', (), 'upload_document'),
|
||||||
url(r'^document/type/(?P<document_type_id>\d+)/upload/$', 'upload_document_with_type', (), 'upload_document_with_type'),
|
url(r'^document/type/(?P<document_type_id>\d+)/upload/$', 'upload_document_with_type', (), 'upload_document_with_type'),
|
||||||
|
url(r'^document/(?P<document_id>\d+)/$', 'document_view', (), 'document_view'),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ from django.views.generic.create_update import create_object
|
|||||||
from django.forms.formsets import formset_factory
|
from django.forms.formsets import formset_factory
|
||||||
|
|
||||||
|
|
||||||
|
from forms import DocumentForm_view
|
||||||
|
|
||||||
from models import Document, DocumentMetadata, DocumentType, MetadataType
|
from models import Document, DocumentMetadata, DocumentType, MetadataType
|
||||||
from forms import DocumentTypeSelectForm, DocumentCreateWizard, \
|
from forms import DocumentTypeSelectForm, DocumentCreateWizard, \
|
||||||
MetadataForm, DocumentForm
|
MetadataForm, DocumentForm
|
||||||
@@ -52,11 +54,12 @@ def upload_document_with_type(request, document_type_id, multiple=True):
|
|||||||
value=value
|
value=value
|
||||||
)
|
)
|
||||||
document_metadata.save()
|
document_metadata.save()
|
||||||
messages.success(request, _(u'Document uploaded successfully.'))
|
|
||||||
if multiple:
|
messages.success(request, _(u'Document uploaded successfully.'))
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
if multiple:
|
||||||
else:
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
return HttpResponseRedirect(reverse('document_list'))
|
else:
|
||||||
|
return HttpResponseRedirect(reverse('document_list'))
|
||||||
else:
|
else:
|
||||||
form = DocumentForm(initial={'document_type':document_type})
|
form = DocumentForm(initial={'document_type':document_type})
|
||||||
|
|
||||||
@@ -65,4 +68,26 @@ def upload_document_with_type(request, document_type_id, multiple=True):
|
|||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
|
def document_view(request, document_id):
|
||||||
|
document = get_object_or_404(Document, pk=document_id)
|
||||||
|
form = DocumentForm_view(instance=document, extra_fields=[
|
||||||
|
{'label':_(u'Filename'), 'field':'file_filename'},
|
||||||
|
{'label':_(u'File extension'), 'field':'file_extension'},
|
||||||
|
{'label':_(u'File mimetype'), 'field':'file_mimetype'},
|
||||||
|
{'label':_(u'Date added'), 'field':'date_added'},
|
||||||
|
])
|
||||||
|
|
||||||
|
return render_to_response('generic_detail.html', {
|
||||||
|
'form':form,
|
||||||
|
'object':document,
|
||||||
|
'subtemplates_dict':[
|
||||||
|
{
|
||||||
|
'name':'generic_list_subtemplate.html',
|
||||||
|
'title':_(u'metadata'),
|
||||||
|
'object_list':document.documentmetadata_set.all(),
|
||||||
|
'extra_columns':[{'name':_(u'qty'), 'attribute':'value'}],
|
||||||
|
'hide_link':True,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user