本文整理汇总了Python中myrobogals.rgmessages.models.EmailMessage.email_type方法的典型用法代码示例。如果您正苦于以下问题:Python EmailMessage.email_type方法的具体用法?Python EmailMessage.email_type怎么用?Python EmailMessage.email_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类myrobogals.rgmessages.models.EmailMessage
的用法示例。
在下文中一共展示了EmailMessage.email_type方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: email_message
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import email_type [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: newpost
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import email_type [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
示例3: newtopic
# 需要导入模块: from myrobogals.rgmessages.models import EmailMessage [as 别名]
# 或者: from myrobogals.rgmessages.models.EmailMessage import email_type [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