handle word docToTxt

This commit is contained in:
sanj 2010-03-14 19:48:12 +05:30
parent 778d698a41
commit ecd40e9b86
3 changed files with 40 additions and 3 deletions

View File

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

View File

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

View File

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