本文整理汇总了Python中myrobogals.rgmessages.models.EmailRecipient.user方法的典型用法代码示例。如果您正苦于以下问题:Python EmailRecipient.user方法的具体用法?Python EmailRecipient.user怎么用?Python EmailRecipient.user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类myrobogals.rgmessages.models.EmailRecipient
的用法示例。
在下文中一共展示了EmailRecipient.user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: email_message
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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()
示例2: genandsendpw
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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()
示例3: save
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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()
示例4: cancelvisit
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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))
示例5: welcome_email
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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()
示例6: send_mail
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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()
示例7: check_default_pass
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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()
示例8: writeemail
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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()
#.........这里部分代码省略.........
示例9: invitetovisit
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [as 别名]
def invitetovisit(request, visit_id):
if not request.user.is_staff:
raise Http404
chapter = request.user.chapter
v = get_object_or_404(SchoolVisit, pk=visit_id)
error = ''
if (v.chapter != chapter) and not request.user.is_superuser:
raise Http404
if request.method == 'POST':
inviteform = InviteForm(request.POST, user=request.user, visit=v)
if inviteform.is_valid():
data = inviteform.cleaned_data
try:
if data['action'] == '1':
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 = v.chapter.invite_email_html
message.html = 1
message.from_name = chapter.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()
# Send to all users who haven't opted out of workshop reminders
if request.POST['type'] == '1':
users = User.objects.filter(chapter=chapter, is_active=True, email_reminder_optin=True)
# Send to chapter committee
elif request.POST['type'] == '2':
users = User.objects.filter(chapter=chapter, is_active=True, is_staff=True)
# Send to all trained users who haven't opted out of workshop reminders
elif request.POST['type'] == '4':
users = User.objects.filter(chapter=chapter, is_active=True, email_reminder_optin=True,
trained=True)
# Send to a user list
elif request.POST['type'] == '5':
ul = data['list']
users = ul.users.all()
# Send to specifically selected users
else:
users = data['memberselect']
for one_user in users:
if data['action'] == '1':
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()
EventAttendee.objects.filter(user=one_user, event=v).delete()
ea = EventAttendee()
ea.event = v
ea.user = one_user
if data['action'] == '1':
ea.rsvp_status = 1
if data['action'] == '2':
ea.rsvp_status = 2
ea.actual_status = 0
ea.save()
if data['action'] == '1':
# Now mark it as OK to send. The email and all recipients are now in MySQL.
# A background script on the server will process the queue.
message.status = 0
message.save()
if data['action'] == '1':
messages.success(request,
message=unicode(_("Invitations have been sent to the selected volunteers")))
if data['action'] == '2':
messages.success(request, message=unicode(_("Selected volunteers have been added as attending")))
return HttpResponseRedirect('/teaching/' + str(v.pk) + '/')
except Exception as e:
error = e.args[0]
else:
inviteform = InviteForm(None, user=request.user, visit=v)
return render_to_response('visit_invite.html', {'inviteform': inviteform, 'visit_id': visit_id, 'error': error},
context_instance=RequestContext(request))
示例10: importcsv
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [as 别名]
def importcsv(filerows, welcomeemail, defaults, chapter, updateuser, ignore_email):
columns=None
users_imported=0
username_pos=0
users_updated=0
existing_users=0
existing_emails=0
count=-1
username_field_exists_flag=False
user_already_exists=False
msg=""
if 'date_joined' not in defaults:
defaults['date_joined'] = datetime.now()
elif defaults['date_joined'] == None:
defaults['date_joined'] = datetime.now()
for row in filerows:
if any(row):
# Create new user
newuser = User()
count+=1
user_already_exists_flag=False
# Get column names from first row, also get the positions of the fields so that we can extract their values
# using their positions later.
if (columns == None):
columns = row
if 'first_name' not in columns:
raise RgImportCsvException(_('You must specify a first_name field'))
else:
first_name_pos=columns.index('first_name')
if 'last_name' not in columns:
raise RgImportCsvException(_('You must specify a last_name field'))
else:
last_name_pos=columns.index('last_name')
if 'email' not in columns:
raise RgImportCsvException(_('You must specify an email field'))
else:
email_pos = columns.index('email')
if 'username' in columns:
username_pos=columns.index('username')
username_field_exists_flag=True
if 'mobile' in columns:
mobile_pos=columns.index('mobile')
continue
# Process row
i = 0;
# extracting the values of the username, email, first_name and last_name fields for each row.
if username_field_exists_flag:
uname=row[username_pos]
else:
uname = ''
email=row[email_pos]
first_name=row[first_name_pos]
last_name=row[last_name_pos]
# now remove all the whitespaces from the extracted values.
uname_data=uname.strip()
email_data=email.strip()
first_name_data=first_name.strip()
last_name_data=last_name.strip()
# check if any of the values is None or empty for a row. If yes, form an error message and ignore that row.
if first_name_data == None or first_name_data == '':
msg += ("<br>First name not provided for row %d - row ignored.") % count
continue
if last_name_data == None or last_name_data == '' :
msg += ("<br>Last name not provided for row %d - row ignored.") % count
continue
if email_data == None or email_data == '' :
msg += ("<br>Email not provided for row %d - row ignored.") % count
continue
# check if the username exists, if yes, check if the 'updateuser' checkbox is ticked. If it is ticked,
# then get the row with the matching username (and, as we will see, replace its contents). Otherwise, ignore.
# Also, they must be from the same chapter
if not check_username(uname_data):
user_already_exists_flag = True
if updateuser:
newuser = User.objects.get(username=uname_data)
if newuser.chapter == chapter:
existing_users += 1
else:
msg += ("<br>Row %d has a username clash (%s) with another chapter - row ignored") % (count, uname_data)
continue
else:
msg += ("<br>Row %d has a username clash (%s) - row ignored") % (count, uname_data)
continue
# check if the email exists for any user, if yes, check if the 'ignore_email' checkbox is ticked. If it is not ticked,
# then get the row with the matching username (and, as we will see, replace its contents). Otherwise, ignore.
# Also, they must be from the same chapter
elif not check_email_and_chapter(email_data, chapter):
existing_emails+=1
if ignore_email:
#.........这里部分代码省略.........
示例11: writeemail
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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)
#.........这里部分代码省略.........
示例12: newpost
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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
示例13: newtopic
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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
示例14: rsvpemail
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [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))
示例15: emailvisitattendees
# 需要导入模块: from myrobogals.rgmessages.models import EmailRecipient [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailRecipient import user [as 别名]
def emailvisitattendees(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':
emailform = EmailAttendeesForm(request.POST, user=request.user, visit=v)
if emailform.is_valid():
data = emailform.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()
# Start processing recipient list
# Send to all invitees
if request.POST['invitee_type'] == '1':
id_list = EventAttendee.objects.filter(event=v.id).values_list('user_id')
users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True)
# Send to invitees who have RSVP'd as attending
elif request.POST['invitee_type'] == '2':
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)
# Send to invitees who have RSVP'd as not attending
elif request.POST['invitee_type'] == '3':
id_list = EventAttendee.objects.filter(event=v.id, rsvp_status=4).values_list('user_id')
users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True)
# Send to invitees who have yet to RSVP
elif request.POST['invitee_type'] == '4':
id_list = EventAttendee.objects.filter(event=v.id, rsvp_status=1).values_list('user_id')
users = User.objects.filter(id__in=id_list, is_active=True, email_reminder_optin=True)
# Send to specifically selected users
elif request.POST['invitee_type'] == '5':
users = data['memberselect']
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()
messages.success(request, message=unicode(_("Email sent succesfully")))
return HttpResponseRedirect('/teaching/' + str(v.pk) + '/')
else:
emailform = EmailAttendeesForm(None, user=request.user, visit=v)
return render_to_response('visit_email.html', {'emailform': emailform, 'visit_id': visit_id},
context_instance=RequestContext(request))