summaryrefslogtreecommitdiffstats
path: root/themis
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2011-10-30 16:19:33 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2011-10-30 16:19:33 (GMT)
commit768f8c366e7f75d0aa8a102ef7f0d0ea4c6e6495 (patch)
treeec3910986e9f0b408fc4b3cb9aacfb4ccb95e779 /themis
parent05e5a94d7b694023277780aab6d77449e5b86882 (diff)
downloadthemis.config-768f8c366e7f75d0aa8a102ef7f0d0ea4c6e6495.zip
themis.config-768f8c366e7f75d0aa8a102ef7f0d0ea4c6e6495.tar.gz
themis.config-768f8c366e7f75d0aa8a102ef7f0d0ea4c6e6495.tar.bz2
add ocr settings
Diffstat (limited to 'themis')
-rw-r--r--themis/config/controlpanel.pt67
-rw-r--r--themis/config/controlpanel.py6
-rw-r--r--themis/config/interfaces.py4
-rw-r--r--themis/config/utils.py19
4 files changed, 95 insertions, 1 deletions
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 @@
</dd>
+
+ <dt id="fieldsetlegend-ocr">OCR Settings</dt>
+ <dd id="fieldset-ocr">
+
+ <form
+ name="ocr"
+ method="post"
+ class="enableUnloadProtection"
+ tal:attributes="action request/URL"
+ tal:define="errors view/errors">
+
+ <div
+ tal:define="error errors/incoming_mails_path | nothing;
+ incoming_mails_path python:request.get('incoming_mails_path', view.settings.incoming_mails_path)"
+ tal:attributes="class python:'field error' if error else 'field'">
+
+ <label for="incoming_mails_path" i18n:translate="label_incoming_mails_path">Incoming Mails Path</label>
+ <div tal:content="error" tal:condition="error" />
+ <input
+ name="incoming_mails_path"
+ id="incoming_mails_path"
+ type="text"
+ size="80"
+ tal:attributes="value incoming_mails_path"
+ />
+ </div>
+
+ <div
+ tal:define="error errors/ocr_code_mapping | nothing;
+ ocr_code_mapping python:request.get('ocr_code_mapping', view.settings.ocr_code_mapping)"
+ tal:attributes="class python:'field error' if error else 'field'">
+
+ <label for="ocr_code_mapping" i18n:translate="label_ocr_code_mapping">OCR Code Mapping</label>
+ <div tal:content="error" tal:condition="error" />
+ <textarea
+ name="ocr_code_mapping"
+ id="ocr_code_mapping"
+ type="text"
+ rows="20"
+ cols="80"
+ tal:content="ocr_code_mapping"
+ >...</textarea>
+ </div>
+
+ <div class="formControls">
+ <input
+ type="submit"
+ name="form.button.OcrSave"
+ class="context"
+ value="Save"
+ i18n:attributes="value" />
+
+ <input
+ type="submit"
+ name="form.button.Cancel"
+ class="context"
+ value="Cancel"
+ i18n:attributes="value" />
+ </div>
+
+ <input tal:replace="structure context/@@authenticator/authenticator" />
+
+ </form>
+
+ </dd>
+
+
</dl>
</div>
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