def item_history_info(self, item): obj = item.getObject() chv = ContentHistoryView(obj, obj.REQUEST) history = chv.fullHistory() if history is not None: return history[0] else: obj_history = {'time': obj.modified, 'actor': obj.Creator} return obj_history
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 history_info(self): context = aq_inner(self.context) recent = self.recent_items() if len(recent) > 0: obj = recent[0].getObject() if (IItemRepository.providedBy(context) or IOrderableItem.providedBy(context) or IOrderableItem.providedBy(obj)): history = {'time': obj.modified} else: chv = ContentHistoryView(obj, obj.REQUEST) history_list = chv.fullHistory() history = history_list[0] return history
def previous_submitter(self): # Get the history data history_view = ContentHistoryView(self.context, self.request) workflow_history = history_view.workflowHistory() # Pull the people who submitted this people = [x.get('actor', {}).get('username', None) for x in workflow_history if x.get('action', '') == 'submit'] # Filter empties people = [x for x in people if x] # Return the most recent one, if we have people if people: return people[0]
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 __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 gethistory(self): context = self.context HistoryView = ContentHistoryView(context, context.REQUEST) content_history = HistoryView.fullHistory() or [] L = [] for history in content_history: tipo = history.get('type','') if tipo == 'workflow': date = history.get('time','').strftime('%d/%m/%Y') else: date = datetime.fromtimestamp(history.get('time','')).strftime('%d/%m/%Y') actor = history.get('actor',{}) if actor: actor = actor.get('username','') if actor: actor = self.get_prefs_user(actor) if actor: L.append({'actor': actor.get('name',''), # 'action': history.get('transition_title',''), # 'type': tipo, 'date':date,}) return L
def get_revision_history(self): """Return the revision history of the current context """ chv = ContentHistoryView(self.context, self.request) return chv.revisionHistory()
def gethistory(self): context = self.context HistoryView = ContentHistoryView(context, context.REQUEST) return HistoryView.fullHistory()
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()
def update(self): D = {} portal_workflow = getToolByName(self.context, "portal_workflow") reference_catalog = getToolByName(self.context, "reference_catalog") portal_membership = getToolByName(self.context, "portal_membership") uid = self.request.form.get('uid','') user_admin = portal_membership.getMemberById('admin') # stash the existing security manager so we can restore it old_security_manager = getSecurityManager() #usuario temporario para o tipo de conteudo ATFILE, que não tem History username_logged = "XXusertmpXX" # create a new context, as the owner of the folder newSecurityManager(self.request,user_admin) context = reference_catalog.lookupObject(uid) if context: HistoryView = ContentHistoryView(context, context.REQUEST) try:context_owner = context.getOwner().getUserName() except:context_owner = 'administrador' image_content = '' if hasattr(context, 'getImageIcone'): img = context.getImageIcone() image_content = img.replace(self.context.absolute_url(),'') try: status = portal_workflow.getInfoFor(context, 'review_state') except WorkflowException: status = 'no workflow' content_history = HistoryView.fullHistory() or [] L = [] for history in content_history: tipo = history.get('type','') if tipo == 'workflow': date = history.get('time','').strftime('%Y-%m-%d %H:%M:%S') else: date = datetime.fromtimestamp(history.get('time','')).strftime('%Y-%m-%d %H:%M:%S') actor = history.get('actor',{}) if not actor: actor = '' L.append({'actor': actor, 'action': history.get('transition_title',''), 'type': tipo, 'date':date,}) if context.portal_type == 'File': D['history'] = [{'actor': username_logged, 'action': 'Edited', 'type': context.portal_type, 'date':context.bobobase_modification_time().strftime('%Y-%m-%d %H:%M:%S'),}] else: D['history'] = L D['details'] = {'uid': context.UID(), 'type': context.portal_type, 'title': context.Title(), 'description':context.Description(), 'owner': context_owner, 'date_created':context.creation_date.strftime('%Y-%m-%d %H:%M:%S'), 'date_modified':context.bobobase_modification_time().strftime('%Y-%m-%d %H:%M:%S'), 'workflow': status, 'url': '/'+'/'.join(context.getPhysicalPath()[2:]), 'image': image_content} excludeField = ['title','description','blogger_bio','blogger_name','blog_entry', 'location', 'language'] typesField = ['string','text','lines','boolean','datetime','reference'] extra_details = {} for field in context.Schema().fields(): if not field.getName() in excludeField and\ field.type in typesField and\ field.accessor: accessor = getattr(context, field.accessor) if accessor: accessor = accessor() if isinstance(accessor, (tuple, list)): accessor = str(list(accessor)) elif isinstance(accessor, bool): accessor = str(accessor) elif isinstance(accessor, (datetime, DateTime)): accessor = accessor.strftime('%d/%m/%Y %H:%M:%S') elif field.type == 'reference': if accessor: accessor = accessor.UID() if isinstance(accessor, str) or isinstance(accessor, unicode): extra_details[field.getName()] = accessor D['extra_details'] = extra_details else: D['deleted'] = True # restore the original context setSecurityManager(old_security_manager) self.retorno = D