本文整理汇总了Python中symposion.utils.mail.send_email函数的典型用法代码示例。如果您正苦于以下问题:Python send_email函数的具体用法?Python send_email怎么用?Python send_email使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了send_email函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: team_detail
def team_detail(request, slug):
team = get_object_or_404(Team, slug=slug)
state = team.get_state_for_user(request.user)
if team.access == "invitation" and state is None and not request.user.is_staff:
raise Http404()
if can_invite(team, request.user):
if request.method == "POST":
form = TeamInvitationForm(request.POST, team=team)
if form.is_valid():
form.invite()
send_email([form.user.email], "teams_user_invited", context={"team": team})
messages.success(request, _("Invitation created."))
return redirect("team_detail", slug=slug)
else:
form = TeamInvitationForm(team=team)
else:
form = None
return render(request, "symposion/teams/team_detail.html", {
"team": team,
"state": state,
"invite_form": form,
"can_join": can_join(team, request.user),
"can_leave": can_leave(team, request.user),
"can_apply": can_apply(team, request.user),
})
示例2: proposal_edit
def proposal_edit(request, pk):
queryset = ProposalBase.objects.select_related("speaker")
proposal = get_object_or_404(queryset, pk=pk)
proposal = ProposalBase.objects.get_subclass(pk=proposal.pk)
if request.user != proposal.speaker.user:
raise Http404()
if not proposal.can_edit():
ctx = {"title": "Proposal editing closed", "body": "Proposal editing is closed for this session type."}
return render(request, "proposals/proposal_error.html", ctx)
form_class = get_form(settings.PROPOSAL_FORMS[proposal.kind.slug])
if request.method == "POST":
form = form_class(request.POST, request.FILES, instance=proposal)
if form.is_valid():
form.save()
if hasattr(proposal, "reviews"):
users = User.objects.filter(Q(review__proposal=proposal) | Q(proposalmessage__proposal=proposal))
users = users.exclude(id=request.user.id).distinct()
for user in users:
ctx = {"user": request.user, "proposal": proposal}
send_email([user.email], "proposal_updated", context=ctx)
messages.success(request, "Proposal updated.")
return redirect("proposal_detail", proposal.pk)
else:
form = form_class(instance=proposal)
return render(request, "proposals/proposal_edit.html", {"proposal": proposal, "form": form})
示例3: save_model
def save_model(self, request, obj, form, change):
# First, save the object
super(PresentationAdmin, self).save_model(request, obj, form, change)
# Next, send an email to python staff
now = datetime.datetime.now()
send_email(
[settings.REGISTRATION_EMAIL],
"presentation_updated",
context={"presentation": obj,
"time": now,
"user": request.user}
)
示例4: proposal_detail
def proposal_detail(request, pk):
queryset = Proposal.objects.select_related("speaker", "speaker__user")
proposal = get_object_or_404(queryset, pk=pk)
if request.user not in [p.user for p in proposal.speakers()]:
raise Http404()
if not settings.ACCEPTING_PROPOSALS:
from symposion.review.forms import SpeakerCommentForm
message_form = SpeakerCommentForm()
if request.method == "POST":
message_form = SpeakerCommentForm(request.POST)
if message_form.is_valid():
message = message_form.save(commit=False)
message.user = request.user
message.proposal = proposal
message.save()
ProposalMessage = SpeakerCommentForm.Meta.model
reviewers = User.objects.filter(
id__in=ProposalMessage.objects.filter(
proposal=proposal
).exclude(
user=request.user
).distinct().values_list("user", flat=True)
)
for reviewer in reviewers:
ctx = {
"proposal": proposal,
"message": message,
"reviewer": True,
}
send_email(
[reviewer.email], "proposal_new_message",
context = ctx
)
return redirect(request.path)
else:
message_form = SpeakerCommentForm()
else:
message_form = None
ctx = {
"proposal": proposal,
"message_form": message_form,
}
ctx = RequestContext(request, ctx)
return render_to_response("proposals/proposal_detail.html", ctx)
示例5: sponsor_add
def sponsor_add(request):
if not request.user.is_staff:
raise Http404()
CHOICES = []
for s in SponsorLevel.objects.all():
CHOICES.append(( s, s.name + ': ' + ', '.join([b.benefit.name for b in BenefitLevel.objects.filter(level = s)]) ))
if request.method == "POST":
form = SponsorApplicationForm(request.POST, user=request.user, choices=CHOICES)
if form.is_valid():
sponsor = form.save(commit=False)
sponsor.save()
event_name = settings.EVENT_NAME
event_website = settings.EVENT_WEBSITE
event_email = settings.EVENT_EMAIL
event_phone = settings.EVENT_PHONE
message_ctx = {
"sponsor": sponsor,
"event_name": event_name,
"event_website": event_website,
"event_email": event_email,
"event_phone": event_phone
}
for c in sponsor.sponsor_contacts:
sponsor_email = c
send_email(
[sponsor_email], "sponsor_signup_conf",
context = message_ctx
)
staff_members = User.objects.filter(is_staff=True)
for staff in staff_members:
staff_email = staff.email
send_email(
[staff_email], "sponsor_signup",
context = message_ctx
)
return redirect("sponsor_detail", pk=sponsor.pk)
else:
form = SponsorApplicationForm(user=request.user, choices=CHOICES)
return render_to_response("sponsorship/add.html", {
"form": form,
}, context_instance=RequestContext(request))
示例6: team_apply
def team_apply(request, slug):
team = get_object_or_404(Team, slug=slug)
state = team.get_state_for_user(request.user)
if team.access == "invitation" and state is None and not request.user.is_staff:
raise Http404()
if can_apply(team, request.user) and request.method == "POST":
membership, created = Membership.objects.get_or_create(team=team, user=request.user)
membership.state = "applied"
membership.save()
managers = [m.user.email for m in team.managers()]
send_email(managers, "teams_user_applied", context={"team": team, "user": request.user})
messages.success(request, _("Applied to join team."))
return redirect("team_detail", slug=slug)
else:
return redirect("team_detail", slug=slug)
示例7: _send_confirmation
def _send_confirmation(sender, instance, created, **kwargs):
"""
Send an email to the sponsors mailing list when a new application is
submitted.
"""
if created:
send_email(
to=[settings.SPONSORSHIP_EMAIL],
kind='new_sponsor',
context={
'sponsor': instance,
},
)
send_email(
to=instance.contact_emails,
kind='new_sponsor_confirm',
context={'sponsor': instance}
)
示例8: proposal_speaker_manage
def proposal_speaker_manage(request, pk):
queryset = ProposalBase.objects.select_related("speaker")
proposal = get_object_or_404(queryset, pk=pk)
proposal = ProposalBase.objects.get_subclass(pk=proposal.pk)
if proposal.speaker != request.user.speaker_profile:
raise Http404()
if request.method == "POST":
add_speaker_form = AddSpeakerForm(request.POST, proposal=proposal)
if add_speaker_form.is_valid():
message_ctx = {"proposal": proposal}
def create_speaker_token(email_address):
# create token and look for an existing speaker to prevent
# duplicate tokens and confusing the pending speaker
try:
pending = Speaker.objects.get(Q(user=None, invite_email=email_address))
except Speaker.DoesNotExist:
salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
token = hashlib.sha1(salt + email_address).hexdigest()
pending = Speaker.objects.create(invite_email=email_address, invite_token=token)
else:
token = pending.invite_token
return pending, token
email_address = add_speaker_form.cleaned_data["email"]
# check if email is on the site now
users = EmailAddress.objects.get_users_for(email_address)
if users:
# should only be one since we enforce unique email
user = users[0]
message_ctx["user"] = user
# look for speaker profile
try:
speaker = user.speaker_profile
except ObjectDoesNotExist:
speaker, token = create_speaker_token(email_address)
message_ctx["token"] = token
# fire off email to user to create profile
send_email([email_address], "speaker_no_profile", context=message_ctx)
else:
# fire off email to user letting them they are loved.
send_email([email_address], "speaker_addition", context=message_ctx)
else:
speaker, token = create_speaker_token(email_address)
message_ctx["token"] = token
# fire off email letting user know about site and to create
# account and speaker profile
send_email([email_address], "speaker_invite", context=message_ctx)
invitation, created = AdditionalSpeaker.objects.get_or_create(
proposalbase=proposal.proposalbase_ptr, speaker=speaker
)
messages.success(request, "Speaker invited to proposal.")
return redirect("proposal_speaker_manage", proposal.pk)
else:
add_speaker_form = AddSpeakerForm(proposal=proposal)
ctx = {"proposal": proposal, "speakers": proposal.speakers(), "add_speaker_form": add_speaker_form}
return render(request, "proposals/proposal_speaker_manage.html", ctx)
示例9: handle
def handle(self, *args, **options):
group = ProposalGroup.objects.get(
name=options["proposal_group_name"],
)
reviewers = self.get_reviewers()
if options['new_reviewers']:
user_reviews = self.assign_new_user_reviews(group, reviewers)
else:
user_reviews = self.assign_user_reviews(group, reviewers)
for user, proposal_results in user_reviews.iteritems():
print("Sending assignments to %r" % user.email)
for pr in proposal_results:
ReviewAssignment.objects.get_or_create(
proposal=pr.proposal,
user=user,
origin=ReviewAssignment.AUTO_ASSIGNED_INITIAL,
)
send_email([user.email], "new_review_assignments", context={
"user": user,
"proposal_results": proposal_results,
"proposal_group": group,
})
示例10: handle
def handle(self, *args, **options):
if options['kind'] not in SLUGS:
print('ERROR: Unknown Proposal Kind: {}\n Must be one of: {}'.format(options['kind'], ', '.join(SLUGS)))
return False
to_bump = defaultdict(list)
unsubmitted = get_proposal_model(options['kind']).objects.filter(submitted=False, cancelled=False)
for unsub in unsubmitted:
path = reverse('proposal_detail', args=[unsub.id])
url = 'https://{domain}{path}'.format(domain=DOMAIN, path=path)
to_bump[unsub.speaker.email].append(unsub)
for email, proposals in to_bump.items():
send_email(
to=[email],
kind='proposal_bump',
context={
'proposal_kind': options['kind'],
'user': proposals[0].speaker.user,
'proposals': proposals,
},
)
示例11: sponsor_passes
#.........这里部分代码省略.........
price = ticket['price']
# Make dict of name/id pairs for discount generation
ticket_dict[ticket_name] = ticket_id
# Make our choices list for form
TICKET_CHOICES.append(( ticket_name, ticket_name + ' -- $' + price ))
# Next, make a list of *active* sponsors to add to our form
SPONSOR_CHOICES = []
for sponsor in Sponsor.objects.filter(active=True):
SPONSOR_CHOICES.append((sponsor, sponsor))
# we also need event title and url for our email
event_title = response['event']['title']
event_url = response['event']['url']
# If form is valid, process form and generate discount
if request.method == "POST":
form = SponsorPassesForm(request.POST, tickets=TICKET_CHOICES, sponsors=SPONSOR_CHOICES)
if form.is_valid():
sponsor = form.cleaned_data["sponsor"]
ticket_names = form.cleaned_data["ticket_names"]
amount_off = form.cleaned_data["amount_off"]
percent_off = form.cleaned_data["percent_off"]
# match selected ticket types to ticket ids from our dict
tickets_list = ','.join(str(v) for k, v in ticket_dict.iteritems() if k in ticket_names)
# Eventbrite will only accept one of the following: amount_off or percent_off
# Create variables to pass into our request one or other depending on staff input
if amount_off != None and percent_off == None:
discount_n = 'amount_off'
discount_v = amount_off
elif percent_off != None and amount_off == None:
discount_n = 'percent_off'
discount_v = percent_off
# Generate discount code
discount_code = (sponsor[:6] + '_' + event_title[:6]).replace(' ', '')
# Alert user if discount already exists
# Except case where no discounts exist to check against
try:
response = eb_client.event_list_discounts({
'id': eb_event_id
})
for dsct in response['discounts']:
discount = dsct['discount']
if discount['code'] == discount_code:
messages.error(request, "Oops, looks like that discount code already exists")
return redirect("sponsor_passes")
except EnvironmentError:
response = ''
pass
# Send request to eventbrite to register the discount code w/params
response = eb_client.discount_new({
'event_id': eb_event_id,
'code': discount_code,
discount_n : discount_v,
'quantity_available': int(form.cleaned_data["number_of_passes"]),
'tickets': tickets_list
})
# Auto-email to sponsor contact with discount code
for spsr in Sponsor.objects.filter(name = sponsor):
contact_name = spsr.contact_name
contact_email = spsr.contact_email
event_email = settings.EVENT_EMAIL
event_phone = settings.EVENT_PHONE
message_ctx = {
"event_name": event_title,
"sponsor": sponsor,
"contact_name": contact_name,
"discount_code": discount_code,
"event_url": event_url,
"event_contact_email": event_email,
"event_contact_phone": event_phone
}
send_email(
[contact_email], "sponsor_passes",
context = message_ctx
)
messages.success(request, "Discount code was generated and has been emailed to sponsor contact")
return redirect("dashboard")
else:
form = SponsorPassesForm(sponsors=SPONSOR_CHOICES, tickets=TICKET_CHOICES)
return render_to_response("sponsorship/passes.html", {
"form": form,
}, context_instance=RequestContext(request))
示例12: review_detail
def review_detail(request, pk):
proposals = ProposalBase.objects.select_related("result").select_subclasses()
proposal = get_object_or_404(proposals, pk=pk)
if not request.user.has_perm("reviews.can_review_%s" % proposal.kind.section.slug):
return access_not_permitted(request)
speakers = [s.user for s in proposal.speakers()]
if not request.user.is_superuser and request.user in speakers:
return access_not_permitted(request)
admin = request.user.is_staff
try:
latest_vote = LatestVote.objects.get(proposal=proposal, user=request.user)
except LatestVote.DoesNotExist:
latest_vote = None
if request.method == "POST":
if request.user in speakers:
return access_not_permitted(request)
if "vote_submit" in request.POST:
review_form = ReviewForm(request.POST)
if review_form.is_valid():
review = review_form.save(commit=False)
review.user = request.user
review.proposal = proposal
review.save()
return redirect(request.path)
else:
message_form = SpeakerCommentForm()
elif "message_submit" in request.POST:
message_form = SpeakerCommentForm(request.POST)
if message_form.is_valid():
message = message_form.save(commit=False)
message.user = request.user
message.proposal = proposal
message.save()
for speaker in speakers:
if speaker and speaker.email:
ctx = {
"proposal": proposal,
"message": message,
"reviewer": False,
}
send_email(
[speaker.email], "proposal_new_message",
context=ctx
)
return redirect(request.path)
else:
initial = {}
if latest_vote:
initial["vote"] = latest_vote.vote
if request.user in speakers:
review_form = None
else:
review_form = ReviewForm(initial=initial)
elif "result_submit" in request.POST:
if admin:
result = request.POST["result_submit"]
if result == "accept":
proposal.result.status = "accepted"
proposal.result.save()
elif result == "reject":
proposal.result.status = "rejected"
proposal.result.save()
elif result == "undecide":
proposal.result.status = "undecided"
proposal.result.save()
elif result == "standby":
proposal.result.status = "standby"
proposal.result.save()
return redirect(request.path)
else:
initial = {}
if latest_vote:
initial["vote"] = latest_vote.vote
if request.user in speakers:
review_form = None
else:
review_form = ReviewForm(initial=initial)
message_form = SpeakerCommentForm()
proposal.comment_count = proposal.result.comment_count
proposal.total_votes = proposal.result.vote_count
proposal.plus_one = proposal.result.plus_one
proposal.plus_zero = proposal.result.plus_zero
proposal.minus_zero = proposal.result.minus_zero
proposal.minus_one = proposal.result.minus_one
#.........这里部分代码省略.........
示例13: review_detail
def review_detail(request, pk):
proposals = Proposal.objects.select_related("result")
proposal = get_object_or_404(proposals, pk=pk)
admin = request.user.groups.filter(name="reviewers-admins").exists()
speakers = [s.user for s in proposal.speakers()]
if proposal.kind.name.lower() == "tutorial":
if not request.user.groups.filter(name="reviewers-tutorials").exists():
return access_not_permitted(request)
else:
if not request.user.groups.filter(name="reviewers").exists():
return access_not_permitted(request)
if not admin and request.user in speakers:
return access_not_permitted(request)
try:
latest_vote = LatestVote.objects.get(proposal=proposal, user=request.user)
except LatestVote.DoesNotExist:
latest_vote = None
if request.method == "POST":
if request.user in speakers:
return access_not_permitted(request)
if hasattr(proposal, "invited") and proposal.invited:
return access_not_permitted(request)
if "vote_submit" in request.POST:
review_form = ReviewForm(request.POST)
if review_form.is_valid():
review = review_form.save(commit=False)
review.user = request.user
review.proposal = proposal
review.save()
return redirect(request.path)
else:
message_form = SpeakerCommentForm()
elif "message_submit" in request.POST:
message_form = SpeakerCommentForm(request.POST)
if message_form.is_valid():
message = message_form.save(commit=False)
message.user = request.user
message.proposal = proposal
message.save()
for speaker in speakers:
if speaker and speaker.email:
ctx = {
"proposal": proposal,
"message": message,
"reviewer": False,
}
send_email(
[speaker.email], "proposal_new_message",
context = ctx
)
return redirect(request.path)
elif "result_submit" in request.POST:
if admin:
result = request.POST["result_submit"]
if result == "accept":
proposal.result.accepted = True
proposal.result.save()
elif result == "reject":
proposal.result.accepted = False
proposal.result.save()
elif result == "undecide":
proposal.result.accepted = None
proposal.result.save()
return redirect(request.path)
else:
initial = {}
if latest_vote:
initial["vote"] = latest_vote.vote
if request.user in speakers:
review_form = None
else:
review_form = ReviewForm(initial=initial)
message_form = SpeakerCommentForm()
proposal.comment_count = proposal.result.comment_count
proposal.total_votes = proposal.result.vote_count
proposal.plus_one = proposal.result.plus_one
proposal.plus_zero = proposal.result.plus_zero
proposal.minus_zero = proposal.result.minus_zero
proposal.minus_one = proposal.result.minus_one
reviews = Review.objects.filter(proposal=proposal).order_by("-submitted_at")
return render_to_response("review/review_detail.html", {
"proposal": proposal,
"latest_vote": latest_vote,
"reviews": reviews,
#.........这里部分代码省略.........
示例14: send_coordinator_emails
def send_coordinator_emails(self):
for user in User.objects.filter(groups__name=SPONSOR_COORDINATORS):
send_email(
[user.email], "sponsor_signup",
context = {"sponsor": self}
)