def render_contribution_list(self): """Render the contribution list template components. :return: dict containing the list's entries, the fragment of displayed entries and whether the contribution passed is displayed in the results. """ contrib_list_kwargs = self.get_list_kwargs() total_entries = contrib_list_kwargs.pop('total_entries') contribs = contrib_list_kwargs['contribs'] tpl = get_template_module('events/contributions/display/_contribution_list.html') tpl_lists = get_template_module('events/management/_lists.html') return {'html': tpl.render_contribution_list(self.event, self.event.display_tzinfo, contribs, total_entries), 'counter': tpl_lists.render_displayed_entries_fragment(len(contribs), total_entries)}
def notify_event_creation(event, occurrences=None): """Send email notifications when a new Event is created :param event: The `Event` that has been created. :param occurrences: A list of event occurrences in case of a series of events. If specified, the links and dates/times are only taken from the events in this list. """ emails = set() query = (event.category.chain_query. filter(Category.notify_managers | (Category.event_creation_notification_emails != [])) .options(joinedload('acl_entries'))) for cat in query: emails.update(cat.event_creation_notification_emails) if cat.notify_managers: for manager in cat.get_manager_list(): if manager.is_single_person: emails.add(manager.email) elif manager.is_group: emails.update(x.email for x in manager.get_members()) if emails: template = get_template_module('events/emails/event_creation.txt', event=event, occurrences=occurrences) send_email(make_email(bcc_list=emails, template=template))
def render_event_management_header_right(event): tpl = get_template_module('events/management/_management_frame.html') return tpl.render_event_management_header_right(event=event, event_types=[ (et.name, et.title) for et in EventType ])
def _process(self): tpl = get_template_module( 'events/registration/emails/invitation_default.html', event=self.event) form_cls = InvitationFormExisting if request.args.get( 'existing') == '1' else InvitationFormNew defaults = FormDefaults(email_body=tpl.get_html_body(), email_subject=tpl.get_subject()) form = form_cls(obj=defaults, regform=self.regform) skip_moderation = form.skip_moderation.data if 'skip_moderation' in form else False if form.validate_on_submit(): for user in form.users.data: self._create_invitation(user, skip_moderation, form.email_from.data, form.email_subject.data, form.email_body.data) num = len(form.users.data) flash( ngettext("The invitation has been sent.", "{n} invitations have been sent.", num).format(n=num), 'success') return jsonify_data( invitation_list=_render_invitation_list(self.regform)) return jsonify_template( 'events/registration/management/regform_invite.html', regform=self.regform, form=form)
def _render_template_list(target, event=None): tpl = get_template_module('designer/_list.html') default_template = get_default_template_on_category(target) if isinstance(target, Category) else None not_deletable = get_not_deletable_templates(target) return tpl.render_template_list(target.designer_templates, target, event=event, default_template=default_template, inherited_templates=get_inherited_templates(target), not_deletable_templates=not_deletable)
def _process(self): users = [User.get(int(id_)) for id_ in request.form.getlist('user_id')] self.user.favorite_users |= set(filter(None, users)) tpl = get_template_module('users/_favorites.html') return jsonify(success=True, users=[serialize_user(user) for user in users], html=tpl.favorite_users_list(self.user))
def _process(self): db.session.delete(self.request) tpl = get_template_module( 'users/emails/registration_request_rejected.txt', req=self.request) send_email(make_email(self.request.email, template=tpl)) flash(_('The request has been rejected.'), 'success') return jsonify_data()
def get_email_body_template(cls, event, **kwargs): """Returns the template of the email body for this agreement definition""" template_name = cls.email_body_template_name or 'emails/agreement_default_body.html' template_path = get_overridable_template_name(template_name, cls.plugin, 'events/agreements/') return get_template_module(template_path, event=event)
def _notify_registration(registration, template, to_managers=False): from fossir.modules.events.registration.util import get_ticket_attachments attachments = None regform = registration.registration_form tickets_handled = values_from_signal( signals.event.is_ticketing_handled.send(regform), single_value=True) if (not to_managers and regform.tickets_enabled and regform.ticket_on_email and not any(tickets_handled) and registration.state == RegistrationState.complete): attachments = get_ticket_attachments(registration) template = get_template_module( 'events/registration/emails/{}'.format(template), registration=registration) to_list = registration.email if not to_managers else registration.registration_form.manager_notification_recipients from_address = registration.registration_form.sender_address if not to_managers else None mail = make_email(to_list=to_list, template=template, html=True, from_address=from_address, attachments=attachments) send_email(mail, event=registration.registration_form.event, module='Registration', user=session.user)
def get_base_ical_parameters(user, detail, path, params=None): """Returns a dict of all parameters expected by iCal template""" from fossir.web.http_api.util import generate_public_auth_request api_mode = api_settings.get('security_mode') persistent_allowed = api_settings.get('allow_persistent') api_key = user.api_key if user else None persistent_user_enabled = api_key.is_persistent_allowed if api_key else None tpl = get_template_module('api/_messages.html') persistent_agreement = tpl.get_ical_persistent_msg() top_urls = generate_public_auth_request(api_key, path, params) urls = generate_public_auth_request(api_key, path, dict(params or {}, detail=detail)) request_urls = { 'publicRequestURL': top_urls['publicRequestURL'], 'authRequestURL': top_urls['authRequestURL'], 'publicRequestDetailedURL': urls['publicRequestURL'], 'authRequestDetailedURL': urls['authRequestURL'] } return { 'api_mode': api_mode, 'api_key': api_key, 'persistent_allowed': persistent_allowed, 'persistent_user_enabled': persistent_user_enabled, 'api_active': api_key is not None, 'api_key_user_agreement': tpl.get_ical_api_key_msg(), 'api_persistent_user_agreement': persistent_agreement, 'user_logged': user is not None, 'request_urls': request_urls }
def _process(self): form = build_review_form(review=self.review) if form.validate_on_submit(): update_review(self.review, **form.split_data) return jsonify_data(flash=False, html=render_paper_page(self.paper)) tpl = get_template_module('events/reviews/forms.html') return jsonify(html=tpl.render_review_form(form, review=self.review))
def _process(self): form = EventPersonForm(obj=FormDefaults(self.person, skip_attrs={'title'}, title=self.person._title)) if form.validate_on_submit(): update_person(self.person, form.data) person_data = self.get_persons()[self.person.email or self.person.id] tpl = get_template_module('events/persons/management/_person_list_row.html') return jsonify_data(html=tpl.render_person_row(person_data)) return jsonify_form(form)
def _process(self): events_by_month = self.group_by_month(self.events) tpl = get_template_module('categories/display/event_list.html') html = tpl.event_list_block(events_by_month=events_by_month, format_event_date=self.format_event_date, is_recent=self.is_recent, happening_now=self.happening_now) return jsonify_data(flash=False, html=html)
def _render_questionnaire_preview(survey): # load the survey once again with all the necessary data survey = (Survey.find(id=survey.id).options( joinedload(Survey.sections).joinedload(SurveySection.children)).one()) tpl = get_template_module( 'events/surveys/management/_questionnaire_preview.html') form = make_survey_form(survey)() return tpl.render_questionnaire_preview(survey, form, get_field_types())
def _registered(user, identity, from_moderation, **kwargs): from fossir.modules.users.util import get_admin_emails if (from_moderation or identity is None or identity.provider != 'fossir' or not user_management_settings.get('notify_account_creation')): return tpl = get_template_module('users/emails/profile_registered_admins.txt', user=user) send_email(make_email(get_admin_emails(), template=tpl))
def render_session_timetable(session, timetable_layout=None, management=False): if not session.start_dt: # no scheduled sessions present return '' timetable_data = TimetableSerializer(session.event).serialize_session_timetable(session, without_blocks=True, strip_empty_days=True) event_info = serialize_event_info(session.event) tpl = get_template_module('events/timetable/_timetable.html') return tpl.render_timetable(timetable_data, event_info, timetable_layout=timetable_layout, management=management)
def notify_static_site_success(static_site): template = get_template_module( 'events/static/emails/download_notification_email.txt', user=static_site.creator, event=static_site.event, link=url_for('static_site.download', static_site, _external=True)) return make_email({static_site.creator.email}, template=template, html=False)
def render_list(self): reg_list_kwargs = self.get_list_kwargs() tpl = get_template_module( 'events/registration/management/_reglist.html') filtering_enabled = reg_list_kwargs.pop('filtering_enabled') return { 'html': tpl.render_registration_list(**reg_list_kwargs), 'filtering_enabled': filtering_enabled }
def render_list(self, abstract=None): list_kwargs = self.get_list_kwargs() tpl = get_template_module( 'events/abstracts/management/_abstract_list.html') filtering_enabled = list_kwargs.pop('filtering_enabled') tpl_lists = get_template_module('events/management/_lists.html') filter_statistics = tpl_lists.render_displayed_entries_fragment( len(list_kwargs['abstracts']), list_kwargs['total_abstracts']) return { 'html': tpl.render_abstract_list(**list_kwargs), 'filtering_enabled': filtering_enabled, 'filter_statistics': filter_statistics, 'hide_abstract': abstract not in list_kwargs['abstracts'] if abstract else None }
def send_submission_notification(self, submission): if not self.notifications_enabled: return template_module = get_template_module( 'events/surveys/emails/new_submission_email.txt', submission=submission) email = make_email(bcc_list=self.new_submission_emails, template=template_module) send_email(email, event=self.event, module='Surveys') logger.info('Sending submission notification for survey %s', self)
def notify_deleted(plugin, room, room_assoc, event, user): """Notifies about the deletion of a vc_room from the system. :param room: the vc_room :param event: the event :param user: the user performing the action """ name = get_overridable_template_name('emails/deleted.html', plugin, core_prefix='vc/') tpl = get_template_module(name, plugin=plugin, vc_room=room, event=event, vc_room_event=room_assoc, user=user) _send('delete', user, plugin, event, room, tpl)
def _send_confirmation(email, salt, endpoint, template, template_args=None, url_args=None, data=None): template_args = template_args or {} url_args = url_args or {} token = secure_serializer.dumps(data or email, salt=salt) url = url_for(endpoint, token=token, _external=True, **url_args) template_module = get_template_module(template, email=email, url=url, **template_args) send_email(make_email(email, template=template_module)) flash(_('We have sent you a verification email. Please check your mailbox within the next hour and open ' 'the link in that email.')) return redirect(url_for(endpoint, **url_args))
def _process(self): form = build_review_form(self.paper.last_revision, self.type) if form.validate_on_submit(): create_review(self.paper, self.type, session.user, **form.split_data) return jsonify_data(flash=False, html=render_paper_page(self.paper)) tpl = get_template_module('events/reviews/forms.html') return jsonify(html=tpl.render_review_form( form, proposal=self.paper, group=self.type))
def _process(self): form = PaperCommentForm(paper=self.paper, user=session.user) if form.validate_on_submit(): visibility = form.visibility.data if form.visibility else None create_comment(self.paper, form.text.data, visibility, session.user) return jsonify_data(flash=False, html=render_paper_page(self.paper)) tpl = get_template_module('events/reviews/forms.html') return jsonify(html=tpl.render_comment_form(form, proposal=self.paper))
def _process(self): form = AbstractCommentForm(abstract=self.abstract, user=session.user) if form.validate_on_submit(): create_abstract_comment(self.abstract, form.data) return jsonify_data(flash=False, html=render_abstract_page( self.abstract, management=self.management)) tpl = get_template_module('events/reviews/forms.html') return jsonify( html=tpl.render_comment_form(form, proposal=self.abstract))
def get_notification_template(cls, name, **context): """Gets the template module for a notification email :param name: the template name :param context: data passed to the template """ tpl = get_overridable_template_name(name, cls.plugin, 'events/requests/emails/', 'emails/') return get_template_module(tpl, **context)
def send_start_notification(self): if not self.notifications_enabled or self.start_notification_sent or not self.event.has_feature( 'surveys'): return template_module = get_template_module( 'events/surveys/emails/start_notification_email.txt', survey=self) email = make_email(bcc_list=self.start_notification_recipients, template=template_module) send_email(email, event=self.event, module='Surveys') logger.info('Sending start notification for survey %s', self) self.start_notification_sent = True
def _process(self): user, identity = register_user(self.request.email, self.request.extra_emails, self.request.user_data, self.request.identity_data, self.request.settings) tpl = get_template_module( 'users/emails/registration_request_accepted.txt', user=user) send_email(make_email(self.request.email, template=tpl)) flash(_('The request has been approved.'), 'success') return jsonify_data()
def _process(self): form = build_review_form(self.abstract, self.track) if form.validate_on_submit(): create_abstract_review(self.abstract, self.track, session.user, **form.split_data) return jsonify_data(flash=False, html=render_abstract_page( self.abstract, management=self.management)) tpl = get_template_module('events/reviews/forms.html') return jsonify(html=tpl.render_review_form( form, proposal=self.abstract, group=self.track))
def make_reminder_email(event, with_agenda, note): """Returns the template module for the reminder email. :param event: The event :param with_agenda: If the event's agenda should be included :param note: A custom message to include in the email """ if event.type_ == EventType.lecture: with_agenda = False return get_template_module('events/reminders/emails/event_reminder.txt', event=event, url=event.short_external_url, note=note, with_agenda=with_agenda, agenda=event.timetable_entries.filter_by(parent_id=None))