Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

New Advanced Configuration Options #42

Merged
merged 28 commits into from
May 10, 2018
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e1977b4
Rename a column in the Souper: 'path' --> 'remote_path'.
nihadness May 2, 2018
0822a51
Do not fail if local path is not set while inserting to Souper.
nihadness May 2, 2018
95bd992
Path Translator with prefix.
nihadness May 2, 2018
522d9d2
Use prefixes in object and parent creation.
nihadness May 2, 2018
ecb6c18
Use new local ID while creating parents.
nihadness May 3, 2018
e62d580
Separated 'Add' and 'Show' views of Remotes.
nihadness May 3, 2018
d182d3b
Introduction to Prefix Logic in import Step.
nihadness May 3, 2018
d26222d
Return string values while getting local paths.
nihadness May 3, 2018
d34b423
Do not touch ID while updating object data.
nihadness May 3, 2018
183ac97
Content Types to be created with prefix in the 'Add Remote' View.
nihadness May 3, 2018
ffc6219
Raise SyncError if record not found in the Souper table.
nihadness May 4, 2018
8c64034
Validate Prefix if Prefixable Types Introduced.
nihadness May 4, 2018
ea66944
Polish.
nihadness May 4, 2018
b5af958
Unwanted Portal Types in 'Add Remote' View.
nihadness May 4, 2018
5e6bea6
Generic 'is_item_allowed' method.
nihadness May 4, 2018
8c3cb5f
'None' --> '[]'
nihadness May 4, 2018
54ad0e1
Quick Fix.
nihadness May 4, 2018
7fb93f9
Polish & Comments
nihadness May 4, 2018
3830b01
Raise SyncError if Remote Path is empty in a Souper Record.
nihadness May 4, 2018
734bfcf
Front End.
nihadness May 4, 2018
3502310
Polish.
nihadness May 4, 2018
4af828c
'Senaite.Lims' compatibility.
nihadness May 7, 2018
2f6dda4
Changes.rst
nihadness May 7, 2018
ac6210b
Remove forgotten pdb.
nihadness May 7, 2018
9c8841b
Uncomment error catch.
nihadness May 7, 2018
bc77d58
Review Changes.
nihadness May 10, 2018
431886d
Polish.
nihadness May 10, 2018
2c7e107
Review Change.
nihadness May 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unwanted Portal Types in 'Add Remote' View.
nihadness committed May 4, 2018
commit b5af958ec723bd0527bb83cb5b647e827feb3135
12 changes: 10 additions & 2 deletions src/senaite/sync/browser/add.py
Original file line number Diff line number Diff line change
@@ -57,15 +57,23 @@ def __call__(self):
import_users = True if form.get("import_users") == 'on' else False
import_registry = True if form.get("import_registry") == 'on' else False
content_types = form.get("content_types", None)
unwanted_content_types = form.get("unwanted_content_types", None)
prefix = form.get("prefix", None)
prefixable_types = form.get("prefixable_types", None)

portal_types = api.get_tool("portal_types")

# Content Type Validation
if content_types is not None:
content_types = [t.strip() for t in content_types.split(",")]
portal_types = api.get_tool("portal_types")
content_types = filter(lambda ct: ct in portal_types,
content_types)
# Content Type Validation
if unwanted_content_types is not None:
unwanted_content_types = [t.strip() for t
in unwanted_content_types.split(",")]
unwanted_content_types = filter(lambda ct: ct in portal_types,
unwanted_content_types)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to reduce a bit the complexity by adding a function to get the content types:

def get_content_types(self, content_types):
    if not content_types:
        return list()
    portal_types = api.get_tool("portal_types")
    ...
    return content_types

So, you'll only need to do the following here:

prefixable_types = self.get_content_types(form.get("prefixable_types", None))
content_types = self.get_content_types(form.get("content_types", None))
unwanted_content_types = self.get_content_types(format.get("unwanted_content_types", None))

Note with this change you'll be able to remove the logic for prefixable_types below.


# Prefix Validation
if prefix:
@@ -84,7 +92,6 @@ def __call__(self):
return self.template()

prefixable_types = [t.strip() for t in prefixable_types.split(",")]
portal_types = api.get_tool("portal_types")
prefixable_types = filter(lambda ct: ct in portal_types,
prefixable_types)

@@ -99,6 +106,7 @@ def __call__(self):
"ac_name": username,
"ac_password": password,
"content_types": content_types,
"unwanted_content_types": unwanted_content_types,
"import_settings": import_settings,
"import_users": import_users,
"import_registry": import_registry,
26 changes: 24 additions & 2 deletions src/senaite/sync/browser/templates/add.pt
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@
Content Types
<span i18n:translate=""
class="help formHelp">
If filled, only indicated Content Types (separated by comma) will be imported. E.g: 'Sample, Client, Worksheet'
If filled, ONLY indicated Content Types (separated by comma) will be imported. E.g: 'Sample, Client, Worksheet'
</span>
</label>
<div class="form-group input-group">
@@ -175,6 +175,28 @@
</div>
</li>

<li class="list-group-item">
<!-- Unwanted Content Types -->
<div class="field form-group field">
<label i18n:translate=""
class="form-control-label"
for="unwanted_content_types">
Content Types to be Skipped
<span i18n:translate=""
class="help formHelp">
If filled, introduced content types will be SKIPPED and only regular objects that are dependencies of the Allowed Types will be imported.. E.g: 'Supplier, Instrument'
</span>
</label>
<div class="form-group input-group">
<input type="text"
size="45"
class="form-control"
id="unwanted_content_types"
name="unwanted_content_types"/>
</div>
</div>
</li>

<li class="list-group-item">
<!-- Prefix -->
<div class="field form-group field">
@@ -206,7 +228,7 @@
Prefixable Content Types
<span i18n:translate=""
class="help formHelp">
Please specify exactly which content types must contain Remote's Prefix in their ID's. E.g: 'Sample, Client, Worksheet'
Please specify exactly which content types must contain Remote's Prefix in their ID's. Must be filled if prefix is enabled. E.g: 'Sample, Client, Worksheet'
</span>
</label>
<div class="form-group input-group">
4 changes: 4 additions & 0 deletions src/senaite/sync/browser/views.py
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@ def __call__(self):
username = storage["credentials"]["username"]
password = storage["credentials"]["password"]
content_types = storage["configuration"].get("content_types", None)
unwanted_content_types = storage["configuration"].get("unwanted_content_types", None)
prefix = storage["configuration"].get("prefix", None)
prefixable_types = storage["configuration"].get("prefixable_types", None)
data = {
@@ -74,6 +75,7 @@ def __call__(self):
"ac_name": username,
"ac_password": password,
"content_types": content_types,
"unwanted_content_types": unwanted_content_types,
"prefix": prefix,
"prefixable_types": prefixable_types,
}
@@ -105,6 +107,7 @@ def __call__(self):
username = storage["credentials"]["username"]
password = storage["credentials"]["password"]
content_types = storage["configuration"].get("content_types", None)
unwanted_content_types = storage["configuration"].get("unwanted_content_types", None)
prefix = storage["configuration"].get("prefix", None)
prefixable_types = storage["configuration"].get("prefixable_types", None)
data = {
@@ -114,6 +117,7 @@ def __call__(self):
"ac_password": password,
"fetch_time": fetch_time,
"content_types": content_types,
"unwanted_content_types": unwanted_content_types,
"prefix": prefix,
"prefixable_types": prefixable_types,
}
6 changes: 5 additions & 1 deletion src/senaite/sync/fetchstep.py
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@ def verify(self):
storage["credentials"]["password"] = self.password
# remember import configuration in the storage
storage["configuration"]["content_types"] = self.content_types
storage["configuration"]["unwanted_content_types"] = self.unwanted_content_types
storage["configuration"]["prefix"] = self.prefix
storage["configuration"]["prefixable_types"] = self.prefixable_types
storage["configuration"]["import_settings"] = self.import_settings
@@ -125,7 +126,10 @@ def _fetch_data(self, window=1000, overlap=10):
start_from, start_from+window))
for item in items:
# skip object or extract the required data for the import
if not item or not item.get("portal_type", True):
if not item:
continue
portal_type = item.get("portal_type", None)
if not portal_type or portal_type in self.unwanted_content_types:
continue
data_dict = utils.get_soup_format(item)
rec_id = self.sh.insert(data_dict)
1 change: 1 addition & 0 deletions src/senaite/sync/syncstep.py
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ def __init__(self, data):
self.password = data.get("ac_password", None)
# Import configuration
self.content_types = data.get("content_types", None)
self.unwanted_content_types = data.get("unwanted_content_types", None)
self.prefix = data.get("prefix", None)
self.prefixable_types = data.get("prefixable_types", None)
self.import_settings = data.get("import_settings", False)