handle word docToTxt
This commit is contained in:
parent
778d698a41
commit
ecd40e9b86
|
@ -1,5 +1,9 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
import datetime
|
import datetime
|
||||||
|
from django.db.models.signals import post_save
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import codecs
|
||||||
|
|
||||||
class Issue(models.Model):
|
class Issue(models.Model):
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
|
@ -11,7 +15,7 @@ class Issue(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
author = models.ForeignKey("Contributor", blank=True, null=True)
|
authors = models.ManyToManyField("Contributor", blank=True, null=True)
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
notes = models.TextField(blank=True)
|
notes = models.TextField(blank=True)
|
||||||
issue = models.ForeignKey(Issue)
|
issue = models.ForeignKey(Issue)
|
||||||
|
@ -34,18 +38,49 @@ class Document(models.Model):
|
||||||
contributor = models.ForeignKey(Contributor)
|
contributor = models.ForeignKey(Contributor)
|
||||||
doc_txt = models.TextField(blank=True)
|
doc_txt = models.TextField(blank=True)
|
||||||
date_added = models.DateTimeField(default=datetime.datetime.now())
|
date_added = models.DateTimeField(default=datetime.datetime.now())
|
||||||
|
|
||||||
|
def txtPath(self):
|
||||||
|
path = self.file.path
|
||||||
|
return path + ".txt"
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
class Image(models.Model):
|
class Image(models.Model):
|
||||||
file = models.FileField(upload_to='erang/images/')
|
file = models.FileField(upload_to='erang/images/')
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
|
contributor = models.ForeignKey(Contributor)
|
||||||
issue = models.ForeignKey(Issue)
|
issue = models.ForeignKey(Issue)
|
||||||
notes = models.TextField(blank=True)
|
notes = models.TextField(blank=True)
|
||||||
date_added = models.DateTimeField(default=datetime.datetime.now())
|
date_added = models.DateTimeField(default=datetime.datetime.now())
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
'''
|
||||||
|
def docToTxt(**kwargs):
|
||||||
|
obj = kwargs['instance']
|
||||||
|
f = open("/tmp/tmpDocToTxt.txt", "w")
|
||||||
|
s = subprocess.Popen(["antiword", "-f", "-m", "UTF-8", obj.file.path], stdout = f)
|
||||||
|
f.close()
|
||||||
|
f2 = open("/tmp/tmpDocToTxt.txt")
|
||||||
|
txt = f2.read()
|
||||||
|
f2.close()
|
||||||
|
obj.doc_txt = txt
|
||||||
|
obj.save()
|
||||||
|
return
|
||||||
|
'''
|
||||||
|
def docToTxt(**kwargs):
|
||||||
|
obj = kwargs['instance']
|
||||||
|
docFilePath = obj.file.path
|
||||||
|
txtPath = obj.txtPath()
|
||||||
|
if not os.path.isfile(txtPath):
|
||||||
|
os.system("antiword -f -m 'UTF-8' '%s' > %s" % (docFilePath, txtPath,))
|
||||||
|
f = codecs.open("/tmp/tmpDocToTxt.txt", encoding='utf-8')
|
||||||
|
txt = f.read()
|
||||||
|
f.close()
|
||||||
|
obj.doc_txt = txt
|
||||||
|
obj.save()
|
||||||
|
return
|
||||||
|
return
|
||||||
|
|
||||||
|
post_save.connect(docToTxt, sender=Document)
|
||||||
|
|
|
@ -43,6 +43,7 @@ urlpatterns = patterns('',
|
||||||
(r'emailsignuplist', 'festival.views.email_signups'),
|
(r'emailsignuplist', 'festival.views.email_signups'),
|
||||||
(r'^favicon.ico$', 'django.views.generic.simple.redirect_to', {'url': '/static/images/favicon.ico'}),
|
(r'^favicon.ico$', 'django.views.generic.simple.redirect_to', {'url': '/static/images/favicon.ico'}),
|
||||||
|
|
||||||
|
(r'^ajax_filtered_fields/', include('ajax_filtered_fields.urls')),
|
||||||
# Uncomment the next line to enable the admin:
|
# Uncomment the next line to enable the admin:
|
||||||
(r'^$', 'festival.views.home')
|
(r'^$', 'festival.views.home')
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
-e svn+http://django-multilingual.googlecode.com/svn/trunk/#egg=multilingual
|
-e svn+http://django-multilingual.googlecode.com/svn/trunk/#egg=multilingual
|
||||||
-e bzr+http://firefogg.org/dev/python-firefogg/#egg=python-firefogg
|
-e bzr+http://firefogg.org/dev/python-firefogg/#egg=python-firefogg
|
||||||
-e bzr+http://firefogg.org/dev/django_firefogg/#egg=django_firefogg
|
-e bzr+http://firefogg.org/dev/django_firefogg/#egg=django_firefogg
|
||||||
|
-e hg+https://django-ajax-filtered-fields.googlecode.com/hg/#egg=django-ajax-filtered-fields
|
||||||
sorl-thumbnail
|
sorl-thumbnail
|
||||||
django-extensions
|
django-extensions
|
||||||
django-debug-toolbar
|
django-debug-toolbar
|
||||||
|
|
Loading…
Reference in New Issue
Block a user