def miniprogram_announcement_post(announcementPostBody): db_session = None if "DEVMODE" in os.environ: if os.environ["DEVMODE"] == "True": db_session = orm.init_db(os.environ["DEV_DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) announcementPostBody_dict = connexion.request.get_json() learner = weapp.getLearner() if not learner: db_session.remove() return {'code': -1001, 'message': '没有找到对应的Learner'}, 200 # 自定义鉴权 if not learner.isAdmin: db_session.remove() return {'code': -1007, 'message': '需要管理员权限', "detail": "只有管理员有权限发送通知"}, 200 try: newAnnouncement = orm.Announcement_db( initiatorId=learner.id, initiatorDisplayName=announcementPostBody_dict['initiatorDisplayName'], recipients=json.dumps(announcementPostBody_dict['recipients']), sentDateTime=util.EWSDateTimeToDateTime(account.default_timezone.localize(EWSDateTime.now())), modifiedDateTime=util.EWSDateTimeToDateTime(account.default_timezone.localize(EWSDateTime.now())), expireDateTime=util.EWSDateTimeToDateTime(EWSDateTime.from_string(announcementPostBody_dict["expireDateTime"])), thumbnail=json.dumps(announcementPostBody_dict['thumbnail']), title=announcementPostBody_dict['title'], description=announcementPostBody_dict['description'], body=json.dumps(announcementPostBody_dict['body']), attachment=json.dumps(announcementPostBody_dict['attachment']), ) db_session.add(newAnnouncement) db_session.commit() newPushMessage = orm.PushMessage_db( messageType="Announcement", entityId=newAnnouncement.id, senderId=learner.id, senderDisplayName=announcementPostBody_dict['initiatorDisplayName'], recipients=json.dumps(announcementPostBody_dict['recipients']), sentDateTime=util.EWSDateTimeToDateTime(account.default_timezone.localize(EWSDateTime.now())), modifiedDateTime=util.EWSDateTimeToDateTime(account.default_timezone.localize(EWSDateTime.now())), expireDateTime=util.EWSDateTimeToDateTime(EWSDateTime.from_string(announcementPostBody_dict["expireDateTime"])), content=json.dumps(announcementPostBody_dict["content"]) ) db_session.add(newPushMessage) db_session.commit() newAnnouncement.pushMessageId = newPushMessage.id db_session.commit() except Exception as e: db_session.remove() return {'code': -5001, 'message': '创建通知失败', 'log': str(e)}, 200 response = {'pushMessage_id': newPushMessage.id, 'announcment_id': newAnnouncement.id} return {'code': 0, 'data': response, 'message': '成功'}, 200
def main(): parser = argparse.ArgumentParser(description='Synchronize ICS to Exchange') parser.add_argument('ics', help="URL of the ICS") parser.add_argument('username', help="EWS username") parser.add_argument('--password', help="EWS password") parser.add_argument('mail', help="EWS primary SMTP mail address") parser.add_argument('--server', help="EWS server") args = parser.parse_args() if not args.password: args.password = getpass() c = Calendar(requests.get(args.ics).text) credentials = Credentials(username=args.username, password=args.password) config = None autodiscover = True if args.server: config = Configuration(server=args.server, credentials=credentials) autodiscover = False my_account = Account(primary_smtp_address=args.mail, credentials=credentials, access_type=DELEGATE, config=config, autodiscover=autodiscover) for i in list(c.timeline): start = EWSDateTime.from_string(str(i.begin)) end = EWSDateTime.from_string(str(i.end)) found = False for calendar_item in my_account.calendar.filter(start__lt=end, end__gt=start): if calendar_item.text_body and args.ics in calendar_item.text_body and i.uid in calendar_item.text_body: found = True break if found: continue item = CalendarItem(account=my_account, folder=my_account.calendar, start=start, end=end, subject=i.name, body="{}\nics2ews: {}\nuid: {}".format( i.description, args.ics, i.uid), location=i.location) item.save()
def miniprogram_announcement_announcementId_patch(announcementId, announcementPatchBody): # 修改通知接口 db_session = None if "DEVMODE" in os.environ: if os.environ["DEVMODE"] == "True": db_session = orm.init_db(os.environ["DEV_DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) announcementPatchBody_dict = connexion.request.get_json() learner = weapp.getLearner() if not learner: db_session.remove() return {'code': -1001, 'message': '没有找到对应的Learner'}, 200 announcement = db_session.query(orm.Announcement_db).filter(orm.Announcement_db.id == announcementId).one_or_none() pushMessage = db_session.query(orm.PushMessage_db).filter(orm.PushMessage_db.id == announcement.pushMessageId).one_or_none() try: for itemKey in announcementPatchBody_dict: if itemKey == "initiatorDisplayName": announcement.initiatorDisplayName = announcementPatchBody_dict[itemKey] if itemKey == "recipients": announcement.recipients = json.dumps(announcementPatchBody_dict[itemKey]) if itemKey == "thumbnail": announcement.thumbnail = json.dumps(announcementPatchBody_dict[itemKey]) if itemKey == "content": pushMessage.content = json.dumps(announcementPatchBody_dict[itemKey]) if itemKey == "body": announcement.body = json.dumps(announcementPatchBody_dict[itemKey]) if itemKey == "attachment": announcement.attachment = json.dumps(announcementPatchBody_dict[itemKey]) if itemKey == "title": announcement.title = announcementPatchBody_dict[itemKey] if itemKey == "description": announcement.description = announcementPatchBody_dict[itemKey] if itemKey == "expireDateTime": newExpireDateTime = util.EWSDateTimeToDateTime(EWSDateTime.from_string(announcementPatchBody_dict[itemKey])), setattr(pushMessage, itemKey, newExpireDateTime) newModifiedDateTime = util.EWSDateTimeToDateTime(account.default_timezone.localize(EWSDateTime.now())), pushMessage.modifiedDateTime = newModifiedDateTime db_session.commit() db_session.remove() return {'code': 0, 'message': '成功'}, 200 except Exception as e: db_session.remove() return {'code': -5002, 'message': '更新通知失败', 'log': str(e)}, 200
def test_ewsdatetime(self): # Test a static timezone tz = EWSTimeZone('Etc/GMT-5') dt = EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=tz) self.assertIsInstance(dt, EWSDateTime) self.assertIsInstance(dt.tzinfo, EWSTimeZone) self.assertEqual(dt.tzinfo.ms_id, tz.ms_id) self.assertEqual(dt.tzinfo.ms_name, tz.ms_name) self.assertEqual(str(dt), '2000-01-02 03:04:05+05:00') self.assertEqual( repr(dt), "EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=EWSTimeZone(key='Etc/GMT-5'))" ) # Test a DST timezone tz = EWSTimeZone('Europe/Copenhagen') dt = EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=tz) self.assertIsInstance(dt, EWSDateTime) self.assertIsInstance(dt.tzinfo, EWSTimeZone) self.assertEqual(dt.tzinfo.ms_id, tz.ms_id) self.assertEqual(dt.tzinfo.ms_name, tz.ms_name) self.assertEqual(str(dt), '2000-01-02 03:04:05+01:00') self.assertEqual( repr(dt), "EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=EWSTimeZone(key='Europe/Copenhagen'))" ) # Test from_string with self.assertRaises(NaiveDateTimeNotAllowed): EWSDateTime.from_string('2000-01-02T03:04:05') self.assertEqual(EWSDateTime.from_string('2000-01-02T03:04:05+01:00'), EWSDateTime(2000, 1, 2, 2, 4, 5, tzinfo=UTC)) self.assertEqual(EWSDateTime.from_string('2000-01-02T03:04:05Z'), EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=UTC)) self.assertIsInstance( EWSDateTime.from_string('2000-01-02T03:04:05+01:00'), EWSDateTime) self.assertIsInstance(EWSDateTime.from_string('2000-01-02T03:04:05Z'), EWSDateTime) # Test addition, subtraction, summertime etc self.assertIsInstance(dt + datetime.timedelta(days=1), EWSDateTime) self.assertIsInstance(dt - datetime.timedelta(days=1), EWSDateTime) self.assertIsInstance(dt - EWSDateTime.now(tz=tz), datetime.timedelta) self.assertIsInstance(EWSDateTime.now(tz=tz), EWSDateTime) # Test various input for from_datetime() self.assertEqual( dt, EWSDateTime.from_datetime( datetime.datetime(2000, 1, 2, 3, 4, 5, tzinfo=EWSTimeZone('Europe/Copenhagen')))) self.assertEqual( dt, EWSDateTime.from_datetime( datetime.datetime( 2000, 1, 2, 3, 4, 5, tzinfo=zoneinfo.ZoneInfo('Europe/Copenhagen')))) self.assertEqual( dt, EWSDateTime.from_datetime( datetime.datetime( 2000, 1, 2, 3, 4, 5, tzinfo=dateutil.tz.gettz('Europe/Copenhagen')))) self.assertEqual( dt, EWSDateTime.from_datetime( datetime.datetime(2000, 1, 2, 3, 4, 5, tzinfo=pytz.timezone('Europe/Copenhagen')))) self.assertEqual(dt.ewsformat(), '2000-01-02T03:04:05+01:00') utc_tz = EWSTimeZone('UTC') self.assertEqual( dt.astimezone(utc_tz).ewsformat(), '2000-01-02T02:04:05Z') # Test summertime dt = EWSDateTime(2000, 8, 2, 3, 4, 5, tzinfo=tz) self.assertEqual( dt.astimezone(utc_tz).ewsformat(), '2000-08-02T01:04:05Z') # Test in-place add and subtract dt = EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=tz) dt += datetime.timedelta(days=1) self.assertIsInstance(dt, EWSDateTime) self.assertEqual(dt, EWSDateTime(2000, 1, 3, 3, 4, 5, tzinfo=tz)) dt = EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=tz) dt -= datetime.timedelta(days=1) self.assertIsInstance(dt, EWSDateTime) self.assertEqual(dt, EWSDateTime(2000, 1, 1, 3, 4, 5, tzinfo=tz)) # Test ewsformat() failure dt = EWSDateTime(2000, 1, 2, 3, 4, 5) with self.assertRaises(ValueError): dt.ewsformat() # Test wrong tzinfo type with self.assertRaises(ValueError): EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=zoneinfo.ZoneInfo('UTC')) with self.assertRaises(ValueError): EWSDateTime.from_datetime(EWSDateTime(2000, 1, 2, 3, 4, 5))
def test_ewsdatetime(self): # Test a static timezone tz = EWSTimeZone.timezone('Etc/GMT-5') dt = tz.localize(EWSDateTime(2000, 1, 2, 3, 4, 5)) self.assertIsInstance(dt, EWSDateTime) self.assertIsInstance(dt.tzinfo, EWSTimeZone) self.assertEqual(dt.tzinfo.ms_id, tz.ms_id) self.assertEqual(dt.tzinfo.ms_name, tz.ms_name) self.assertEqual(str(dt), '2000-01-02 03:04:05+05:00') self.assertEqual( repr(dt), "EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=<StaticTzInfo 'Etc/GMT-5'>)" ) # Test a DST timezone tz = EWSTimeZone.timezone('Europe/Copenhagen') dt = tz.localize(EWSDateTime(2000, 1, 2, 3, 4, 5)) self.assertIsInstance(dt, EWSDateTime) self.assertIsInstance(dt.tzinfo, EWSTimeZone) self.assertEqual(dt.tzinfo.ms_id, tz.ms_id) self.assertEqual(dt.tzinfo.ms_name, tz.ms_name) self.assertEqual(str(dt), '2000-01-02 03:04:05+01:00') self.assertEqual( repr(dt), "EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=<DstTzInfo 'Europe/Copenhagen' CET+1:00:00 STD>)" ) # Test from_string with self.assertRaises(NaiveDateTimeNotAllowed): EWSDateTime.from_string('2000-01-02T03:04:05') self.assertEqual(EWSDateTime.from_string('2000-01-02T03:04:05+01:00'), UTC.localize(EWSDateTime(2000, 1, 2, 2, 4, 5))) self.assertEqual(EWSDateTime.from_string('2000-01-02T03:04:05Z'), UTC.localize(EWSDateTime(2000, 1, 2, 3, 4, 5))) self.assertIsInstance( EWSDateTime.from_string('2000-01-02T03:04:05+01:00'), EWSDateTime) self.assertIsInstance(EWSDateTime.from_string('2000-01-02T03:04:05Z'), EWSDateTime) # Test addition, subtraction, summertime etc self.assertIsInstance(dt + datetime.timedelta(days=1), EWSDateTime) self.assertIsInstance(dt - datetime.timedelta(days=1), EWSDateTime) self.assertIsInstance(dt - EWSDateTime.now(tz=tz), datetime.timedelta) self.assertIsInstance(EWSDateTime.now(tz=tz), EWSDateTime) self.assertEqual( dt, EWSDateTime.from_datetime( tz.localize(datetime.datetime(2000, 1, 2, 3, 4, 5)))) self.assertEqual(dt.ewsformat(), '2000-01-02T03:04:05+01:00') utc_tz = EWSTimeZone.timezone('UTC') self.assertEqual( dt.astimezone(utc_tz).ewsformat(), '2000-01-02T02:04:05Z') # Test summertime dt = tz.localize(EWSDateTime(2000, 8, 2, 3, 4, 5)) self.assertEqual( dt.astimezone(utc_tz).ewsformat(), '2000-08-02T01:04:05Z') # Test normalize, for completeness self.assertEqual( tz.normalize(dt).ewsformat(), '2000-08-02T03:04:05+02:00') self.assertEqual( utc_tz.normalize(dt, is_dst=True).ewsformat(), '2000-08-02T01:04:05Z') # Test in-place add and subtract dt = tz.localize(EWSDateTime(2000, 1, 2, 3, 4, 5)) dt += datetime.timedelta(days=1) self.assertIsInstance(dt, EWSDateTime) self.assertEqual(dt, tz.localize(EWSDateTime(2000, 1, 3, 3, 4, 5))) dt = tz.localize(EWSDateTime(2000, 1, 2, 3, 4, 5)) dt -= datetime.timedelta(days=1) self.assertIsInstance(dt, EWSDateTime) self.assertEqual(dt, tz.localize(EWSDateTime(2000, 1, 1, 3, 4, 5))) # Test ewsformat() failure dt = EWSDateTime(2000, 1, 2, 3, 4, 5) with self.assertRaises(ValueError): dt.ewsformat() # Test wrong tzinfo type with self.assertRaises(ValueError): EWSDateTime(2000, 1, 2, 3, 4, 5, tzinfo=pytz.utc) with self.assertRaises(ValueError): EWSDateTime.from_datetime(EWSDateTime(2000, 1, 2, 3, 4, 5))
obj['this_is_a_list'] = [] obj['this_is_a_list'].append('list_value') res = EWSv2.keys_to_camel_case(obj) assert res['thisIsAValue'] == 'the_value' assert res['thisIsAList'][0] == 'listValue' def test_start_logging(): EWSv2.start_logging() logging.getLogger().debug("test this") assert "test this" in EWSv2.log_stream.getvalue() @pytest.mark.parametrize( 'since_datetime, expected_result', [('', EWSDateTime.from_string('2021-05-23 13:18:14.901293+00:00'))]) def test_fetch_last_emails_first_fetch(mocker, since_datetime, expected_result): """ Given: - First fetch timestamp - no last_run When: - Fetching last emails Then: - Verify datetime_received__gte is ten minutes earlier """ class MockObject: def filter(self, datetime_received__gte=''): return MockObject2()
Given: - String that represents the HTML body When: - Parsing the HTML string to incorporate the inline images Then: - Clean the HTML string and add the relevant references to image files """ import EWSO365 as ewso365 mocker.patch.object(ewso365, 'random_word_generator', return_value='abcd1234') assert handle_html(html_input) == expected_output @freeze_time('2021-05-23 13:18:14.901293+00:00') @pytest.mark.parametrize('since_datetime, filter_arg, expected_result', [('', 'last_modified_time__gte', EWSDateTime.from_string('2021-05-23 13:08:14.901293+00:00')), ('2021-05-23 21:28:14.901293+00:00', 'datetime_received__gte', '2021-05-23 21:28:14.901293+00:00') ]) def test_fetch_last_emails(mocker, since_datetime, filter_arg, expected_result): """ Given: - First fetch timestamp - no last_run - Not the first time fetching - last_run with a date When: - Fetching last emails Then: - Verify last_modified_time__gte is ten minutes earlier - Verify datetime_received__gte according to the datetime received
Then: - Clean the HTML string and add the relevant references to image files """ import EWSO365 as ewso365 mocker.patch.object(ewso365, 'random_word_generator', return_value='abcd1234') assert handle_html(html_input) == expected_output @freeze_time('2021-05-23 13:18:14.901293+00:00') @pytest.mark.parametrize( 'since_datetime, filter_arg, expected_result', [('', 'last_modified_time__gte', EWSDateTime.from_string('2021-05-23 13:08:14.901293+00:00')), ('2021-05-23 21:28:14.901293+00:00', 'datetime_received__gte', '2021-05-23 21:28:14.901293+00:00')]) def test_fetch_last_emails(mocker, since_datetime, filter_arg, expected_result): """ Given: - First fetch timestamp - no last_run - Not the first time fetching - last_run with a date When: - Fetching last emails Then: - Verify last_modified_time__gte is ten minutes earlier - Verify datetime_received__gte according to the datetime received
def miniprogram_event_post(eventPostBody): # 创建活动接口 db_session = None if "DEVMODE" in os.environ: if os.environ["DEVMODE"] == "True": db_session = orm.init_db(os.environ["DEV_DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) eventPostBody_dict = connexion.request.get_json() learner = weapp.getLearner() if not learner: db_session.remove() return {'code': -1001, 'message': '没有找到对应的Learner'}, 200 # 自定义鉴权 if not learner.isAdmin: if "initiatorDisplayName" in eventPostBody: db_session.remove() return { 'code': -1007, 'message': '需要管理员权限', "detail": "非管理员不可自定义发起者名称" }, 200 initiatorDisplayName = learner.familyName + learner.givenName else: initiatorDisplayName = eventPostBody_dict[ "initiatorDisplayName"] if "initiatorDisplayName" in eventPostBody_dict else learner.familyName + learner.givenName try: newEvent = orm.Event_db( initiatorId=learner.id, initiatorDisplayName=initiatorDisplayName, eventInfo=json.dumps(eventPostBody_dict["eventInfo"]), invitee=json.dumps(eventPostBody_dict["invitee"]), thumbnail=json.dumps(eventPostBody_dict["thumbnail"]), expireDateTime=util.EWSDateTimeToDateTime( EWSDateTime.from_string( eventPostBody_dict["eventInfo"]["expireDateTime"]))) db_session.add(newEvent) db_session.commit() newPushMessage = orm.PushMessage_db( messageType="Event", entityId=newEvent.id, senderId=learner.id, senderDisplayName=initiatorDisplayName, recipients=json.dumps(eventPostBody_dict["invitee"]), rsvp=json.dumps({ "accept": [], "decline": [], "tentative": [] }), sentDateTime=util.EWSDateTimeToDateTime( account.default_timezone.localize(EWSDateTime.now())), modifiedDateTime=util.EWSDateTimeToDateTime( account.default_timezone.localize(EWSDateTime.now())), expireDateTime=util.EWSDateTimeToDateTime( EWSDateTime.from_string( eventPostBody_dict["eventInfo"]["expireDateTime"])), content=json.dumps(eventPostBody_dict["content"])) db_session.add(newPushMessage) db_session.commit() newEvent.pushMessageId = newPushMessage.id db_session.commit() newNotification = orm.Notification_db( learnerId=learner.id, notificationType="活动日程", entityId=newEvent.id, createdDateTime=util.EWSDateTimeToDateTime( account.default_timezone.localize(EWSDateTime.now())), expireDateTime=util.EWSDateTimeToDateTime( EWSDateTime.from_string( json.loads(newEvent.eventInfo)["expireDateTime"])), title=json.loads(newEvent.eventInfo)["title"], description=json.loads(newEvent.eventInfo)["description"]) db_session.add(newNotification) db_session.commit() # TODO: 这里应当添加Microsoft Graph API为initiator添加appointment并发送至recipients except Exception as e: db_session.remove() return {'code': -3001, 'message': '活动创建失败', 'log': str(e)}, 200 response = {"pushMessageId": newPushMessage.id, "id": newEvent.id} db_session.remove() return {'code': 0, 'data': response, 'message': '成功'}, 200
def miniprogram_event_patch(eventId): # 修改活动接口,包括报名的部分 db_session = None if "DEVMODE" in os.environ: if os.environ["DEVMODE"] == "True": db_session = orm.init_db(os.environ["DEV_DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) eventPatchBody_dict = connexion.request.get_json() learner = weapp.getLearner() if not learner: db_session.remove() return {'code': -1001, 'message': '没有找到对应的Learner'}, 200 event: orm.Event_db = db_session.query( orm.Event_db).filter(orm.Event_db.id == eventId).one_or_none() pushMessage = db_session.query(orm.PushMessage_db).filter( orm.PushMessage_db.id == event.pushMessageId).one_or_none() if event.initiatorId != learner.id: try: newRsvp = json.loads(pushMessage.rsvp) if pushMessage.rsvp else { 'accept': [], 'decline': [], 'tentative': [] } newEntry = { 'id': learner.id, 'fullname': learner.familyName + learner.givenName } # 登记参加的处理逻辑 if eventPatchBody_dict["rsvp"] == "参加": if newEntry not in newRsvp['accept']: newRsvp["accept"].append(newEntry) existingNotification: orm.Notification_db = db_session.query( orm.Notification_db).filter( orm.Notification_db.learnerId == learner.id ).filter(orm.Notification_db.notificationType == "活动日程").filter(orm.Notification_db.entityId == event.id).one_or_none() if existingNotification: existingNotification.status = "参加" else: newNotification: orm.Notification_db = orm.Notification_db( learnerId=learner.id, notificationType="活动日程", entityId=event.id, createdDateTime=util.EWSDateTimeToDateTime( account.default_timezone.localize( EWSDateTime.now())), expireDateTime=util.EWSDateTimeToDateTime( EWSDateTime.from_string( json.loads( event.eventInfo)["expireDateTime"])), status="参加", title=json.loads(event.eventInfo)["title"], description=json.loads( event.eventInfo)["description"], ) db_session.add(newNotification) for responseType in ["decline"]: if newEntry in newRsvp[responseType]: newRsvp[responseType].remove(newEntry) for responseType in ["tentative"]: if newEntry in newRsvp[responseType]: newRsvp[responseType].remove(newEntry) # 登记不参加的处理逻辑 if eventPatchBody_dict["rsvp"] == "不参加": if newEntry not in newRsvp['decline']: newRsvp["decline"].append(newEntry) for responseType in ["accept", "tentative"]: if newEntry in newRsvp[responseType]: newRsvp[responseType].remove(newEntry) notificationToDelete = db_session.query( orm.Notification_db).filter( orm.Notification_db.learnerId == learner.id).filter( orm.Notification_db.notificationType == "活动日程").filter(orm.Notification_db.entityId == event.id).one_or_none() if notificationToDelete: db_session.delete(notificationToDelete) # 登记待定的处理逻辑 if eventPatchBody_dict["rsvp"] == "待定": if newEntry not in newRsvp['tentative']: newRsvp["tentative"].append(newEntry) existingNotification: orm.Notification_db = db_session.query( orm.Notification_db).filter( orm.Notification_db.learnerId == learner.id ).filter(orm.Notification_db.notificationType == "活动日程").filter(orm.Notification_db.entityId == event.id).one_or_none() if existingNotification: existingNotification.status = "待定" else: newNotification: orm.Notification_db = orm.Notification_db( learnerId=learner.id, notificationType="活动日程", entityId=event.id, createdDateTime=util.EWSDateTimeToDateTime( account.default_timezone.localize( EWSDateTime.now())), expireDateTime=util.EWSDateTimeToDateTime( EWSDateTime.from_string( json.loads( event.eventInfo)["expireDateTime"])), status="参加", title=json.loads(event.eventInfo)["title"], description=json.loads( event.eventInfo)["description"], ) db_session.add(newNotification) for responseType in ["decline", "accept"]: if newEntry in newRsvp[responseType]: newRsvp[responseType].remove(newEntry) setattr(pushMessage, "rsvp", json.dumps(newRsvp)) db_session.commit() except Exception as e: db_session.remove() return {'code': -3002, 'message': '更新rsvp信息失败', 'log': str(e)}, 200 db_session.remove() return {'code': 0, 'message': '成功更新rsvp信息'}, 200 else: try: for itemKey in eventPatchBody_dict: if itemKey == "initiatorDisplayName": event.initiatorDisplayName = eventPatchBody_dict[itemKey] if itemKey == "invitee": event.invitee = json.dumps(eventPatchBody_dict[itemKey]) if itemKey == "thumbnail": event.thumbnail = json.dumps(eventPatchBody_dict[itemKey]) if itemKey == "content": pushMessage.content = json.dumps( eventPatchBody_dict[itemKey]) if itemKey in ["title", "description", "fee", "location"]: newEventInfo = json.loads(event.eventInfo) newEventInfo[itemKey] = eventPatchBody_dict[itemKey] event.eventInfo = json.dumps(newEventInfo) if itemKey in ["endDateTime", "startDateTime"]: newEventInfo = json.loads(event.eventInfo) newEventInfo[itemKey] = eventPatchBody_dict[itemKey] event.eventInfo = json.dumps(newEventInfo) newPatchDateTime = util.EWSDateTimeToDateTime( EWSDateTime.from_string(eventPatchBody_dict[itemKey])), setattr(pushMessage, itemKey, newPatchDateTime) if itemKey == "expireDateTime": newPatchExpireDateTime = util.EWSDateTimeToDateTime( EWSDateTime.from_string(eventPatchBody_dict[itemKey])), setattr(pushMessage, itemKey, newPatchExpireDateTime) setattr(event, "expireDateTime", newPatchExpireDateTime) newModifiedDateTime = util.EWSDateTimeToDateTime( account.default_timezone.localize(EWSDateTime.now())), pushMessage.modifiedDateTime = newModifiedDateTime db_session.commit() db_session.remove() return {'code': 0, 'message': '成功'}, 200 except Exception as e: db_session.remove() return {'code': -3003, 'message': '更新活动失败', 'log': str(e)}, 200