コード例 #1
0
 def save_event(self):
     """
     This method takes dictionary containing event data. It first checks if
     any event is there with given info (user_id, social_network_id,
     social_network_event_id), then it updates the existing event otherwise
     creates a new event in getTalent database.
     Call this method after successfully publishing event on social network.
     :return event.id: id for event in getTalent database, that was created or updated
     :rtype event.id : int
     """
     data = self.data
     sn_event_id = data['social_network_event_id']
     social_network_id = data['social_network_id']
     event = Event.get_by_user_id_social_network_id_vendor_event_id(
         self.user.id, social_network_id, sn_event_id)
     try:
         # if event exists in database, then update existing one.
         if event:
             del data['id']
             event.update(**data)
         else:
             # event not found in database, create a new one
             event = Event(**data)
             Event.save(event)
     except Exception as error:
         logger.exception(
             'save_event: Event was not updated/saved in Database. '
             'user_id: %s, event_id: %s, social network: %s(id: %s). Error:%s'
             % (self.user.id, event.id, self.social_network.name,
                self.social_network.id, error.message))
         raise EventNotSaveInDb(
             'Error occurred while saving event in database')
     return event.id
コード例 #2
0
 def save_or_update_event(self, event_data):
     """
     This method takes event dictionary data and save that event in database or update the existing one
     if there is already event there with this data.
     :param event_data: event dict
     :rtype: Event
     """
     event = Event.get_by_user_id_social_network_id_vendor_event_id(
         self.user.id, self.social_network.id,
         event_data['social_network_event_id'])
     event_data['is_deleted_from_vendor'] = 0
     event_data['is_hidden'] = 0
     if event:
         event.update(**event_data)
         logger.info('Event updated successfully : %s' % event.to_json())
     else:
         event = Event(**event_data)
         Event.save(event)
         logger.info('Event imported successfully : %s' % event.to_json())
     return event