Updated annotations adapters
authorThierry Florac <thierry.florac@onf.fr>
Mon, 28 May 2018 14:05:19 +0200
changeset 68 0169d052e20d
parent 67 c7d8a3a64220
child 69 c0483f61b97e
Updated annotations adapters
src/pyams_scheduler/trigger.py
--- a/src/pyams_scheduler/trigger.py	Mon May 28 12:00:32 2018 +0200
+++ b/src/pyams_scheduler/trigger.py	Mon May 28 14:05:19 2018 +0200
@@ -18,14 +18,13 @@
 # import interfaces
 from pyams_scheduler.interfaces import ITaskSchedulingMode, ICronTaskScheduling, ICronTask, SCHEDULER_TASK_CRON_INFO, \
     IDateTaskScheduling, IDateTask, ILoopTaskScheduling, SCHEDULER_TASK_DATE_INFO, ILoopTask, SCHEDULER_TASK_LOOP_INFO
-from zope.annotation.interfaces import IAnnotations
 
 # import packages
 from apscheduler.triggers.cron import CronTrigger
 from apscheduler.triggers.date import DateTrigger
 from apscheduler.triggers.interval import IntervalTrigger
 from persistent import Persistent
-from pyams_utils.adapter import adapter_config
+from pyams_utils.adapter import adapter_config, get_annotation_adapter
 from pyams_utils.date import date_to_datetime
 from pyams_utils.registry import utility_config
 from pyams_utils.timezone import tztime
@@ -92,11 +91,8 @@
 @adapter_config(context=ICronTask, provides=ICronTaskScheduling)
 def cron_task_scheduler_info_factory(context):
     """Cron-style task scheduling info factory"""
-    annotations = IAnnotations(context)
-    info = annotations.get(SCHEDULER_TASK_CRON_INFO)
-    if info is None:
-        info = annotations[SCHEDULER_TASK_CRON_INFO] = CronTaskScheduleInfo()
-    return info
+    return get_annotation_adapter(context, SCHEDULER_TASK_CRON_INFO, CronTaskScheduleInfo,
+                                  notify=False, locate=False)
 
 
 #
@@ -128,11 +124,8 @@
 @adapter_config(context=IDateTask, provides=IDateTaskScheduling)
 def date_task_scheduler_info_factory(context):
     """Date-style task scheduling info factory"""
-    annotations = IAnnotations(context)
-    info = annotations.get(SCHEDULER_TASK_DATE_INFO)
-    if info is None:
-        info = annotations[SCHEDULER_TASK_DATE_INFO] = DateTaskScheduleInfo()
-    return info
+    return get_annotation_adapter(context, SCHEDULER_TASK_DATE_INFO, DateTaskScheduleInfo,
+                                  notify=False, locate=False)
 
 
 #
@@ -176,8 +169,5 @@
 @adapter_config(context=ILoopTask, provides=ILoopTaskScheduling)
 def loop_task_scheduler_info_factory(context):
     """Loop-style task scheduling info factory"""
-    annotations = IAnnotations(context)
-    info = annotations.get(SCHEDULER_TASK_LOOP_INFO)
-    if info is None:
-        info = annotations[SCHEDULER_TASK_LOOP_INFO] = LoopTaskScheduleInfo()
-    return info
+    return get_annotation_adapter(context, SCHEDULER_TASK_LOOP_INFO, LoopTaskScheduleInfo,
+                                  notify=False, locate=False)