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

Conversation

nihadness
Copy link
Contributor

@nihadness nihadness commented May 4, 2018

Current behavior before PR

  1. 'Adding a new Remote From' and 'Data of existing Remotes' are in the same View.
  2. It is not possible to specify object types which a user doesn't want to import.
  3. While importing from different remotes, objects with the same ID are overriden or not being updated.

Desired behavior after PR is merged

  1. The old (/sync) view will only list the Fetched Data and their Actions. New (/sync_add) View will be available to add a new remote.
  2. A new field will be added to 'Add' form where users can define Content Types- separated by comma, to be skipped during import.
  3. New 'Prefix Logic' will be introduced and users will be able to define a prefix for each remote and use them for specific content types. It will help the system to save similar objects from different Remotes separately. Prefixes will be added only to object ID's so far... If Prefix is empty, it will behave in the old, standard way.

Screenshots

Adding New Remote Form:

image

Extended Advanced Options:
image


I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@nihadness nihadness requested a review from juangallostra May 9, 2018 09:12
@nihadness nihadness requested a review from xispa May 9, 2018 09:13

url = form.get("url", "")
if not url.startswith("http"):
url = "http://{}".format(url)
Copy link
Member

Choose a reason for hiding this comment

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

Make "https" as default's

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Safety first! : )

self.add_status_message(message, "error")
return self.template()

import_settings = True if form.get("import_settings") == 'on' else False
Copy link
Member

Choose a reason for hiding this comment

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

Please, replace it as follows:

import_settings = form.get('import_settings') == 'on'

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.

type="submit"
name="fetch"
i18n:attributes="value"
value="Save & Fetch"/>
Copy link
Member

Choose a reason for hiding this comment

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

Better "Save and fetch"

<b>Prefix: <span style="font-size: medium" tal:replace="python: view.storage[storage]['configuration'].get('prefix', 'Not defined')"/></b><br><br>
Settings will <span tal:condition="python: not view.storage[storage]['configuration'].get('import_settings')">NOT</span>,
Registry will <span tal:condition="python: not view.storage[storage]['configuration'].get('import_registry')">NOT</span>,
Users will <span tal:condition="python: not view.storage[storage]['configuration'].get('import_users')">NOT</span> be imported.<br><br>
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to create a function (something like def get_storage_setting(self, parameter, section='configuration') in the view to make the retrieval of all these settings easier. A thumb of rule is to always try to keep the tpl as much simpler as possible, with less logic as possible.

content_types = storage["configuration"].get("content_types", [])
unwanted_content_types = storage["configuration"].get("unwanted_content_types", [])
prefix = storage["configuration"].get("prefix", None)
prefixable_types = storage["configuration"].get("prefixable_types", [])
Copy link
Member

Choose a reason for hiding this comment

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

Same function suggested above to be called from the tpl, could be used here to get all these settings in an easier way

content_types = storage["configuration"].get("content_types", [])
unwanted_content_types = storage["configuration"].get("unwanted_content_types", [])
prefix = storage["configuration"].get("prefix", None)
prefixable_types = storage["configuration"].get("prefixable_types", [])
Copy link
Member

Choose a reason for hiding this comment

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

ditto

if not p_local_uid:
if hasattr(existing, "UID") and existing.UID():
p_local_uid = existing.UID()
self.sh.update_by_path(p_path, local_uid=p_local_uid)
self.sh.update_by_remote_path(p_path, local_uid=p_local_uid)
Copy link
Member

Choose a reason for hiding this comment

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

Please, add some comments here to make the code more understandable for newbies

ret = [t.strip() for t in content_types.split(",") if t]
ret = filter(lambda ct: ct.lower() in portal_types, ret)
ret = filter(lambda ct, types=portal_types: ct in types, ret)
Copy link
Member

Choose a reason for hiding this comment

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

Just ensure there are no duplicates

ret = list(set(ret))

@xispa xispa merged commit 740df4c into senaite:master May 10, 2018
@nihadness nihadness deleted the advanced-configuration branch May 30, 2018 10:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

3 participants