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 @@