def startFixExpirationDate(self): """ Fix affected objects """ wf = getToolByName(self.context, "portal_workflow", None) mt = getToolByName(self.context, 'portal_membership', None) actor = mt.getAuthenticatedMember().id for brain in self.search(): obj = brain.getObject() history = ContentHistoryView(obj, self.request).fullHistory() for entry in history: if entry['transition_title'] == 'Archive': date = entry['time'] obj.setExpirationDate(date) for wfname in obj.workflow_history.keys(): state = wf.getInfoFor(obj, 'review_state', 'None') comment = 'Added missing Expiration Date.' history = obj.workflow_history[wfname] history += ({ 'action': 'Upgrade script', 'review_state': state, 'actor': actor, 'comments': comment, 'time': DateTime(), }, ) obj.workflow_history[wfname] = history obj.workflow_history._p_changed = True obj.reindexObject() notify(ObjectModifiedEvent(obj)) break start = self.request.get('start_from_script', None) if start: return return self.index()
def checkPublishingDate(self, brains, excludeExpired, updateEffectiveDate): """ Return values of the creation and publishing date """ result = '<table border="1"><tr><th>#</th><th>Obj URL</th><th>Creation date</th><th>Obj effective</th><th>Brain effective</th><th>History date</th><th>WARNING</th></tr>' request = self.REQUEST count = 0 total = len(brains) for brain in brains: count += 1 # exclude expired content from the report if (brain.ExpirationDate != 'None') and excludeExpired: info('EXPIRED, excluded from the report: %s' % brain.getURL()) continue obj = brain.getObject() info('%s/%s - checking dates for %s' % (count, total, brain.getURL())) history = None history_publishing_date = None try: history = ContentHistoryView(obj, request).fullHistory() except Exception, err: info('ERROR: no history found for %s', brain.getURL()) info_exception('Exception: %s ', err) for entry in history: if entry['transition_title'] == 'Publish': history_publishing_date = entry['time'] break date_warning = '' if history_publishing_date: if (obj.effective().Date() != brain.effective.Date()) or \ (obj.effective().Date() != history_publishing_date.Date()) or \ (brain.effective.Date() != history_publishing_date.Date()): date_warning = 'True' else: if (obj.effective().Date() != brain.effective.Date()) or \ (obj.effective().Date() != brain.created.Date()) or \ (brain.effective.Date() != brain.created.Date()): date_warning = 'True' # update EffectiveDate value if (date_warning == 'True') and updateEffectiveDate: obj.edit(effectiveDate=history_publishing_date) obj.reindexObject() #obj.reindexObject(idxs=["EffectiveDate"]) result += "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % ( count, brain.getURL(), brain.created, obj.effective(), brain.effective, history_publishing_date, date_warning) if count % 5 == 0: transaction.commit()
def get_revision_history(brain_or_object): """Get the revision history for the given brain or context. :param brain_or_object: A single catalog brain or content object :type brain_or_object: ATContentType/DexterityContentType/CatalogBrain :returns: Workflow history :rtype: obj """ obj = get_object(brain_or_object) chv = ContentHistoryView(obj, safe_getattr(obj, "REQUEST", None)) return chv.fullHistory()
def __call__(self): related_action = self.element.related_action notification_subject = self.element.notification_subject notification_action = self.element.notification_action obj = self.event.object path = "/".join(obj.getPhysicalPath()) tags = get_tags(obj) try: url = obj.absolute_url() except Exception: url = "N/A" try: content_title = obj.Title() except Exception: content_title = "N/A" try: actor = ContentHistoryView( obj, self.context.REQUEST).fullHistory()[0]['actor']['username'] except Exception: try: actor = obj.Creator() except Exception: actor = "N/A" rabbit_config = get_rabbit_config() rabbit = RabbitMQConnector(**rabbit_config) try: rabbit.open_connection() rabbit.declare_queue(RABBIT_QUEUE) json_notification = { 'notification_subject': notification_subject, 'notification_action': notification_action, 'content_url': url, 'content_title': content_title, 'actor': actor, 'path': path, 'tags': tags, 'events': related_action, } message = json.dumps(json_notification) rabbit.send_message(RABBIT_QUEUE, message) except Exception: LOGGER.error( "RabbitMQ connection problem. " "Check client configuration: /@@rabbitmq-client-controlpanel." " See example in documentation.")
def get_revision_history(self): """Return the revision history of the current context """ chv = ContentHistoryView(self.context, self.request) return chv.revisionHistory()
def content_history(self): h = ContentHistoryView(self.context, self.request).fullHistory() return h or []
def getHistory(context): """ get history for a certain object. """ return ContentHistoryView(context, context.REQUEST).fullHistory()