Source

orgtool / orgtool / ext / papers / schema.py

Full commit
# -*- coding: utf-8 -*-

from doqu import Document, Many
from doqu.fields import *
from orgtool.ext.tracking.schema import TrackedDocument


def get_image_base_path():
    from tool import app
    ext = app.get_feature('papers')
    return ext.env['image_base_path']


class Page(TrackedDocument):
    summary = Field(unicode, required=True)
    details = Field(unicode)
    image = ImageField(get_image_base_path, required=True)
    language = Field(unicode)  # "en", "cze", etc. — mainly for OCR (CuneiForm)
    source_fingerprint = Field(str)  # ETL: not necessarily current file

    def __unicode__(self):
        return u'{summary}'.format(**self)

    def save(self, *args, **kwargs):
        #self['image'].save()
        #self['file_hash'] = self.get_file_hash()
        #self['details'] = image_to_text(path=self['image'].full_path,
        #                                language=self['language'])
        return super(Page, self).save(*args, **kwargs)

    def get_image_url(self):
        # FIXME
        return u'/media/scanned_papers/{0}'.format(self.image.path)


class Paper(TrackedDocument):
    summary = Field(unicode, required=True)
    details = Field(unicode)
    pages = Many(Page)