Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URB-3212 - Improve _rest_getDecidedMeetingDate #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
2.0.0b3 (unreleased)
--------------------

- Nothing changed yet.
- Improve `_rest_getDecidedMeetingDate` to make only one request.
[aduchene]


2.0.0b2 (2024-10-16)
Expand Down
63 changes: 30 additions & 33 deletions src/imio/pm/wsclient/browser/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class IGeneratedActionsSchema(Interface):
"""Schema used for the datagrid field 'generated_actions' of IWS4PMClientSettings."""
condition = schema.TextLine(
title=_("TAL Condition"),
required=False,)
required=False, )
permissions = schema.Choice(
title=_("Permissions"),
required=False,
Expand All @@ -57,7 +57,7 @@ class IFieldMappingsSchema(Interface):
vocabulary=u'imio.pm.wsclient.pm_item_data_vocabulary')
expression = schema.TextLine(
title=_("TAL expression to evaluate for the corresponding PloneMeeting field name"),
required=True,)
required=True, )


class IAllowedAnnexTypesSchema(Interface):
Expand All @@ -74,7 +74,7 @@ class IUserMappingsSchema(Interface):
required=True)
pm_userid = schema.TextLine(
title=_("PloneMeeting corresponding user id"),
required=True,)
required=True, )


class IWS4PMClientSettings(Interface):
Expand All @@ -83,34 +83,34 @@ class IWS4PMClientSettings(Interface):
"""
pm_url = schema.TextLine(
title=_(u"PloneMeeting URL"),
required=True,)
required=True, )
pm_timeout = schema.Int(
title=_(u"PloneMeeting connection timeout"),
description=_(u"Enter the timeout while connecting to PloneMeeting. Do not set a too high timeout because it "
"will impact the load of the viewlet showing PM infos on a sent element if PM is not available. "
"Default is '10' seconds."),
default=10,
required=True,)
required=True, )
pm_username = schema.TextLine(
title=_("PloneMeeting username to use"),
description=_(u"The user must be at least a 'MeetingManager'. Nevertheless, items will be created regarding "
"the <i>User ids mappings</i> defined here under."),
required=True,)
required=True, )
pm_password = schema.Password(
title=_("PloneMeeting password to use"),
required=True,)
required=True, )
only_one_sending = schema.Bool(
title=_("An element can be sent one time only"),
default=True,
required=True,)
required=True, )
viewlet_display_condition = schema.TextLine(
title=_("Viewlet display condition"),
description=_("Enter a TAL expression that will be evaluated to check if the viewlet displaying "
"informations about the created items in PloneMeeting should be displayed. "
"If empty, the viewlet will only be displayed if an item is actually linked to it. "
"The 'isLinked' variable representing this default behaviour is available "
"in the TAL expression."),
required=False,)
required=False, )
field_mappings = schema.List(
title=_("Field accessor mappings"),
description=_("For every available data you can send, define in the mapping a TAL expression that will be "
Expand All @@ -122,15 +122,15 @@ class IWS4PMClientSettings(Interface):
value_type=DictRow(title=_("Field mappings"),
schema=IFieldMappingsSchema,
required=False),
required=False,)
required=False, )
allowed_annexes_types = schema.List(
title=_("Allowed annexes types"),
description=_("List here the annexes types allowed to be display in the linked meeting item viewlet"),
value_type=DictRow(title=_("Allowed annex type"),
schema=IAllowedAnnexTypesSchema,
required=False),
default=[],
required=False,)
required=False, )
user_mappings = schema.List(
title=_("User ids mappings"),
description=_("By default, while sending an element to PloneMeeting, the user id of the logged in user "
Expand All @@ -141,7 +141,7 @@ class IWS4PMClientSettings(Interface):
value_type=DictRow(title=_("User mappings"),
schema=IUserMappingsSchema,
required=False),
required=False,)
required=False, )
generated_actions = schema.List(
title=_("Generated actions"),
description=_("Actions to send an item to PloneMeeting can be generated. First enter a 'TAL condition' "
Expand All @@ -150,7 +150,7 @@ class IWS4PMClientSettings(Interface):
value_type=DictRow(title=_("Actions"),
schema=IGeneratedActionsSchema,
required=False),
required=False,)
required=False, )


class WS4PMClientSettingsEditForm(RegistryEditForm):
Expand Down Expand Up @@ -182,7 +182,7 @@ def updateFields(self):
field_mappings.mode = 'display'
else:
if generated_actions_field.mode == 'display' and \
'form.buttons.save' not in self.request.form.keys():
'form.buttons.save' not in self.request.form.keys():
# only change mode while not in the "saving" process (that calls updateFields, but why?)
# because it leads to loosing generated_actions because a [] is returned by extractDate here above
self.fields.get('generated_actions').mode = 'input'
Expand Down Expand Up @@ -269,7 +269,7 @@ def _format_rest_query_url(self, endpoint, **kwargs):
else:
if v:
arguments.append("{0}={1}".format(k, v))
elif k in ("fullobjects", ):
elif k in ("fullobjects",):
arguments.append(k)
if arguments:
return "{url}/{endpoint}?{arguments}".format(
Expand Down Expand Up @@ -410,34 +410,31 @@ def _rest_getMeetingsAcceptingItems(self, data):
return response.json()["items"]

def _rest_getDecidedMeetingDate(self,
data,
item_portal_type,
decided_states=('accepted', 'accepted_but_modified', 'accepted_and_returned')):
data,
item_portal_type,
decided_states=('accepted', 'accepted_but_modified', 'accepted_and_returned')):
"""
Get the actual decided meeting date. It handles delayed and sentTo items appropriately.
Use item_portal_type parameter to get the decided meeting date for this portal_type.
It returns a datetime object if a meeting has been found, or None otherwise.
TODO: handle decided_states correctly, fetching decided states from PloneMeeting configuration
"""
brains = self._rest_searchItems(data)
if not brains:
query = {
'extra_include': 'meeting,linked_items',
'extra_include_linked_items_mode': 'every_successors',
'extra_include_linked_items_extra_include': 'meeting',
}
query.update(data)
items = self._rest_searchItems(query)
if not items:
return # Item has been deleted or has not been sent to PloneMeeting
item = self._rest_getItemInfos(
{"UID": brains[0]['UID'], "showExtraInfos": True,
'extra_include': 'meeting,linked_items',
'extra_include_meeting_additional_values': '*',
'extra_include_linked_items_mode': 'every_successors'}
)[0]
item = items[0]
if item_portal_type == item["@type"] and item['review_state'] in decided_states:
return datetime.strptime(item['extra_include_meeting']['date'], "%Y-%m-%dT%H:%M:%S")
elif item['extra_include_linked_items']:
for linked_item in item['extra_include_linked_items']:
if item_portal_type == linked_item["@type"] and linked_item['review_state'] in decided_states:
item = self._rest_getItemInfos(
{"UID": linked_item['UID'], "showExtraInfos": True, 'extra_include': 'meeting'}
)[0]
return datetime.strptime(item['extra_include_meeting']['date'], "%Y-%m-%dT%H:%M:%S")

return datetime.strptime(linked_item['extra_include_meeting']['date'], "%Y-%m-%dT%H:%M:%S")

def _rest_getItemTemplate(self, data):
"""Query the getItemTemplate REST server method."""
Expand Down Expand Up @@ -717,7 +714,7 @@ def notify_configuration_changed(event):
domain='imio.pm.wsclient',
mapping={
'meetingConfigTitle':
ws4pmSettings.getMeetingConfigTitle(actToGen['pm_meeting_config_id']),
ws4pmSettings.getMeetingConfigTitle(actToGen['pm_meeting_config_id']),
},
context=portal.REQUEST),
description='', i18n_domain='imio.pm.wsclient',
Expand All @@ -726,7 +723,7 @@ def notify_configuration_changed(event):
icon_expr='string:${portal_url}/++resource++imio.pm.wsclient.images/send_to_plonemeeting.png',
available_expr=actToGen['condition'] or '',
# make sure we have a tuple as permissions value
permissions=actToGen['permissions'] and (actToGen['permissions'], ) or ('View', ),
permissions=actToGen['permissions'] and (actToGen['permissions'],) or ('View',),
visible=True)
object_buttons._setObject(actionId, action)
i = i + 1
Loading