Merge pull request #411 from sartography/convert-timestamp-499

get_localtime cleanup #499
This commit is contained in:
Dan Funk 2021-11-01 15:36:39 -04:00 committed by GitHub
commit 28d4fa4675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 21 deletions

View File

@ -1,5 +1,6 @@
import sys
import traceback
import datetime
from crc import app, session
from crc.api.common import ApiError
@ -45,7 +46,8 @@ email(subject="My Subject", recipients="user@example.com", attachments=['Study_A
subject = self.get_subject(kwargs['subject'])
recipients = self.get_email_addresses(kwargs['recipients'], study_id)
content, content_html = EmailService().get_rendered_content(task.task_spec.documentation, task.data)
email_model = EmailModel(subject=subject,
email_model = EmailModel(id=1,
subject=subject,
recipients=recipients,
content=content,
content_html=content_html,

View File

@ -2,7 +2,9 @@ from crc.scripts.script import Script
from crc.api.common import ApiError
from crc import session
from crc.models.email import EmailModel, EmailModelSchema
import json
from crc.services.email_service import EmailService
import datetime
class EmailData(Script):
@ -12,11 +14,22 @@ class EmailData(Script):
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
if 'email_id' in kwargs or 'workflow_spec_id' in kwargs:
return True
else:
return False
subject = 'My Test Email'
recipients = 'user@example.com'
content, content_html = EmailService().get_rendered_content(task.task_spec.documentation, task.data)
email_model = EmailModel(subject=subject,
recipients=recipients,
content=content,
content_html=content_html,
timestamp=datetime.datetime.utcnow())
return EmailModelSchema(many=True).dump([email_model])
def do_task(self, task, study_id, workflow_id, **kwargs):
else:
raise ApiError.from_task(code='missing_email_id',
message='You must include an email_id or workflow_spec_id with the get_email_data script.',
task=task)
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
email_models = None
email_data = None
if 'email_id' in kwargs:

View File

@ -1,5 +1,3 @@
import datetime
from crc.api.common import ApiError
from crc.scripts.script import Script
@ -15,7 +13,7 @@ class GetLocaltime(Script):
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
if 'timestamp' in kwargs:
return datetime.datetime.now()
return self.do_task(task, study_id, workflow_id, *args, **kwargs)
raise ApiError(code='missing_timestamp',
message='You must include a timestamp to convert.')

View File

@ -15,7 +15,9 @@
<bpmn:documentation>This is my email</bpmn:documentation>
<bpmn:incoming>Flow_0lnc9x0</bpmn:incoming>
<bpmn:outgoing>Flow_0gtgzcf</bpmn:outgoing>
<bpmn:script>email_model = email(subject='My Email Subject', recipients='user@example.com')</bpmn:script>
<bpmn:script>email_model = email(subject='My Email Subject', recipients='user@example.com')
email_data = get_email_data(email_id=email_model['id'])
</bpmn:script>
</bpmn:scriptTask>
<bpmn:scriptTask id="Activity_1by2ose" name="Get Localtime">
<bpmn:documentation>timestamp = email_model.timestamp
@ -23,7 +25,8 @@ localtime = get_localtime(str(timestamp))</bpmn:documentation>
<bpmn:incoming>Flow_0gtgzcf</bpmn:incoming>
<bpmn:outgoing>Flow_0k1hbif</bpmn:outgoing>
<bpmn:script>timestamp=email_model.timestamp
localtime = get_localtime(timestamp=timestamp)</bpmn:script>
localtime = get_localtime(timestamp=timestamp)
</bpmn:script>
</bpmn:scriptTask>
<bpmn:manualTask id="Activity_0d5fjpa" name="Display Times">
<bpmn:documentation># Timestamp
@ -38,21 +41,21 @@ localtime = get_localtime(timestamp=timestamp)</bpmn:script>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1dxw783">
<bpmndi:BPMNEdge id="Flow_0lnc9x0_di" bpmnElement="Flow_0lnc9x0">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0gtgzcf_di" bpmnElement="Flow_0gtgzcf">
<di:waypoint x="370" y="117" />
<di:waypoint x="430" y="117" />
<bpmndi:BPMNEdge id="Flow_0kgtoh1_di" bpmnElement="Flow_0kgtoh1">
<di:waypoint x="690" y="117" />
<di:waypoint x="752" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0k1hbif_di" bpmnElement="Flow_0k1hbif">
<di:waypoint x="530" y="117" />
<di:waypoint x="590" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0kgtoh1_di" bpmnElement="Flow_0kgtoh1">
<di:waypoint x="690" y="117" />
<di:waypoint x="752" y="117" />
<bpmndi:BPMNEdge id="Flow_0gtgzcf_di" bpmnElement="Flow_0gtgzcf">
<di:waypoint x="370" y="117" />
<di:waypoint x="430" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0lnc9x0_di" bpmnElement="Flow_0lnc9x0">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />