def send_connect_mail(user, provider, request): data = get_common_mail_context(request) data.update({ 'user': user, 'provider': provider }) subj_user = render_to_string('cosinnus_oauth_client/mail/notification_after_oauth_account_connect.txt', data) text = textfield(render_to_string('cosinnus_oauth_client/mail/notification_after_oauth_account_connect.html', data)) send_html_mail_threaded(user, subj_user, text)
def send_welcome_mail(self, user, request): data = get_common_mail_context(request) provider = self.sociallogin.account.provider data.update({'user': user, 'provider': provider}) subj_user = render_to_string( 'cosinnus_oauth_client/mail/welcome_after_oauth_signup_subj.txt', data) text = textfield( render_to_string( 'cosinnus_oauth_client/mail/welcome_after_oauth_signup.html', data)) send_html_mail_threaded(user, subj_user, text)
def _send_user_welcome_email_if_enabled(user, force=False): """ If welcome email sending is enabled for this portal, send one out to the given user """ # if a welcome email text is set in the portal in admin portal = CosinnusPortal.get_current() if not portal.welcome_email_active and not force: return text = portal.welcome_email_text.strip() if portal.welcome_email_text else '' if not force and (not text or not user): return # render the text as markdown text = textfield(text) subj_user = _('Welcome to %(portal_name)s!') % {'portal_name': portal.name} send_html_mail_threaded(user, subj_user, text)
def send_testmail(request): if request and not request.user.is_superuser: return HttpResponseForbidden('Not authenticated') mode = request.GET.get('mode', None) if mode not in ['html', 'direct', 'direct_html', 'threaded', 'override']: mode = 'html' subject = mode + ': Testmail from Housekeeping at %s' % str(now()) template = 'cosinnus/common/internet_explorer_not_supported.html' retmsg = '\n\n<br><br> Use ?mode=[html, direct, direct_html, threaded, override]\n\nThe Answer was: ' if mode == 'html': retmsg += force_text( send_html_mail_threaded( request.user, subject, textfield('This is a test mail from housekeeping.'))) return HttpResponse('Sent mail using html mode. ' + retmsg) if mode == 'direct': retmsg += force_text( send_mail(request.user.email, subject, template, {})) return HttpResponse('Sent mail using direct mode. ' + retmsg) if mode == 'direct_html': template = 'cosinnus/housekeeping/test_html_mail.html' retmsg += force_text( send_mail(request.user.email, subject, template, {}, is_html=True)) return HttpResponse('Sent mail using direct HTML mode. ' + retmsg) if mode == 'threaded': retmsg += force_text( send_mail_or_fail_threaded(request.user.email, subject, template, {})) return HttpResponse('Sent mail using threaded mode. ' + retmsg) if mode == 'override': retmsg += force_text( EmailMessage(subject, 'No content', 'Testing <%s>' % settings.COSINNUS_DEFAULT_FROM_EMAIL, [request.user.email]).send()) return HttpResponse('Sent mail using override mode. ' + retmsg) return HttpResponse('Did not send any mail. ' + retmsg)
def __init__(self, result, user=None, *args, **kwargs): if result.portals: # some results, like users, have multiple portals associated. we select one of those to show # the origin from visible_portals = get_visible_portal_ids() displayable_portals = [port_id for port_id in result.portals if port_id in visible_portals] current_portal_id = CosinnusPortal.get_current().id portal = current_portal_id if ((not displayable_portals) or current_portal_id in displayable_portals) else displayable_portals[0] else: portal = result.portal fields = { 'id': itemid_from_searchresult(result), 'type': SEARCH_MODEL_NAMES[result.model], 'title': result.title, 'slug': result.slug, 'lat': result.mt_location_lat, 'lon': result.mt_location_lon, 'address': result.mt_location, 'url': result.url, 'iconImageUrl': result.icon_image_url, 'backgroundImageSmallUrl': result.background_image_small_url, 'backgroundImageLargeUrl': result.background_image_large_url, 'description': textfield(result.description), 'relevance': result.score, 'topics': result.mt_topics, 'portal': portal, 'group_slug': result.group_slug, 'group_name': result.group_name, 'participant_count': result.participant_count, 'member_count': result.member_count, 'content_count': result.content_count, 'liked': user.id in result.liked_user_ids if (user and getattr(result, 'liked_user_ids', [])) else False, } fields.update(**kwargs) return super(HaystackMapResult, self).__init__(*args, **fields)
def print_testmail(request): """ Displays a HTML email like it would be sent to a user """ if request and not request.user.is_superuser: return HttpResponseForbidden('Not authenticated') subject = 'This is a test mail' content_html = textfield( "Detailed testmail test content cannot be shown without a forum group." ) forum_slug = getattr(settings, 'NEWW_FORUM_GROUP_SLUG', None) if forum_slug: from cosinnus_notifications.models import NotificationEvent # noqa from cosinnus_note.models import Note, Comment # noqa from cosinnus_notifications.notifications import render_digest_item_for_notification_event forum = get_object_or_None(get_cosinnus_group_model(), slug=forum_slug, portal=CosinnusPortal.get_current()) notes = Note.objects.filter(group=forum) if notes.count() > 0: note = notes[0] comment = Comment(creator=request.user, text="This is a test comment.", note=note) notification_event = NotificationEvent() notification_event._target_object = comment notification_event.group = forum notification_event.notification_id = 'note__note_comment_posted_on_any' notification_event.user = request.user content_html = render_digest_item_for_notification_event( notification_event) html = render_notification_item_html_mail(request.user, subject, content_html) return HttpResponse(html)
def get_description_html(self, obj): return textfield(obj.description)
def get_note_html(self, obj): return textfield(obj.note)