From 768f8c366e7f75d0aa8a102ef7f0d0ea4c6e6495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 30 Oct 2011 17:19:33 +0100 Subject: [PATCH] add ocr settings --- themis/config/controlpanel.pt | 67 +++++++++++++++++++++++++++++++++++ themis/config/controlpanel.py | 6 ++++ themis/config/interfaces.py | 4 +++ themis/config/utils.py | 19 +++++++++- 4 files changed, 95 insertions(+), 1 deletion(-) diff --git a/themis/config/controlpanel.pt b/themis/config/controlpanel.pt index 5007d16..6621e9b 100644 --- a/themis/config/controlpanel.pt +++ b/themis/config/controlpanel.pt @@ -90,6 +90,73 @@ + +
OCR Settings
+
+ +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ + + +
+ + + + + +
+ + diff --git a/themis/config/controlpanel.py b/themis/config/controlpanel.py index 8730124..726f1e2 100644 --- a/themis/config/controlpanel.py +++ b/themis/config/controlpanel.py @@ -45,6 +45,12 @@ class ThemisControlpanel(BrowserView): self.settings.mail_category_mapping = form.get('mail_category_mapping') self.settings.documents_path = form.get('documents_path') + if 'form.button.OcrSave' in form: + self.authorize() + submitted = True + self.settings.ocr_code_mapping = form.get('ocr_code_mapping') + self.settings.incoming_mails_path = form.get('incoming_mails_path') + if submitted and not self.errors: self._setup() IStatusMessage(self.request).add(_(u"Changes saved")) diff --git a/themis/config/interfaces.py b/themis/config/interfaces.py index aaf90ce..a44cfe1 100644 --- a/themis/config/interfaces.py +++ b/themis/config/interfaces.py @@ -11,3 +11,7 @@ class IThemisSettings(Interface): title=_(u'Mail Category Mapping'), required=False) documents_path = schema.TextLine(title=_(u'Documents Path'), required=False) + + incoming_mails_path = schema.TextLine(title=_(u'Documents Path'), required=False) + + ocr_code_mapping = schema.Text(title=_(u'OCR Code Mapping'), required=False) diff --git a/themis/config/utils.py b/themis/config/utils.py index ba71a7d..643eb28 100644 --- a/themis/config/utils.py +++ b/themis/config/utils.py @@ -15,7 +15,7 @@ def get_document_type_for_mail(mail): continue if line.startswith('#'): continue - category, object_type = line.strip().split(':') + category, object_type = line.strip().split('|') if category in values: return object_type return None @@ -23,3 +23,20 @@ def get_document_type_for_mail(mail): def get_document_location_for_mail(mail): settings = component.getUtility(IRegistry).forInterface(IThemisSettings, False) return settings.documents_path + +def get_incoming_mails_location(): + settings = component.getUtility(IRegistry).forInterface(IThemisSettings, False) + return settings.incoming_mails_path + +def get_mail_categories_from_ocr_code(ocr_code): + settings = component.getUtility(IRegistry).forInterface(IThemisSettings, False) + mapping = settings.ocr_code_mapping + for line in mapping.splitlines(): + if not line: + continue + if line.startswith('#'): + continue + code, category, subcategory = line.strip().split('|') + if code == ocr_code: + return category, subcategory + return None