diff --git a/README.md b/README.md index b30e29e..15d9556 100755 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ To understand how the reanalyse project works, you'll need to read carefully: $ hg clone https://bitbucket.org/cogtree/python-solr $ sudo pyton python-solr/setup.py install +### python-magic (used to detect file mimetype) + + $ sudo easy_install python-magic + ### apache > django conf $ vi /apache/reanalyse.conf @@ -50,8 +54,8 @@ To understand how the reanalyse project works, you'll need to read carefully: * `./solrdataindex/` * `./upload/` + $ vi settingsprivate.py - $ mkdir logs upload download solrdataindex $ sudo chown -R www-data:www-data solr log upload download diff --git a/reanalyseapp/globalvars.py b/reanalyseapp/globalvars.py index 010b091..440ec2f 100755 --- a/reanalyseapp/globalvars.py +++ b/reanalyseapp/globalvars.py @@ -54,16 +54,17 @@ DOC_CAT_2['transcr'] = 'Transcription' -# C) meta_documents.csv : COLUMN *mimetype . -DOCUMENT_MIMETYPES = ['ese','tei'] # special files (ese is saved as json, tei is parsed) -DOCUMENT_MIMETYPES += ['link','ref'] # doc without local file (only title/text/description, or link, ...) -DOCUMENT_MIMETYPES += ['pdf','htm','csv'] # normaly displayed docs +# C) meta_documents.csv : COLUMN *mimetype . +# be careful ! "mimetype" doesn't mean real mimetype of the file, rather the category for the Texte model (to be renamed in Document) +DOCUMENT_MIMETYPES = ['ese','tei'] # special files (ese is saved as json, tei is parsed) +DOCUMENT_MIMETYPES += ['link','ref'] # doc without local file (only title/text/description, or link, ...) +DOCUMENT_MIMETYPES += ['img','pdf','htm','csv'] # normaly displayed docs # documents are parsed only if they are in A) & B) & C) # note that ese is also processed, but in a different way. see importexport.py -# types of document from the django models point of view (ie texte.doctype) -# NB: this Texte attribute is made using *mimetype.upper() +# when a Document is processed, the model is made using DOCUMENT_MIMETYPES.upper() +# ... types of document used by the django models point of view (ie texte.doctype) DOCUMENT_TYPE_CHOICES = ( ('TEI', 'XML TEI'), ('LINK', 'External link'), @@ -71,6 +72,7 @@ ('PDF', 'PDF'), ('HTM', 'HTML File'), ('CSV', 'CSV Table'), + ('IMG', 'Image'), #('TXT', 'Text File'), #('RTF', 'RTF'), # rather use htm for the moment, it's simpler #('ATL', 'XML Atlas.Ti'), # ...forget about it for the moment (data too much unstructured) diff --git a/reanalyseapp/imexport.py b/reanalyseapp/imexport.py index 23a8a9d..142745a 100755 --- a/reanalyseapp/imexport.py +++ b/reanalyseapp/imexport.py @@ -267,7 +267,7 @@ def importEnqueteUsingMeta(upPath,folderPath): if doc_mimetype=='tei': newDocument.status = '5' # 'waiting' status newDocument.save() - elif doc_mimetype=='pdf' or doc_mimetype=='csv': + elif doc_mimetype=='pdf' or doc_mimetype=='csv' or doc_mimetype=='img': newDocument.status = '0' newDocument.save() elif doc_mimetype=='htm': diff --git a/reanalyseapp/views.py b/reanalyseapp/views.py index 40d466a..f9d4245 100755 --- a/reanalyseapp/views.py +++ b/reanalyseapp/views.py @@ -24,6 +24,9 @@ import glob import os +# to detect file mimetype when serving files (gexf, pdf, img, ...) +import magic + # solr process import subprocess @@ -1274,7 +1277,9 @@ def edShow(request,eid,did): thevals.append([cssClass,row[k]]) values.append(thevals) ctx.update({'csvTable':{'columns':columns,'values':values}}) - ######################################### + + ######################################### PDF, IMG + # for pdf, img: nothing to do, everything is in the model (filelocation, name, etc...) updateCtxWithPerm(ctx,request,e) updateCtxWithSearchForm(ctx) @@ -1409,6 +1414,14 @@ def servePdf(request,did): fsock = open(d.locationpath,"rb").read() response = HttpResponse(fsock, mimetype="application/pdf") return response +# serve img +def serveImg(request,did): + d = Texte.objects.get(id=did) + mime = magic.Magic(mime=True) + filemime = mime.from_file(d.locationpath) + fsock = open(d.locationpath,"rb").read() + response = HttpResponse(fsock, mimetype=filemime) + return response ########################################################################### diff --git a/templates/bq_ed_show.html b/templates/bq_ed_show.html index 29f5782..873ef99 100755 --- a/templates/bq_ed_show.html +++ b/templates/bq_ed_show.html @@ -276,6 +276,10 @@

{{texte.name}}

{% endif %} +{% if texte.doctype == 'IMG' %} + +{% endif %} + {% if texte.doctype == 'HTM' %}
{% autoescape off %} diff --git a/templates/content/method_content_fr.html b/templates/content/method_content_fr.html index 816ac56..068b120 100755 --- a/templates/content/method_content_fr.html +++ b/templates/content/method_content_fr.html @@ -44,7 +44,7 @@

Description complète de la normalisation d'une enquête

doc, docx.txtpour les verbatims (fichiers intermédiaires). ces fichiers .txt doivent être ensuite convertis au format TEI .xml (voir plus bas)oui rtf.htmlimite la mise en page et le formattage à quelques éléments simples (titres, sous-titres, paragraphes) mais permet l'indexation (recherche dans le texte)oui ppt.pdfpas d'indexation du texte, mais conservation de la mise en pageoui - image.jpg...non + image.jpg .png .gifaffichage simpleoui audio.mp3...non Lorsque le choix de l'encodage est proposé, toujours préférer "UTF-8"
@@ -161,7 +161,7 @@

Description complète de la normalisation d'une enquête

*descr emplacement du fichier dans le dossier enquête, ou lien externe - /xml /htm /csv /pdf /link /ref + /xml /htm /csv /pdf /img /link /ref nom dans le site enquête /preparatory /analyse /verbatim /publication /ese apparaît en infobulle à coté de chaque document @@ -201,6 +201,12 @@

Description complète de la normalisation d'une enquête

Rapport d'enquête.doc export pdf + d234_data/ image.pngimg + Mon imageanalyse + Photo des chiens de chasse00/10/12 + image.raw + save as png + d034[NP]ref Publication journal TEIpublication Article publié p.34-35 du journal TEI15/10/12 diff --git a/urls.py b/urls.py index cbf88b3..8dbe830 100755 --- a/urls.py +++ b/urls.py @@ -19,8 +19,9 @@ (r'^stream/(?P\d+)/(?P\d+)$', 'reanalyseapp.views.stream'), (r'^getesereport/(?P\d+)', 'reanalyseapp.views.getEseReport'), # ESE report download (r'^graph/download/(?P\d+)', 'reanalyseapp.views.downloadGraph'), - (r'^graph/serve/(?P\d+).gexf', 'reanalyseapp.views.serveGraph'), # for gexf display (sigma?) - (r'^graph/serve/(?P\d+).pdf', 'reanalyseapp.views.servePdf'), # for simple pdf display + (r'^e/serve/gexf/(?P\d+).gexf', 'reanalyseapp.views.serveGraph'), # for gexf display (sigma?) + (r'^e/serve/pdf/(?P\d+).pdf', 'reanalyseapp.views.servePdf'), # for simple pdf display + (r'^e/serve/img/(?P\d+)', 'reanalyseapp.views.serveImg'), # for simple img display ###################################################################################################### ########## ENQUETES