add ocr settings
This commit is contained in:
parent
05e5a94d7b
commit
768f8c366e
|
@ -90,6 +90,73 @@
|
||||||
|
|
||||||
</dd>
|
</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>
|
</dl>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -45,6 +45,12 @@ class ThemisControlpanel(BrowserView):
|
||||||
self.settings.mail_category_mapping = form.get('mail_category_mapping')
|
self.settings.mail_category_mapping = form.get('mail_category_mapping')
|
||||||
self.settings.documents_path = form.get('documents_path')
|
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:
|
if submitted and not self.errors:
|
||||||
self._setup()
|
self._setup()
|
||||||
IStatusMessage(self.request).add(_(u"Changes saved"))
|
IStatusMessage(self.request).add(_(u"Changes saved"))
|
||||||
|
|
|
@ -11,3 +11,7 @@ class IThemisSettings(Interface):
|
||||||
title=_(u'Mail Category Mapping'), required=False)
|
title=_(u'Mail Category Mapping'), required=False)
|
||||||
|
|
||||||
documents_path = schema.TextLine(title=_(u'Documents Path'), 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)
|
||||||
|
|
|
@ -15,7 +15,7 @@ def get_document_type_for_mail(mail):
|
||||||
continue
|
continue
|
||||||
if line.startswith('#'):
|
if line.startswith('#'):
|
||||||
continue
|
continue
|
||||||
category, object_type = line.strip().split(':')
|
category, object_type = line.strip().split('|')
|
||||||
if category in values:
|
if category in values:
|
||||||
return object_type
|
return object_type
|
||||||
return None
|
return None
|
||||||
|
@ -23,3 +23,20 @@ def get_document_type_for_mail(mail):
|
||||||
def get_document_location_for_mail(mail):
|
def get_document_location_for_mail(mail):
|
||||||
settings = component.getUtility(IRegistry).forInterface(IThemisSettings, False)
|
settings = component.getUtility(IRegistry).forInterface(IThemisSettings, False)
|
||||||
return settings.documents_path
|
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
|
||||||
|
|
Reference in New Issue