def start(self, context, request, appstruct, **kw): from ..proposal_management.behaviors import exclude_participant_from_wg root = getSite() context.state.remove('active') context.state.append('deactivated') context.set_organization(None) proposals = getattr(context, 'participations', []) anonymous_proposals = getattr(context.mask, 'participations', []) for proposal in proposals: exclude_participant_from_wg(proposal, request, context, root) for proposal in anonymous_proposals: exclude_participant_from_wg(proposal, request, context.mask, root) context.modified_at = datetime.datetime.now(tz=pytz.UTC) context.reindex() pref_author = list(get_users_by_preferences(context)) alert('internal', [request.root], pref_author, internal_kind=InternalAlertKind.content_alert, subjects=[context], alert_kind='user_deactivated') request.registry.notify( ActivityExecuted(self, [context], get_current())) return {}
def start(self, context, request, appstruct, **kw): from ..proposal_management.behaviors import exclude_participant_from_wg root = getSite() context.state.remove('active') context.state.append('deactivated') context.set_organization(None) proposals = getattr(context, 'participations', []) anonymous_proposals = getattr(context.mask, 'participations', []) for proposal in proposals: exclude_participant_from_wg( proposal, request, context, root) for proposal in anonymous_proposals: exclude_participant_from_wg( proposal, request, context.mask, root) context.modified_at = datetime.datetime.now(tz=pytz.UTC) context.reindex() pref_author = list(get_users_by_preferences(context)) alert('internal', [request.root], pref_author, internal_kind=InternalAlertKind.content_alert, subjects=[context], alert_kind='user_deactivated') request.registry.notify(ActivityExecuted( self, [context], get_current())) return {}
def _get_users_to_alerts(self, context, request): #@TODO OPTIMIZATION author = getattr(context, 'author', None) users = list(get_users_by_preferences(context)) if author not in users: users.append(author) return users
def _get_users_to_alerts(self, context, request): #@TODO OPTIMIZATION author = getattr(context, 'author', None) users = list(get_users_by_preferences(context)) if author not in users: users.append(author) return users
def update_len_selections(root, registry): from novaideo.views.filter import find_entities, get_users_by_preferences from novaideo.content.interface import ISearchableEntity import transaction contents = find_entities(interfaces=[ISearchableEntity]) len_entities = str(len(contents)) for index, content in enumerate(contents): result = get_users_by_preferences(content) content.len_selections = len(result) if index % 1000 == 0: log.info("**** Commit ****") transaction.commit() log.info(str(index) + "/" + len_entities) log.info('Len comments updated')
def start(self, context, request, appstruct, **kw): appstruct.pop('_csrf_token_') context.opinion = PersistentDict(appstruct) context.state = PersistentList( ['examined', 'published', context.opinion['opinion']]) context.init_examined_at() context.remove_tokens() context.reindex() member = context.author root = getSite() users = list(get_users_by_preferences(context)) users.append(member) alert( 'internal', [root], users, internal_kind=InternalAlertKind.examination_alert, subjects=[context]) # Add Nia comment alert_comment_nia( context, request, root, internal_kind=InternalAlertKind.examination_alert, subject_type='idea' ) if getattr(member, 'email', ''): mail_template = root.get_mail_template( 'opinion_idea', member.user_locale) subject = mail_template['subject'].format( subject_title=context.title) localizer = request.localizer email_data = get_user_data(member, 'recipient', request) email_data.update(get_entity_data(context, 'subject', request)) message = mail_template['template'].format( opinion=localizer.translate(_(context.opinion_value)), explanation=context.opinion['explanation'], novaideo_title=root.title, **email_data ) alert('email', [root.get_site_sender()], [member.email], subject=subject, body=message) request.registry.notify(ActivityExecuted( self, [context], get_current(request))) return {}
def mysubscriber_object_modified(event): content = event.object args = event.args state_source = args.get('state_source', '') state_target = args.get('state_target', '') request = get_current_request() users = get_users_by_preferences(content) root = request.root localizer = request.localizer subject_data = get_entity_data(content, 'subject', request) all_users = [] for member in users: all_users.append(member) if getattr(member, 'email', ''): mail_template = root.get_mail_template('alert_content_modified', member.user_locale) subject = mail_template['subject'].format(**subject_data) state_source_translate = state_source state_target_translate = state_target if state_source: state_source_translate = localizer.translate( get_states_mapping(member, content, state_source)) if state_target: state_target_translate = localizer.translate( get_states_mapping(member, content, state_target)) email_data = get_user_data(member, 'recipient', request) email_data.update(subject_data) message = mail_template['template'].format( state_source=state_source_translate, state_target=state_target_translate, novaideo_title=root.title, **email_data) alert('email', [root.get_site_sender()], [member.email], subject=subject, body=message) alert('internal', [root], all_users, internal_kind=InternalAlertKind.content_alert, subjects=[content], alert_kind='modified')
def mysubscriber_object_published(event): content = event.object author = getattr(content, 'author', None) tree = content.tree request = get_current_request() root = request.root challenge = getattr(content, 'challenge', None) query = None challeng_followers = [] if getattr(challenge, 'is_restricted', False): novaideo_catalog = find_catalog('novaideo') challenges_index = novaideo_catalog['challenges'] query = challenges_index.any([get_oid(challenge)]) elif challenge: challeng_followers = get_users_by_preferences(challenge) alert('internal', [root], set(challeng_followers), internal_kind=InternalAlertKind.content_alert, subjects=[content], alert_kind='published_in_challenge') users = get_users_by_keywords(tree, query) subject_data = get_entity_data(content, 'subject', request) all_users = [] for member in users: all_users.append(member) if getattr(member, 'email', '') and author is not member: mail_template = root.get_mail_template('alert_new_content', member.user_locale) subject = mail_template['subject'].format(**subject_data) email_data = get_user_data(member, 'recipient', request) email_data.update(subject_data) message = mail_template['template'].format( novaideo_title=root.title, **email_data) alert('email', [root.get_site_sender()], [member.email], subject=subject, body=message) if author in all_users: all_users.remove(author) alert('internal', [root], set(all_users), internal_kind=InternalAlertKind.content_alert, subjects=[content], alert_kind='published') pref_author = get_users_by_preferences(author) all_users = [u for u in pref_author if u not in set(all_users)] alert('internal', [root], all_users, internal_kind=InternalAlertKind.content_alert, subjects=[content], alert_kind='published_author', member_url=request.resource_url(author, '@@index'), member_title=getattr(author, 'title', author.__name__)) if getattr(content, 'original', None): original = content.original users = list(get_users_by_preferences(original)) users.append(original.author) alert('internal', [root], set(users), internal_kind=InternalAlertKind.content_alert, subjects=[content], alert_kind='duplicated', url=request.resource_url(original, '@@index'), duplicate_title=original.title)