Hi,
Some time ago I had to validate ODT files sent to server via admin
site. Since I know how long it took me to solve that problem and I
haven't found any hints in google I decided to share with my solution.
Take have a look on my code:

import zipfile
try:
    from cStringIO import StringIO
except:
    from StringIO import StringIO

class ODTField(models.FileField):
    def __init__(self, verbose_name=None, name=None, upload_to='',
**kwargs):
        super(ODTField,self).__init__(verbose_name, name, upload_to, \
                   validator_list = [self.isODTFile])
    def isODTFile(self, field_data, all_data):
        try:
            tmp = StringIO(field_data["content"])
            zf = zipfile.ZipFile(tmp,"r")
            if zf.read("content.xml")< =0:
                raise ValidationError, _('Document must be \
                                                      in OpenDocument
format.')
        except:
            raise ValidationError, _('Document must be in OpenDocument
format.')


The most importatnt part of code is passing the argument
validator_list = [self.isODTFile] into argument list of __init__.

Btw. I started with my friend site about python and python related
stuff in polish. If you speek polish and have some time:D take have
look on it http://www.pydev.pl

Christopher Ciesielski aka kac.gigant


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to