本文整理汇总了Python中myrobogals.rgmessages.models.EmailMessage.html方法的典型用法代码示例。如果您正苦于以下问题:Python EmailMessage.html方法的具体用法?Python EmailMessage.html怎么用?Python EmailMessage.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类myrobogals.rgmessages.models.EmailMessage
的用法示例。
在下文中一共展示了EmailMessage.html方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
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
"""
for user in self.users_cache:
t = loader.get_template(email_template_name)
c = {
'email': user.email,
'uid': int_to_base36(user.id),
'user': user,
'token': token_generator.make_token(user),
}
message = EmailMessage()
message.subject = 'Password reset'
message.body = t.render(Context(c))
message.from_address = '[email protected]'
message.reply_address = '[email protected]'
message.from_name = user.chapter.name
message.sender = User.objects.get(username='edit')
message.html = False
message.status = -1
message.save()
recipient = EmailRecipient()
recipient.message = message
recipient.user = user
recipient.to_name = user.get_full_name()
recipient.to_address = user.email
recipient.save()
message.status = 0
message.save()
示例2: email_message
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def email_message(email_subject, email_body, chapter):
message = EmailMessage()
message.subject = email_subject
message.body = email_body
message.from_name = "myRobogals"
message.from_address = "[email protected]"
message.reply_address = "[email protected]"
message.sender = User.objects.get(username='edit')
message.html = True
message.email_type = 0
# Message is set to WAIT mode
message.status = -1
message.save()
# Creates a list of all users to notify
if chapter.notify_list != None:
users_to_notify = chapter.notify_list.users.all()
# Email to all users that need to be notified
for user in users_to_notify:
recipient = EmailRecipient()
recipient.message = message
recipient.user = user
recipient.to_name = user.get_full_name()
recipient.to_address = user.email
recipient.save()
message.status = 0
message.save()
示例3: genandsendpw
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def genandsendpw(user, welcomeemail, chapter):
plaintext_password = User.objects.make_random_password(6)
user.set_password(plaintext_password)
user.save()
message = EmailMessage()
message.subject = welcomeemail['subject']
try:
message.body = welcomeemail['body'].format(
chapter=chapter,
user=user,
plaintext_password=plaintext_password)
except Exception:
raise RgGenAndSendPwException('Email body contains invalid fields')
message.from_address = '[email protected]'
message.reply_address = '[email protected]'
message.from_name = chapter.name
message.sender = User.objects.get(username='edit')
message.html = welcomeemail['html']
message.status = -1
message.save()
recipient = EmailRecipient()
recipient.message = message
recipient.user = user
recipient.to_name = user.get_full_name()
recipient.to_address = user.email
recipient.save()
message.status = 0
message.save()
示例4: previewemail
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def previewemail(request):
if not request.user.is_staff and not request.user.is_superuser:
raise Http404
message = EmailMessage()
if request.POST['header']:
h = EmailHeader.objects.filter(pk=request.POST['header'])
if h:
message.body = h[0].upper_body + request.POST['msg'] + h[0].lower_body
else:
message.body = request.POST['msg']
else:
message.body = request.POST['msg']
message.html = True
return render_to_response('email_show.html', {'email': message}, context_instance=RequestContext(request))
示例5: cancelvisit
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def cancelvisit(request, visit_id):
if not request.user.is_staff:
raise Http404
chapter = request.user.chapter
v = get_object_or_404(SchoolVisit, pk=visit_id)
if (v.chapter != chapter) and not request.user.is_superuser:
raise Http404
if request.method == 'POST':
cancelform = CancelForm(request.POST, user=request.user, visit=v)
if cancelform.is_valid():
data = cancelform.cleaned_data
message = EmailMessage()
message.subject = data['subject']
message.body = data['body']
message.from_address = request.user.email
message.reply_address = request.user.email
message.sender = request.user
message.html = True
message.from_name = chapter.name
message.scheduled = False
# Don't send it yet until the recipient list is done
message.status = -1
# Save to database so we get a value for the primary key,
# which we need for entering the recipient entries
message.save()
# Send to everyone who has been invited
id_list = EventAttendee.objects.filter(event=v.id, rsvp_status=2).values_list('user_id')
users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True)
for one_user in users:
recipient = EmailRecipient()
recipient.message = message
recipient.user = one_user
recipient.to_name = one_user.get_full_name()
recipient.to_address = one_user.email
recipient.save()
message.status = 0
message.save()
Event.objects.filter(id=v.id).delete()
messages.success(request, message=unicode(_("Visit cancelled successfully")))
return HttpResponseRedirect('/teaching/list/')
else:
cancelform = CancelForm(None, user=request.user, visit=v)
return render_to_response('visit_cancel.html', {'cancelform': cancelform, 'visit_id': visit_id},
context_instance=RequestContext(request))
示例6: welcome_email
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def welcome_email(request, chapter, u):
message = EmailMessage()
try:
message.subject = chapter.welcome_email_subject.format(
chapter=chapter,
user=u,
plaintext_password=request.POST['password1'])
except Exception:
message.subject = chapter.welcome_email_subject
try:
message.body = chapter.welcome_email_msg.format(
chapter=chapter,
user=u,
plaintext_password=request.POST['password1'])
except Exception:
message.body = chapter.welcome_email_msg
# Setting defaults
message.from_address = '[email protected]'
message.reply_address = '[email protected]'
message.from_name = chapter.name
message.sender = User.objects.get(username='edit')
message.html = chapter.welcome_email_html
# Setting message to -1 in the DB shows that the message is in WAIT mode
message.status = -1
message.save()
# Prepares message for sending
recipient = EmailRecipient()
recipient.message = message
recipient.user = u
recipient.to_name = u.get_full_name()
recipient.to_address = u.email
recipient.save()
# Change message to PENIDNG mode, which waits for server to send
message.status = 0
message.save()
示例7: send_mail
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def send_mail(self, subject_template_name, email_template_name,
context, from_email, to_email, html_email_template_name=None):
body = loader.render_to_string(email_template_name, context)
message = EmailMessage()
message.subject = 'Password reset'
message.body = body
message.from_address = '[email protected]'
message.reply_address = '[email protected]'
message.from_name = context['user'].chapter.name
message.sender = User.objects.get(username='edit')
message.html = False
message.status = -1
message.save()
recipient = EmailRecipient()
recipient.message = message
recipient.user = context['user']
recipient.to_name = context['user'].get_full_name()
recipient.to_address = to_email
recipient.save()
message.status = 0
message.save()
示例8: check_default_pass
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def check_default_pass():
users = User.objects.all()
for u in users:
if check_password("newrg123", u.password):
message = EmailMessage()
message.body = "Dear " + u.first_name + ",\n\nYou are recieving this automated email because your myRobogals account is still set to use the default password. This is a security risk and exposes your myRobogals account to potentially being used by others.\n\nPlease login at http://my.robogals.org using the following credentials:\nUsername: " + u.username + "\nPassword: newrg123\n\nOnce you have logged in, please change your password.\n\nThankyou,\n\nmyRobogals password nagging bot :)"
message.subject = "Warning: Account is using default password"
message.from_address = "[email protected]"
message.from_name = "myRobogals"
message.reply_address = "[email protected]"
message.html = False
message.status = -1
message.sender_id = 168
message.save()
recipient = EmailRecipient()
recipient.message = message
recipient.user = u
recipient.to_name = u.get_full_name()
recipient.to_address = u.email
recipient.save()
message.status = 0
message.save()
示例9: writeemail
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def writeemail(request):
memberstatustypes = MemberStatusType.objects.all()
if not request.user.is_staff:
raise Http404
if request.method == 'POST':
typesel = request.POST['type']
schedsel = request.POST['scheduling']
statussel = request.POST['status']
if 'step' in request.POST:
if request.POST['step'] == '1':
emailform = WriteEmailForm(request.POST, user=request.user)
request.session['emailform'] = emailform
elif request.POST['step'] == '2':
if 'emailform' not in request.session:
raise Http404
emailform = request.session['emailform']
del request.session['emailform']
else:
raise Http404
else:
raise Http404
if emailform.is_valid():
data = emailform.cleaned_data
if request.POST['step'] == '2':
message = EmailMessage()
message.subject = data['subject']
message.body = data['body']
message.from_address = request.user.email
message.reply_address = request.user.email
message.sender = request.user
message.html = True
if request.POST['scheduling'] == '1':
message.scheduled = True
message.scheduled_date = datetime.combine(data['schedule_date'], data['schedule_time'])
try:
message.scheduled_date_type = int(data['schedule_zone'])
except Exception:
message.scheduled_date_type = 1
else:
message.scheduled = False
if request.POST['type'] == '4':
n = data['newsletters']
message.from_name = n.from_name
message.from_address = n.from_email
message.reply_address = n.from_email
message.sender = n.from_user
else:
message.content_subtype = "html"
if int(data['from_type']) == 0:
message.from_name = "Robogals"
elif int(data['from_type']) == 1:
message.from_name = request.user.chapter.name
else:
message.from_name = request.user.get_full_name()
# Don't send it yet until the recipient list is done
message.status = -1
# Save to database so we get a value for the primary key,
# which we need for entering the recipient entries
message.save()
if request.POST['type'] == '1':
if request.user.is_superuser:
# "Email all members worldwide" feature disabled Nov 2010 - too much potential for abuse.
# Can be re-enabled by uncommenting the following line, commenting the exception,
# and removing the disabled tag from the relevant radio button in email_write.html
#users = User.objects.filter(chapter__in=data['chapters'], is_active=True, email_chapter_optin=True)
raise Exception
else:
users = User.objects.filter(chapter=request.user.chapter, is_active=True, email_chapter_optin=True).exclude(email='')
elif request.POST['type'] == '2':
if request.user.is_superuser:
users = User.objects.filter(chapter__in=data['chapters_exec'], is_active=True, is_staff=True).exclude(email='')
else:
users = User.objects.filter(chapter=request.user.chapter, is_active=True, is_staff=True).exclude(email='')
elif request.POST['type'] == '5':
ul = data['list']
users = ul.users.all().exclude(email='')
elif request.POST['type'] == '4':
if request.user.is_superuser:
# Special rule for The Amplifier
if data['newsletters'].pk == 1:
users = User.objects.filter(is_active=True, email_newsletter_optin=True).exclude(email='')
else:
users = User.objects.none()
else:
users = data['recipients']
usersfiltered = []
if statussel != '0' and request.POST['type'] != '4':
for one_user in users:
if one_user.membertype().pk == int(statussel):
if request.POST['step'] == '1':
usersfiltered.append(one_user)
else:
if str(one_user.pk) in request.POST.keys():
recipient = EmailRecipient()
#.........这里部分代码省略.........
示例10: api
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def api(request):
if 'api' not in request.GET:
return HttpResponse("-1")
elif request.GET['api'] != API_SECRET:
return HttpResponse("-1")
elif 'action' in request.GET:
try:
n = Newsletter.objects.get(pk=request.GET['newsletter'])
except Newsletter.DoesNotExist:
return HttpResponse("-1")
try:
if request.GET['action'] == 'subscribe':
email = unquote_plus(request.GET['email']).strip()
if not email_re.match(email):
return HttpResponse("C") # Invalid email
c = NewsletterSubscriber.objects.filter(email=email, newsletter=n, active=True).count()
if c != 0:
return HttpResponse("B") # Already subscribed
if n.pk == 1:
users_count = User.objects.filter(is_active=True, email=email, email_newsletter_optin=True).count()
if users_count > 0:
return HttpResponse("B") # Already subscribed
try:
# They've tried to subscribe already, so resend confirmation email
p = PendingNewsletterSubscriber.objects.get(email=email, newsletter=n)
except PendingNewsletterSubscriber.DoesNotExist:
p = PendingNewsletterSubscriber()
p.email = email
p.uniqid = md5(SECRET_KEY + email + n.name).hexdigest()
p.newsletter = n
p.save()
confirm_url = n.confirm_url + "pid=" + str(p.pk) + "&key=" + p.uniqid
message = EmailMessage()
message.subject = n.confirm_subject
message.body = n.confirm_email.replace('{email}', email).replace('{url}', confirm_url)
message.from_address = n.confirm_from_email
message.from_name = n.confirm_from_name
message.reply_address = n.confirm_from_email
message.sender = n.confirm_from_user
message.html = n.confirm_html
# Don't send it yet until the recipient list is done
message.status = -1
# Save to database so we get a value for the primary key,
# which we need for entering the recipient entries
message.save()
recipient = EmailRecipient()
recipient.message = message
recipient.to_name = ""
recipient.to_address = email
recipient.save()
message.status = 0
message.save()
return HttpResponse("A") # Success!
elif request.GET['action'] == 'confirm':
pid = unquote_plus(request.GET['id'])
key = unquote_plus(request.GET['key'])
try:
p = PendingNewsletterSubscriber.objects.get(pk=pid, newsletter=n, uniqid=key)
except PendingNewsletterSubscriber.DoesNotExist:
return HttpResponse("B")
try:
if n.pk != 1:
# Only do the user thing for The Amplifier (id = 1)
raise User.DoesNotExist
try:
u = User.objects.get(email=p.email)
except User.MultipleObjectsReturned:
# Subscribe the first user with this email address
u = User.objects.filter(email=p.email)[0]
# This user is already a Robogals member
u.email_newsletter_optin = True
u.save()
except User.DoesNotExist:
ns = NewsletterSubscriber()
ns.newsletter = n
ns.email = p.email
ns.active = True
ns.details_verified = False
ns.save()
p.delete()
return HttpResponse("A")
elif request.GET['action'] == 'unsubscribe':
email = unquote_plus(request.GET['email']).strip()
try:
ns = NewsletterSubscriber.objects.get(email=email, newsletter=n, active=True)
except NewsletterSubscriber.DoesNotExist:
# Not on the list. Perhaps subscribed as a Robogals member?
if n.pk != 1:
# Only do the user thing for The Amplifier (id = 1)
return HttpResponse("B") # Not subscribed
try:
for u in User.objects.filter(email=email):
if u.email_newsletter_optin:
u.email_newsletter_optin = False
u.save()
return HttpResponse("A")
return HttpResponse("B") # Not subscribed
except User.DoesNotExist:
return HttpResponse("B") # Not subscribed
ns.unsubscribed_date = datetime.now()
#.........这里部分代码省略.........
示例11: importcsv
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
#.........这里部分代码省略.........
unis = University.objects.all()
uni_ids = [-1]
for uni in unis:
uni_ids.append(uni.pk)
numval(colname, cell, newuser, defaults, uni_ids)
if getattr(newuser, 'university_id', 0) == -1:
newuser.university_id = chapter.university_id
elif colname == 'course_type':
numval(colname, cell, newuser, defaults, [1, 2])
elif colname == 'student_type':
numval(colname, cell, newuser, defaults, [1, 2])
elif colname == 'student_number':
stringval(colname, cell, newuser, defaults)
elif colname == 'privacy':
numval(colname, cell, newuser, defaults, [0, 5, 10, 20])
elif colname == 'dob_public':
boolval(colname, cell, newuser, defaults)
elif colname == 'email_public':
boolval(colname, cell, newuser, defaults)
elif colname == 'email_chapter_optin':
boolval(colname, cell, newuser, defaults)
elif colname == 'mobile_marketing_optin':
boolval(colname, cell, newuser, defaults)
elif colname == 'email_reminder_optin':
boolval(colname, cell, newuser, defaults)
elif colname == 'mobile_reminder_optin':
boolval(colname, cell, newuser, defaults)
elif colname == 'email_newsletter_optin':
boolval(colname, cell, newuser, defaults)
else:
pass # Unknown column, ignore
# Increment column and do the loop again
i += 1
# Should be the default at the model-level,
# but just to be sure...
newuser.is_active = True
newuser.is_staff = False
newuser.is_superuser = False
# If we still don't have a username and/or password
# by this stage, let's generate one
if getattr(newuser, 'username', '') == '':
new_username = generate_unique_username(row, columns)
newuser.username = new_username
if getattr(newuser, 'password', '') == '':
plaintext_password = User.objects.make_random_password(6)
newuser.set_password(plaintext_password)
# Apply any unapplied defaults
for key, value in defaults.iteritems():
if key not in columns:
setattr(newuser, key, value)
# And finally...
newuser.chapter = chapter
newuser.save()
# Must be called after save() because the primary key
# is required for these
mt = MemberStatus(user_id=newuser.pk, statusType_id=1)
mt.save()
# Send welcome email
if welcomeemail:
message = EmailMessage()
try:
message.subject = welcomeemail['subject'].format(
chapter=chapter,
user=newuser,
plaintext_password=plaintext_password)
except Exception:
newuser.delete()
raise RgImportCsvException(_('Welcome email subject format is invalid'))
try:
message.body = welcomeemail['body'].format(
chapter=chapter,
user=newuser,
plaintext_password=plaintext_password)
except Exception:
newuser.delete()
raise RgImportCsvException(_('Welcome email format is invalid'))
message.from_address = '[email protected]'
message.reply_address = '[email protected]'
message.from_name = chapter.name
message.sender = User.objects.get(username='edit')
message.html = welcomeemail['html']
message.status = -1
message.save()
recipient = EmailRecipient()
recipient.message = message
recipient.user = newuser
recipient.to_name = newuser.get_full_name()
recipient.to_address = newuser.email
recipient.save()
message.status = 0
message.save()
users_imported += 1
return users_imported
示例12: rsvpemail
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def rsvpemail(request, conf_id):
# Superuser check
if not request.user.is_superuser:
raise Http404
conf = get_object_or_404(Conference, pk=conf_id)
chapter = request.user.chapter
# Determine if form has been POSTed back
if request.method == 'POST':
# Validate email form data
emailform = EmailAttendeesForm(request.POST, conference=conf, user=request.user)
if emailform.is_valid():
data = emailform.cleaned_data
# Set up message
message = EmailMessage()
message.subject = data['subject']
message.body = data['body']
message.from_address = request.user.email
message.reply_address = request.user.email
message.sender = request.user
message.html = True
if int(data['from_type']) == 0:
message.from_name = "Robogals"
elif int(data['from_type']) == 1:
message.from_name = request.user.chapter.name
else:
message.from_name = request.user.get_full_name()
message.scheduled = False
# Don't send it yet until the recipient list is done
message.status = -1
# Save to database so we get a value for the primary key,
# which we need for entering the recipient entries
message.save()
# Start processing recipient list
# Insert choices for attending, not attending etc here
if request.POST['invitee_type'] == '1': # All
# Using `ConferenceAttendee`
users = ConferenceAttendee.objects.filter(conference=conf.id)
# Using `User`
# id_list = ConferenceAttendee.objects.filter(conference=conf.id).values_list('user_id')
# users = User.objects.filter(id__in = id_list, is_active=True, email_reminder_optin=True).order_by('last_name')
elif request.POST['invitee_type'] == '2': # Selected
users = data['memberselect']
for one_user in users:
recipient = EmailRecipient()
recipient.message = message
recipient.to_address = one_user.email
# Using `ConferenceAttendee`
recipient.user = one_user.user
recipient.to_name = one_user.full_name()
# Using `User`
# recipient.user = one_user
# recipient.to_name = one_user.get_full_name()
recipient.save()
# Send message
message.status = 0
message.save()
request.user.message_set.create(message=unicode(_("Email sent successfully")))
return HttpResponseRedirect('/conferences/' + str(conf.pk) + '/')
else:
emailform = EmailAttendeesForm(None, conference=conf, user=request.user)
# Display email form
return render_to_response('conf_rsvp_email.html', {'conf': conf, 'emailform': emailform}, context_instance=RequestContext(request))
示例13: writeemail
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def writeemail(request):
memberstatustypes = MemberStatusType.objects.all()
if not request.user.is_staff:
raise Http404
if request.method == 'POST':
typesel = request.POST['type']
schedsel = request.POST['scheduling']
statussel = request.POST['status']
if 'step' in request.POST:
if request.POST['step'] == '1':
emailform = WriteEmailForm(request.POST, user=request.user)
request.session['emailid'] = datetime.utcnow().strftime('%y%m%d%H%M%S')
request.session['emailform'] = emailform
elif request.POST['step'] == '2':
if ('emailform' not in request.session) or ('emailid' not in request.session):
if 'emailform' in request.session:
del request.session['emailform']
if 'emailid' in request.session:
del request.session['emailid']
raise Http404
if request.session['emailid'] != request.POST['emailid']:
raise Http404
warning = False
msg = ''
maxfilesize = 10
maxfilesetting = MessagesSettings.objects.filter(key='maxuploadfilesize')
if maxfilesetting:
maxfilesize = int(maxfilesetting[0].value)
for f in request.FILES.getlist('upload_files'):
if (f.name.__len__() > 70):
msg += '<br>File name: "' + f.name + '" is longer than 70 characters'
warning = True
if (f.size > maxfilesize * 1024*1024):
msg += '<br>File: "' + f.name + '" is larger than ' + str(maxfilesize) + ' MB'
warning = True
if warning:
del request.session['emailform']
del request.session['emailid']
request.user.message_set.create(message=unicode(_('- Can not upload files. Reason(s): %s' % msg)))
return HttpResponseRedirect('/messages/email/write/')
emailform = request.session['emailform']
del request.session['emailform']
del request.session['emailid']
else:
raise Http404
else:
raise Http404
if emailform.is_valid():
data = emailform.cleaned_data
if request.POST['step'] == '2':
message = EmailMessage()
message.subject = data['subject']
if data['header_list']:
hl = data['header_list']
message.body = hl.upper_body + data['body'] + hl.lower_body
else:
message.body = data['body']
message.from_address = request.user.email
message.reply_address = request.user.email
message.sender = request.user
message.html = True
if request.POST['scheduling'] == '1':
message.scheduled = True
message.scheduled_date = datetime.combine(data['schedule_date'], data['schedule_time'])
try:
message.scheduled_date_type = int(data['schedule_zone'])
except Exception:
message.scheduled_date_type = 1
else:
message.scheduled = False
if request.POST['type'] == '4':
n = data['newsletters']
message.from_name = n.from_name
message.from_address = n.from_email
message.reply_address = n.from_email
message.sender = n.from_user
else:
message.content_subtype = "html"
if int(data['from_type']) == 0:
message.from_name = "Robogals"
elif int(data['from_type']) == 1:
message.from_name = request.user.chapter.name
else:
message.from_name = request.user.get_full_name()
# Don't send it yet until the recipient list is done
message.status = -1
# Save to database so we get a value for the primary key,
# which we need for entering the recipient entries
message.save()
if request.POST['type'] == '1':
if request.user.is_superuser:
# "Email all members worldwide" feature disabled Nov 2010 - too much potential for abuse.
# Can be re-enabled by uncommenting the following line, commenting the exception,
# and removing the disabled tag from the relevant radio button in email_write.html
#users = User.objects.filter(chapter__in=data['chapters'], is_active=True, email_chapter_optin=True)
#.........这里部分代码省略.........
示例14: newpost
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def newpost(request, topic_id):
request.user.forum_last_act = datetime.datetime.now()
request.user.save()
user = request.user
t = get_object_or_404(Topic, pk=topic_id)
f = t.forum
g = f.category
c = g.chapter
if (user.is_superuser) or (user.is_staff and ((c == user.chapter) or (c == None))) or ((c == user.chapter) and (g.exec_only == False)) or ((c == None) and (g.exec_only == False)):
if request.method == 'POST':
postform = WritePostForm(request.POST)
if postform.is_valid():
data = postform.cleaned_data
postMessage = Post()
postMessage.topic = t
postMessage.posted_by = user
postMessage.message = data['message']
postMessage.save()
t.num_views = t.num_views - 1
t.last_post_time = datetime.datetime.now()
t.last_post_user = user
t.save()
f.last_post_time = datetime.datetime.now()
f.last_post_user = user
f.save()
if 'watch' in request.POST:
if request.POST['watch'] == '1':
if not f.watchers.filter(pk=user.pk):
t.watchers.add(user)
else:
if f.watchers.filter(pk=user.pk):
f.watchers.remove(user)
for topic in f.topic_set.all():
if topic != t:
topic.watchers.add(user)
else:
topic.watchers.remove(user)
else:
t.watchers.remove(user)
watchers = (f.watchers.all() | t.watchers.all()).distinct().exclude(pk=request.user.pk)
if watchers:
message = EmailMessage()
message.subject = 'New Post for topic "' + t.subject + '"'
message.body = 'New post for topic "' + t.subject + '" for forum "' + f.name + '" in category "' + g.name + '"\n\nPost message: (posted by ' + postMessage.posted_by.get_full_name() + ')\n' + postMessage.message
message.from_name = "myRobogals"
message.from_address = "[email protected]"
message.reply_address = "[email protected]"
message.sender = User.objects.get(pk=1692) #need to change
message.html = False
message.email_type = 1
message.status = -1
message.save()
for watcher in watchers:
recipient = EmailRecipient()
recipient.message = message
recipient.user = watcher
recipient.to_name = watcher.get_full_name()
recipient.to_address = watcher.email
recipient.save()
message.status = 0
message.save()
else:
request.user.message_set.create(message=unicode(_('- The field "Message" can not be empty')))
else:
raise Http404
if 'return' in request.GET:
return HttpResponseRedirect(request.GET['return'])
elif 'return' in request.POST:
return HttpResponseRedirect(request.POST['return'])
elif c:
return HttpResponseRedirect('/forums/' + c.myrobogals_url + '/topic/' + str(t.pk) + '/')
else:
return HttpResponseRedirect('/forums/' + request.user.chapter.myrobogals_url + '/topic/' + str(t.pk) + '/')
else:
raise Http404
示例15: newtopic
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import html [as 别名]
def newtopic(request, forum_id):
request.user.forum_last_act = datetime.datetime.now()
request.user.save()
f = get_object_or_404(Forum, pk=forum_id)
g = f.category
c = g.chapter
user = request.user
if (user.is_superuser) or (user.is_staff and ((c == user.chapter) or (c == None))) or ((c == user.chapter) and (g.exec_only == False)) or ((c == None) and (g.exec_only == False)):
if request.method == 'POST':
topicform = NewTopicForm(request.POST)
if topicform.is_valid():
data = topicform.cleaned_data
newTopic = Topic()
newTopic.forum = f
newTopic.posted_by = user
newTopic.subject = data['subject']
newTopic.last_post_time = datetime.datetime.now()
newTopic.last_post_user = user
if Topic.objects.filter(forum=newTopic.forum, subject=newTopic.subject):
msg = '- A similar topic already exists'
request.user.message_set.create(message=unicode(_(msg)))
else:
newTopic.save()
postMessage = Post()
postMessage.topic = newTopic
postMessage.posted_by = user
postMessage.message = data['message']
postMessage.save()
f.last_post_time = datetime.datetime.now()
f.last_post_user = user
f.save()
watchers = f.watchers.all().exclude(pk=request.user.pk)
if watchers:
message = EmailMessage()
message.subject = 'New Topic: ' + newTopic.subject
message.body = 'New topic for forum "' + f.name + '" in category "' + g.name +'"\n\nTopic subject: ' + newTopic.subject + ' (started by ' + newTopic.posted_by.get_full_name() + ')\n\nTopic Message:\n' + postMessage.message
message.from_name = "myRobogals"
message.from_address = "[email protected]"
message.reply_address = "[email protected]"
message.sender = User.objects.get(username='edit')
message.html = False
message.email_type = 1
message.status = -1
message.save()
for watcher in watchers:
recipient = EmailRecipient()
recipient.message = message
recipient.user = watcher
recipient.to_name = watcher.get_full_name()
recipient.to_address = watcher.email
recipient.save()
message.status = 0
message.save()
else:
request.user.message_set.create(message=unicode(_('- The fields "New Topic" and "Message" can not be empty')))
else:
raise Http404
if 'return' in request.GET:
return HttpResponseRedirect(request.GET['return'])
elif 'return' in request.POST:
return HttpResponseRedirect(request.POST['return'])
elif c:
return HttpResponseRedirect('/forums/' + c.myrobogals_url + '/forum/' + str(f.pk) + '/')
else:
return HttpResponseRedirect('/forums/' + request.user.chapter.myrobogals_url + '/forum/' + str(f.pk) + '/')
else:
raise Http404