From ecd40e9b867ea2cd3ad7d127157d5ce6f9545cfd Mon Sep 17 00:00:00 2001 From: sanj Date: Sun, 14 Mar 2010 19:48:12 +0530 Subject: [PATCH] handle word docToTxt --- itf/erang/models.py | 41 ++++++++++++++++++++++++++++++++++++++--- itf/urls.py | 1 + requirements.txt | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/itf/erang/models.py b/itf/erang/models.py index 51bbcfc..e9f8172 100644 --- a/itf/erang/models.py +++ b/itf/erang/models.py @@ -1,5 +1,9 @@ from django.db import models import datetime +from django.db.models.signals import post_save +import subprocess +import os +import codecs class Issue(models.Model): name = models.CharField(max_length=255) @@ -11,7 +15,7 @@ class Issue(models.Model): return self.name 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) notes = models.TextField(blank=True) issue = models.ForeignKey(Issue) @@ -34,18 +38,49 @@ class Document(models.Model): contributor = models.ForeignKey(Contributor) doc_txt = models.TextField(blank=True) date_added = models.DateTimeField(default=datetime.datetime.now()) - + + def txtPath(self): + path = self.file.path + return path + ".txt" + def __unicode__(self): return self.title class Image(models.Model): file = models.FileField(upload_to='erang/images/') title = models.CharField(max_length=255) + contributor = models.ForeignKey(Contributor) issue = models.ForeignKey(Issue) notes = models.TextField(blank=True) date_added = models.DateTimeField(default=datetime.datetime.now()) def __unicode__(self): 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) diff --git a/itf/urls.py b/itf/urls.py index 1f4be26..a200fe3 100644 --- a/itf/urls.py +++ b/itf/urls.py @@ -43,6 +43,7 @@ urlpatterns = patterns('', (r'emailsignuplist', 'festival.views.email_signups'), (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: (r'^$', 'festival.views.home') ) diff --git a/requirements.txt b/requirements.txt index 9d3ebab..a36dd0e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ -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/django_firefogg/#egg=django_firefogg +-e hg+https://django-ajax-filtered-fields.googlecode.com/hg/#egg=django-ajax-filtered-fields sorl-thumbnail django-extensions django-debug-toolbar