def handle_update_evaluations(self, action): """ update list of evaluators in objects pending for review. """ # code from upgrades.py brains = api.content.find(object_provides=IEvaluable, review_state='pending') evaluators = [i.id for i in api.user.get_users(groupname='evaluators')] for evaluable in brains: obj = evaluable.getObject() evaluations = IEvaluation(obj).evaluations inactive = [i for i in evaluations if i not in evaluators] for userid in inactive: api.user.revoke_roles(username=userid, roles=['Reader'], obj=obj) evaluations.pop(userid) logger.info('remove {} from evaluators'.format(userid)) for userid in evaluators: if userid not in evaluations: evaluations[userid] = PersistentList() api.user.grant_roles(username=userid, roles=['Reader'], obj=obj) logger.info('Adding {} to {}'.format( userid, evaluable.Title.encode('utf-8'))) logger.info('{} has {} evaluators'.format( evaluable.Title.encode('utf-8'), len(evaluations)))
def upgrade_evaluators(setup): # objects already studied brains = api.content.find(object_provides=IEvaluable, review_state='studied') for evaluable in brains: evaluations = IEvaluation(evaluable.getObject()).evaluations for user in api.user.get_users(): if user.id not in evaluations and user.id != 'erendira': evaluations[user.id] = PersistentList() logger.info('Adding {} to {}'.format( user.id, brains[0].Title.encode('utf-8'))) logger.info('{} has {} evaluators'.format( brains[0].Title.encode('utf-8'), len(evaluations))) # objects to be studied brains = api.content.find(object_provides=IEvaluable, review_state='pending') for evaluable in brains: evaluations = IEvaluation(evaluable.getObject()).evaluations for user in api.user.get_users(groupname='evaluators'): if user.id not in evaluations: evaluations[user.id] = PersistentList() logger.info('Adding {} to {}'.format( user.id, brains[0].Title.encode('utf-8'))) logger.info('{} has {} evaluators'.format( brains[0].Title.encode('utf-8'), len(evaluations)))
def update(self): super(Evaluation, self).update() if self.evaluation is None: self.evaluation = IEvaluation(self.context) if self.is_manager is None: self.is_manager = api.user.has_permission( ViewManagementScreens, user=api.user.get_current(), obj=self.context) if self.userid is None: self.userid = api.user.get_current().getId()
def handle_update_evaluations(self, action): """This method is meant to be used only once """ # code from upgrades.py brains = api.content.find(object_provides=IEvaluable) for brain in brains: obj = brain.getObject() evaluations = IEvaluation(obj).evaluations for xid in evaluations.keys(): api.user.grant_roles(username=xid, roles=['Reader'], obj=obj) api.content.disable_roles_acquisition(obj=obj) api.group.grant_roles(groupname='Reviewers', roles=['Reader'], obj=obj) logger.info('listo')
class Evaluation(base.ViewletBase): evaluation = None is_manager = None userid = None def update(self): super(Evaluation, self).update() if self.evaluation is None: self.evaluation = IEvaluation(self.context) if self.is_manager is None: self.is_manager = api.user.has_permission( ViewManagementScreens, user=api.user.get_current(), obj=self.context) if self.userid is None: self.userid = api.user.get_current().getId() def evaluated(self): return self.evaluation.already_evaluated(self.userid) def evaluationvalue(self): if not self.evaluation.already_evaluated(self.userid): return None return self.evaluation.evaluations[self.userid][0]['evaluation'] def allevaluations(self): """Every evaluotion object supose to have the evaluators ids as values in the Anotation dict """ allevaluations = self.evaluation.evaluations evaluators = [] for userid in allevaluations: value = None member = api.user.get(userid) if allevaluations[userid]: value = allevaluations[userid][0]['evaluation'] evaluators.append((member.getProperty('fullname'), value)) evaluators.sort() return evaluators
def evaluations(self, brain): evaluations = IEvaluation(brain.getObject()).evaluations evaluators = [] isManager = self.isManager() userid = api.user.get_current().id for xid in sorted(evaluations.keys()): member = api.user.get(username=xid) if isManager: member_evaluations = evaluations.get(member.id, None) value = member_evaluations and member_evaluations[0][ 'evaluation'] evaluators.append( (member.getProperty('fullname'), value, member.id)) elif userid == member.id: member_evaluations = evaluations.get(member.id, None) value = member_evaluations and member_evaluations[0][ 'evaluation'] evaluators.append( (member.getProperty('fullname'), value, member.id)) break return evaluators
def send_email(self): catalog = api.portal.get_tool(name='portal_catalog') brains = catalog(path=dict(query='/'.join( self.context.getPhysicalPath()), depth=1), review_state='pending', sort_on='evaluation_date') evaluators = api.user.get_users(groupname='evaluators') emails = {} for brain in brains: values = IEvaluation(brain.getObject()).evaluations for gmember in evaluators: if values.get(gmember.id, None) is None: emails.setdefault(gmember.id, []) emails[gmember.id].append((brain.Title, brain.getURL())) evaluators_data = {} for evaluator in evaluators: evaluators_data[evaluator.id] = { 'name': evaluator.getProperty('fullname'), 'email': evaluator.getProperty('email'), } message = [] for k, v in emails.iteritems(): salutation = _( u'email_intro_msg', default=u'Dear ${name}', mapping={u'name': safe_unicode(evaluators_data[k]['name'])}) if len(v) > 1: mail_intro = _(u'You have the following pending reviews:') else: mail_intro = _(u'you have the following pending review:') mail_cases = u'\n'.join( [i[0] + u' ' + safe_unicode(i[1]) for i in v]) mail_sign = u'Asuntos Académicos\nInstituto de Matemáticas, UNAM' salutation = self.context.translate(salutation) mail_intro = self.context.translate(mail_intro) mail_text = '\n'.join([ salutation, mail_intro, u'\n', mail_cases, u'\n\n', mail_sign ]) mail_subject = self.context.translate( _(u'Pending reviews, IM UNAM')) try: api.portal.send_email( recipient=evaluators_data[k]['email'], sender='*****@*****.**', subject=mail_subject, body=mail_text, ) message.append(evaluators_data[k]['email']) except SMTPRecipientsRefused: # Don't disclose email address on failure raise SMTPRecipientsRefused( 'Recipient address rejected by server') IStatusMessage(self.request).addStatusMessage( self.context.translate(_(u'The system sended email to: ')) + ', '.join(message), 'info') return True
def __call__(self, rating): evaluation = IEvaluation(self.context) evaluation.clear() return 'success'
def __call__(self, rating): evaluation = IEvaluation(self.context) current = api.user.get_current() evaluation.evaluate(rating, current.getId()) return 'success'