Source

orgtool / orgtool / ext / papers / schema.py

Full commit
# -*- coding: utf-8 -*-
from tool import app
from doqu import Document, Many
from doqu.ext.fields import *

from orgtool.ext.tracking.schema import TrackedDocument

from .helpers import get_image_base_path


class UploadedDocumentPart(TrackedDocument):
    "Scanned paper (single page)"
    summary = Field(unicode, required=True)
    details = Field(unicode)
    image = ImageField(get_image_base_path, required=True)
    #attachment = FileField(get_image_base_path, required=True)
    language = Field(unicode)  # "en", "cze", etc. — mainly for OCR (CuneiForm)
    source = Field(unicode)
    source_fingerprint = Field(str)  # ETL: not necessarily current file

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

    def get_image_url(self):
        ext = app.get_feature('papers')
        return u'{0}{1}'.format(ext.env['image_base_url'], self.image.path)


class UploadedDocument(TrackedDocument):
    "Scanned document (multiple pages)"
    summary = Field(unicode, required=True)
    details = Field(unicode)
    pages = Many(UploadedDocumentPart)
    # TODO:
    #author = ...
    #owner = ...
    #location = ...
    #date = ...