本文整理汇总了Python中seahub.utils.send_html_email函数的典型用法代码示例。如果您正苦于以下问题:Python send_html_email函数的具体用法?Python send_html_email怎么用?Python send_html_email使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了send_html_email函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: email_user_on_activation
def email_user_on_activation(user):
"""Send an email to user when admin activate his/her account.
"""
c = {
'username': user.email,
}
send_html_email(_(u'Your account on %s is activated') % SITE_NAME,
'sysadmin/user_activation_email.html', c, None, [user.email])
开发者ID:Neurones67,项目名称:seahub,代码行数:8,代码来源:sysadmin.py
示例2: send_shared_upload_link
def send_shared_upload_link(request):
"""
Handle ajax post request to send shared upload link.
"""
if not request.method == 'POST':
raise Http404
content_type = 'application/json; charset=utf-8'
if not IS_EMAIL_CONFIGURED:
data = json.dumps({'error':_(u'Sending shared upload link failed. Email service is not properly configured, please contact administrator.')})
return HttpResponse(data, status=500, content_type=content_type)
from seahub.settings import SITE_NAME
form = UploadLinkShareForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
shared_upload_link = form.cleaned_data['shared_upload_link']
extra_msg = escape(form.cleaned_data['extra_msg'])
to_email_list = string2list(email)
for to_email in to_email_list:
# Add email to contacts.
mail_sended.send(sender=None, user=request.user.username,
email=to_email)
c = {
'email': request.user.username,
'to_email': to_email,
'shared_upload_link': shared_upload_link,
}
if extra_msg:
c['extra_msg'] = extra_msg
if REPLACE_FROM_EMAIL:
from_email = request.user.username
else:
from_email = None # use default from email
if ADD_REPLY_TO_HEADER:
reply_to = request.user.username
else:
reply_to = None
try:
send_html_email(_(u'An upload link is shared to you on %s') % SITE_NAME,
'shared_upload_link_email.html',
c, from_email, [to_email],
reply_to=reply_to)
except Exception, e:
logger.error(str(e))
data = json.dumps({'error':_(u'Internal server error. Send failed.')})
return HttpResponse(data, status=500, content_type=content_type)
data = json.dumps({"msg": _(u'Successfully sent.')})
return HttpResponse(data, status=200, content_type=content_type)
开发者ID:allo-,项目名称:seahub,代码行数:58,代码来源:views.py
示例3: send_group_member_add_mail
def send_group_member_add_mail(request, group, from_user, to_user):
c = {
'email': from_user,
'to_email': to_user,
'group': group,
}
subject = _(u'You are invited to join a group on %s') % SITE_NAME
send_html_email(subject, 'group/add_member_email.html', c, None, [to_user])
开发者ID:TanLian,项目名称:seahub,代码行数:9,代码来源:views.py
示例4: send_user_add_mail
def send_user_add_mail(request, email, password):
"""Send email when add new user."""
c = {
'user': request.user.username,
'org': request.user.org,
'email': email,
'password': password,
}
send_html_email(_(u'You are invited to join %s') % SITE_NAME,
'sysadmin/user_add_email.html', c, None, [email])
开发者ID:Neurones67,项目名称:seahub,代码行数:10,代码来源:sysadmin.py
示例5: send_user_reset_email
def send_user_reset_email(request, email, password):
"""
Send email when reset user password.
"""
c = {
'email': email,
'password': password,
}
send_html_email(_(u'Password has been reset on %s') % SITE_NAME,
'sysadmin/user_reset_email.html', c, None, [email])
开发者ID:Neurones67,项目名称:seahub,代码行数:11,代码来源:sysadmin.py
示例6: send_shared_link
def send_shared_link(request):
"""
Handle ajax post request to send file shared link.
"""
if not request.method == 'POST':
raise Http404
content_type = 'application/json; charset=utf-8'
if not IS_EMAIL_CONFIGURED:
data = json.dumps({'error':_(u'Sending shared link failed. Email service is not properly configured, please contact administrator.')})
return HttpResponse(data, status=500, content_type=content_type)
from seahub.settings import SITE_NAME
form = FileLinkShareForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
file_shared_link = form.cleaned_data['file_shared_link']
file_shared_name = form.cleaned_data['file_shared_name']
file_shared_type = form.cleaned_data['file_shared_type']
extra_msg = escape(form.cleaned_data['extra_msg'])
to_email_list = string2list(email)
for to_email in to_email_list:
# Add email to contacts.
mail_sended.send(sender=None, user=request.user.username,
email=to_email)
c = {
'email': request.user.username,
'to_email': to_email,
'file_shared_link': file_shared_link,
'file_shared_name': file_shared_name,
}
if extra_msg:
c['extra_msg'] = extra_msg
try:
if file_shared_type == 'f':
c['file_shared_type'] = "file"
send_html_email(_(u'A file is shared to you on %s') % SITE_NAME, 'shared_link_email.html', c, None, [to_email])
else:
c['file_shared_type'] = "directory"
send_html_email(_(u'A directory is shared to you on %s') % SITE_NAME, 'shared_link_email.html', c, None, [to_email])
except Exception, e:
logger.error(str(e))
data = json.dumps({'error':_(u'Internal server error. Send failed.')})
return HttpResponse(data, status=500, content_type=content_type)
data = json.dumps({"msg": _(u'Successfully sent.')})
return HttpResponse(data, status=200, content_type=content_type)
开发者ID:3c7,项目名称:seahub,代码行数:54,代码来源:views.py
示例7: send_activation_email
def send_activation_email(self, site):
"""
Send an activation email to the user associated with this
``RegistrationProfile``.
The activation email will make use of two templates:
``registration/activation_email_subject.txt``
This template will be used for the subject line of the
email. Because it is used as the subject line of an email,
this template's output **must** be only a single line of
text; output longer than one line will be forcibly joined
into only a single line.
``registration/activation_email.txt``
This template will be used for the body of the email.
These templates will each receive the following context
variables:
``activation_key``
The activation key for the new account.
``expiration_days``
The number of days remaining during which the account may
be activated.
``site``
An object representing the site on which the user
registered; depending on whether ``django.contrib.sites``
is installed, this may be an instance of either
``django.contrib.sites.models.Site`` (if the sites
application is installed) or
``django.contrib.sites.models.RequestSite`` (if
not). Consult the documentation for the Django sites
framework for details regarding these objects' interfaces.
"""
ctx_dict = { 'activation_key': self.activation_key,
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
'site': site,
'SITE_ROOT': settings.SITE_ROOT }
subject = render_to_string('registration/activation_email_subject.txt',
ctx_dict)
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
try:
user = User.objects.get(id=self.emailuser_id)
send_html_email(subject, 'registration/activation_email.html',
ctx_dict, None, [user.username])
except User.DoesNotExist:
pass
开发者ID:pombredanne,项目名称:seahub,代码行数:52,代码来源:models.py
示例8: post
def post(self, request, repo_id):
""" Only used for reset encrypted repo's password, and then send new
password to user's mainbox.
Permission checking:
1. repo owner.
"""
if not ENABLE_RESET_ENCRYPTED_REPO_PASSWORD or \
not IS_EMAIL_CONFIGURED:
error_msg = _(u'Feature disabled.')
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
# resource check
repo = seafile_api.get_repo(repo_id)
if not repo:
error_msg = 'Library %s not found.' % repo_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
if not repo.encrypted:
error_msg = 'Library %s is not encrypted.' % repo_id
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
# permission check
username = request.user.username
if not is_repo_owner(request, repo_id, username):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
secret_key = RepoSecretKey.objects.get_secret_key(repo_id)
if not secret_key:
error_msg = _(u"Can not reset this library's password.")
return api_error(HTTP_520_OPERATION_FAILED, error_msg)
new_password = get_random_string(10)
try:
seafile_api.reset_repo_passwd(repo_id, username, secret_key, new_password)
content = {'repo_name': repo.name, 'password': new_password,}
send_html_email(_(u'New password of library %s') % repo.name,
'snippets/reset_repo_password.html', content,
None, [email2contact_email(username)])
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({'success': True})
开发者ID:haiwen,项目名称:seahub,代码行数:47,代码来源:repo_send_new_password.py
示例9: do_action
def do_action(self):
now = datetime.datetime.now()
try:
cmd_last_check = CommandsLastCheck.objects.get(command_type=self.label)
logger.debug('Last check time is %s' % cmd_last_check.last_check)
unseen_notices = UserNotification.objects.get_all_notifications(
seen=False, time_since=cmd_last_check.last_check)
logger.debug('Update last check time to %s' % now)
cmd_last_check.last_check = now
cmd_last_check.save()
except CommandsLastCheck.DoesNotExist:
logger.debug('No last check time found, get all unread notices.')
unseen_notices = UserNotification.objects.get_all_notifications(
seen=False)
logger.debug('Create new last check time: %s' % now)
CommandsLastCheck(command_type=self.label, last_check=now).save()
email_ctx = {}
for notice in unseen_notices:
if email_ctx.has_key(notice.to_user):
email_ctx[notice.to_user] += 1
else:
email_ctx[notice.to_user] = 1
for to_user, count in email_ctx.items():
subject = subjects[1] if count > 1 else subjects[0]
c = {
'to_user': to_user,
'notice_count': count,
}
try:
send_html_email(subject, 'notifications/notice_email.html', c,
settings.DEFAULT_FROM_EMAIL, [to_user])
logger.info('Successfully sent email to %s' % to_user)
except Exception, e:
logger.error('Failed to send email to %s, error detail: %s' % (to_user, e))
开发者ID:Neurones67,项目名称:seahub,代码行数:44,代码来源:send_notices.py
示例10: save
def save(self, domain_override=None, email_template_name='registration/password_reset_email.html',
use_https=False, token_generator=default_token_generator):
"""
Generates a one-use only link for resetting password and sends to the user
"""
user = self.users_cache
if not domain_override:
site_name = get_site_name()
else:
site_name = domain_override
c = {
'email': user.username,
'uid': int_to_base36(user.id),
'user': user,
'token': token_generator.make_token(user),
}
send_html_email(_("Reset Password on %s") % site_name,
email_template_name, c, None, [user.username])
开发者ID:haiwen,项目名称:seahub,代码行数:21,代码来源:forms.py
示例11: send_shared_link
def send_shared_link(request):
"""
Handle ajax post request to send file shared link.
"""
if not request.method == 'POST':
raise Http404
content_type = 'application/json; charset=utf-8'
if not IS_EMAIL_CONFIGURED:
data = json.dumps({'error':_(u'Sending shared link failed. Email service is not properly configured, please contact administrator.')})
return HttpResponse(data, status=500, content_type=content_type)
from seahub.settings import SITE_NAME
form = FileLinkShareForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
file_shared_link = form.cleaned_data['file_shared_link']
file_shared_name = form.cleaned_data['file_shared_name']
file_shared_type = form.cleaned_data['file_shared_type']
extra_msg = escape(form.cleaned_data['extra_msg'])
to_email_list = string2list(email)
send_success, send_failed = [], []
for to_email in to_email_list:
if not is_valid_email(to_email):
send_failed.append(to_email)
continue
# Add email to contacts.
mail_sended.send(sender=None, user=request.user.username,
email=to_email)
c = {
'email': request.user.username,
'to_email': to_email,
'file_shared_link': file_shared_link,
'file_shared_name': file_shared_name,
}
if extra_msg:
c['extra_msg'] = extra_msg
if REPLACE_FROM_EMAIL:
from_email = request.user.username
else:
from_email = None # use default from email
if ADD_REPLY_TO_HEADER:
reply_to = request.user.username
else:
reply_to = None
try:
if file_shared_type == 'f':
c['file_shared_type'] = _(u"file")
send_html_email(_(u'A file is shared to you on %s') % SITE_NAME,
'shared_link_email.html',
c, from_email, [to_email],
reply_to=reply_to
)
else:
c['file_shared_type'] = _(u"directory")
send_html_email(_(u'A directory is shared to you on %s') % SITE_NAME,
'shared_link_email.html',
c, from_email, [to_email],
reply_to=reply_to)
send_success.append(to_email)
except Exception:
send_failed.append(to_email)
if len(send_success) > 0:
data = json.dumps({"send_success": send_success, "send_failed": send_failed})
return HttpResponse(data, status=200, content_type=content_type)
else:
data = json.dumps({"error": _("Internal server error, or please check the email(s) you entered")})
return HttpResponse(data, status=400, content_type=content_type)
else:
return HttpResponseBadRequest(json.dumps(form.errors),
content_type=content_type)
开发者ID:insky2005,项目名称:seahub,代码行数:82,代码来源:views.py
示例12: do_action
def do_action(self):
now = datetime.datetime.now()
try:
cmd_last_check = CommandsLastCheck.objects.get(command_type=self.label)
logger.debug('Last check time is %s' % cmd_last_check.last_check)
unseen_notices = UserNotification.objects.get_all_notifications(
seen=False, time_since=cmd_last_check.last_check)
logger.debug('Update last check time to %s' % now)
cmd_last_check.last_check = now
cmd_last_check.save()
except CommandsLastCheck.DoesNotExist:
logger.debug('No last check time found, get all unread notices.')
unseen_notices = UserNotification.objects.get_all_notifications(
seen=False)
logger.debug('Create new last check time: %s' % now)
CommandsLastCheck(command_type=self.label, last_check=now).save()
email_ctx = {}
for notice in unseen_notices:
to_email = Profile.objects.get_contact_email_by_user(notice.to_user)
if notice.to_user in email_ctx:
email_ctx[to_email] += 1
else:
email_ctx[to_email] = 1
for to_user, count in email_ctx.items():
# save current language
cur_language = translation.get_language()
# get and active user language
user_language = self.get_user_language(to_user)
translation.activate(user_language)
logger.info('Set language code to %s' % user_language)
self.stdout.write('[%s] Set language code to %s' % (
str(datetime.datetime.now()), user_language))
notices = []
for notice in unseen_notices:
if notice.to_user != to_user:
continue
if notice.is_priv_file_share_msg():
notice = self.format_priv_file_share_msg(notice)
elif notice.is_user_message():
notice = self.format_user_message(notice)
elif notice.is_group_msg():
notice = self.format_group_message(notice)
elif notice.is_grpmsg_reply():
notice = self.format_grpmsg_reply(notice)
elif notice.is_repo_share_msg():
notice = self.format_repo_share_msg(notice)
elif notice.is_file_uploaded_msg():
notice = self.format_file_uploaded_msg(notice)
elif notice.is_group_join_request():
notice = self.format_group_join_request(notice)
elif notice.is_add_user_to_group():
notice = self.format_add_user_to_group(notice)
notices.append(notice)
if not notices:
continue
c = {
'to_user': to_user,
'notice_count': count,
'notices': notices,
}
try:
send_html_email(_('New notice on %s') % settings.SITE_NAME,
'notifications/notice_email.html', c,
None, [to_user])
logger.info('Successfully sent email to %s' % to_user)
self.stdout.write('[%s] Successfully sent email to %s' % (str(datetime.datetime.now()), to_user))
except Exception as e:
logger.error('Failed to send email to %s, error detail: %s' % (to_user, e))
self.stderr.write('[%s] Failed to send email to %s, error detail: %s' % (str(datetime.datetime.now()), to_user, e))
# restore current language
translation.activate(cur_language)
开发者ID:henryhe008,项目名称:seahub,代码行数:93,代码来源:send_notices.py
示例13: do_action
#.........这里部分代码省略.........
unseen_notices = UserNotification.objects.get_all_notifications(
seen=False)
logger.debug('Create new last check time: %s' % now)
CommandsLastCheck(command_type=self.label, last_check=now).save()
email_ctx = {}
for notice in unseen_notices:
if notice.to_user in email_ctx:
email_ctx[notice.to_user] += 1
else:
email_ctx[notice.to_user] = 1
for to_user, count in email_ctx.items():
# save current language
cur_language = translation.get_language()
# get and active user language
user_language = self.get_user_language(to_user)
translation.activate(user_language)
logger.debug('Set language code to %s for user: %s' % (user_language, to_user))
self.stdout.write('[%s] Set language code to %s' % (
str(datetime.datetime.now()), user_language))
notices = []
for notice in unseen_notices:
logger.info('Processing unseen notice: [%s]' % (notice))
d = json.loads(notice.detail)
repo_id = d.get('repo_id', None)
group_id = d.get('group_id', None)
try:
if repo_id and not seafile_api.get_repo(repo_id):
notice.delete()
continue
if group_id and not ccnet_api.get_group(group_id):
notice.delete()
continue
except Exception as e:
logger.error(e)
continue
if notice.to_user != to_user:
continue
elif notice.is_group_msg():
notice = self.format_group_message(notice)
elif notice.is_repo_share_msg():
notice = self.format_repo_share_msg(notice)
elif notice.is_repo_share_to_group_msg():
notice = self.format_repo_share_to_group_msg(notice)
elif notice.is_file_uploaded_msg():
notice = self.format_file_uploaded_msg(notice)
elif notice.is_group_join_request():
notice = self.format_group_join_request(notice)
elif notice.is_add_user_to_group():
notice = self.format_add_user_to_group(notice)
elif notice.is_file_comment_msg():
notice = self.format_file_comment_msg(notice)
elif notice.is_guest_invitation_accepted_msg():
notice = self.format_guest_invitation_accepted_msg(notice)
if notice is None:
continue
notices.append(notice)
if not notices:
continue
contact_email = Profile.objects.get_contact_email_by_user(to_user)
to_user = contact_email # use contact email if any
c = {
'to_user': to_user,
'notice_count': count,
'notices': notices,
}
try:
send_html_email(_('New notice on %s') % get_site_name(),
'notifications/notice_email.html', c,
None, [to_user])
logger.info('Successfully sent email to %s' % to_user)
self.stdout.write('[%s] Successfully sent email to %s' % (str(datetime.datetime.now()), to_user))
except Exception as e:
logger.error('Failed to send email to %s, error detail: %s' % (to_user, e))
self.stderr.write('[%s] Failed to send email to %s, error detail: %s' % (str(datetime.datetime.now()), to_user, e))
# restore current language
translation.activate(cur_language)
开发者ID:haiwen,项目名称:seahub,代码行数:101,代码来源:send_notices.py
示例14: post
def post(self, request):
if not IS_EMAIL_CONFIGURED:
error_msg = _(u'Sending shared link failed. Email service is not properly configured, please contact administrator.')
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
# check args
email = request.POST.get('email', None)
if not email:
error_msg = 'email invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
token = request.POST.get('token', None)
if not token:
error_msg = 'token invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
extra_msg = request.POST.get('extra_msg', '')
# check if token exists
try:
link = UploadLinkShare.objects.get(token=token)
except UploadLinkShare.DoesNotExist:
error_msg = 'token %s not found.' % token
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
# check if is upload link owner
username = request.user.username
if not link.is_owner(username):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
result = {}
result['failed'] = []
result['success'] = []
to_email_list = string2list(email)
# use contact_email, if present
useremail = Profile.objects.get_contact_email_by_user(request.user.username)
for to_email in to_email_list:
failed_info = {}
if not is_valid_email(to_email):
failed_info['email'] = to_email
failed_info['error_msg'] = 'email invalid.'
result['failed'].append(failed_info)
continue
# prepare basic info
c = {
'email': username,
'to_email': to_email,
'extra_msg': extra_msg,
}
if REPLACE_FROM_EMAIL:
from_email = useremail
else:
from_email = None # use default from email
if ADD_REPLY_TO_HEADER:
reply_to = useremail
else:
reply_to = None
c['shared_upload_link'] = gen_shared_upload_link(token)
title = _(u'An upload link is shared to you on %s') % SITE_NAME
template = 'shared_upload_link_email.html'
# send email
try:
send_html_email(title, template, c, from_email, [to_email], reply_to=reply_to)
result['success'].append(to_email)
except Exception as e:
logger.error(e)
failed_info['email'] = to_email
failed_info['error_msg'] = 'Internal Server Error'
result['failed'].append(failed_info)
return Response(result)
开发者ID:RaphaelWimmer,项目名称:seahub,代码行数:80,代码来源:send_upload_link_email.py
示例15: send_group_member_add_mail
def send_group_member_add_mail(request, group, from_user, to_user):
c = {"email": from_user, "to_email": to_user, "group": group}
subject = _(u"You are invited to join a group on %s") % SITE_NAME
send_html_email(subject, "group/add_member_email.html", c, None, [to_user])
开发者ID:octomike,项目名称:seahub,代码行数:5,代码来源:views.py
示例16: do_action
def do_action(self):
now = datetime.datetime.now()
try:
cmd_last_check = CommandsLastCheck.objects.get(command_type=self.label)
logger.debug('Last check time is %s' % cmd_last_check.last_check)
unseen_notices = UserNotification.objects.get_all_notifications(
seen=False, time_since=cmd_last_check.last_check)
logger.debug('Update last check time to %s' % now)
cmd_last_check.last_check = now
cmd_last_check.save()
except CommandsLastCheck.DoesNotExist:
logger.debug('No last check time found, get all unread notices.')
unseen_notices = UserNotification.objects.get_all_notifications(
seen=False)
logger.debug('Create new last check time: %s' % now)
CommandsLastCheck(command_type=self.label, last_check=now).save()
email_ctx = {}
for notice in unseen_notices:
if notice.to_user in email_ctx:
email_ctx[notice.to_user] += 1
else:
email_ctx[notice.to_user] = 1
for to_user, count in email_ctx.items():
notices = []
for notice in unseen_notices:
if notice.to_user != to_user:
continue
if notice.is_priv_file_share_msg():
notice = self.format_priv_file_share_msg(notice)
elif notice.is_user_message():
notice = self.format_user_message(notice)
elif notice.is_group_msg():
notice = self.format_group_message(notice)
elif notice.is_grpmsg_reply():
notice = self.format_grpmsg_reply(notice)
elif notice.is_repo_share_msg():
notice = self.format_repo_share_msg(notice)
elif notice.is_file_uploaded_msg():
notice = self.format_file_uploaded_msg(notice)
elif notice.is_group_join_request():
notice = self.format_group_join_request(notice)
notices.append(notice)
if not notices:
continue
subject = subjects[1] if count > 1 else subjects[0]
c = {
'to_user': to_user,
'notice_count': count,
'notices': notices,
'avatar_url': self.get_avatar_url(to_user),
'service_url': get_service_url(),
}
try:
send_html_email(subject, 'notifications/notice_email.html', c,
None, [to_user])
logger.info('Successfully sent email to %s' % to_user)
except Exception as e:
logger.error('Failed to send email to %s, error detail: %s' % (to_user, e))
开发者ID:jamjr,项目名称:seahub,代码行数:76,代码来源:send_notices.py
示例17: do_action
def do_action(self):
today = datetime.utcnow().replace(hour=0).replace(minute=0).replace(
second=0).replace(microsecond=0)
emails = []
user_file_updates_email_intervals = []
for ele in UserOptions.objects.filter(
option_key=KEY_FILE_UPDATES_EMAIL_INTERVAL):
try:
user_file_updates_email_intervals.append(
(ele.email, int(ele.option_val))
)
emails.append(ele.email)
except Exception as e:
logger.error(e)
continue
user_last_emailed_time_dict = {}
for ele in UserOptions.objects.filter(
option_key=KEY_FILE_UPDATES_LAST_EMAILED_TIME).filter(
email__in=emails):
try:
user_last_emailed_time_dict[ele.email] = datetime.strptime(
ele.option_val, "%Y-%m-%d %H:%M:%S")
except Exception as e:
logger.error(e)
continue
for (username, interval_val) in user_file_updates_email_intervals:
# save current language
cur_language = translation.get_language()
# get and active user language
user_language = self.get_user_language(username)
translation.activate(user_language)
logger.debug('Set language code to %s for user: %s' % (
user_language, username))
self.stdout.write('[%s] Set language code to %s' % (
str(datetime.now()), user_language))
# get last_emailed_time if any, defaults to today
last_emailed_time = user_last_emailed_time_dict.get(username, today)
now = datetime.utcnow().replace(microsecond=0)
if (now - last_emailed_time).seconds < interval_val:
continue
# get file updates(from: last_emailed_time, to: now) for repos
# user can access
res = seafevents_api.get_user_activities_by_timestamp(
username, last_emailed_time, now)
if not res:
continue
# remove my activities
res = filter(lambda x: x.op_user != username, res)
if not res:
continue
# format mail content & send file updates email to user
try:
for ele in res:
ele.user_avatar = self.get_avatar_src(ele.op_user)
ele.local_timestamp = utc_to_local(ele.timestamp)
ele.op_user_link = a_tag(email2nickname(ele.op_user),
user_info_url(ele.op_user))
ele.operation, ele.op_details = self.format_file_operation(ele)
except Exception as e:
logger.error('Failed to format mail content for user: %s' %
username)
logger.error(e, exc_info=True)
continue
nickname = email2nickname(username)
contact_email = Profile.objects.get_contact_email_by_user(username)
c = {
'name': nickname,
'updates_count': len(res),
'updates': res,
}
try:
send_html_email(_('New file updates on %s') % get_site_name(),
'notifications/file_updates_email.html', c,
None, [contact_email])
# set new last_emailed_time
UserOptions.objects.set_file_updates_last_emailed_time(
username, now)
except Exception as e:
logger.error('Failed to send email to %s, error detail: %s' %
(contact_email, e))
self.stderr.write('[%s] Failed to send email to %s, error '
'detail: %s' % (str(now), contact_email, e))
finally:
# reset lang
translation.activate(cur_language)
开发者ID:haiwen,项目名称:seahub,代码行数:96,代码来源:send_file_updates.py
注:本文中的seahub.utils.send_html_email函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论