当前位置: 首页>>代码示例>>Python>>正文


Python mail.send_mail_template函数代码示例

本文整理汇总了Python中utils.mail.send_mail_template函数的典型用法代码示例。如果您正苦于以下问题:Python send_mail_template函数的具体用法?Python send_mail_template怎么用?Python send_mail_template使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了send_mail_template函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save

    def save(self):
        new_sources = self.cleaned_data["sources"]
        old_sources = set(source["id"] for source in self.sound.sources.all().values("id"))
        try:
            new_sources.remove(self.sound.id)  # stop the universe from collapsing :-D
        except KeyError:
            pass

        for sid in old_sources - new_sources:  # in old but not in new
            try:
                source = Sound.objects.get(id=sid)
                self.sound.sources.remove(source)

                # modify remix_group
                send_mail_template(
                    u"Sound removed as remix source",
                    "sounds/email_remix_update.txt",
                    {"source": source, "action": "removed", "remix": self.sound},
                    None,
                    source.user.email,
                )
            except Sound.DoesNotExist:
                pass
            except Exception, e:
                # Report any other type of exception and fail silently
                print("Problem removing source from remix or sending mail: %s" % e)
开发者ID:takuya1981,项目名称:freesound,代码行数:26,代码来源:forms.py

示例2: flag_user

def flag_user(request, username=None):
    if request.POST:
        flagged_user = User.objects.get(username__iexact=request.POST["username"])
        reporting_user = request.user
        object_id = request.POST["object_id"]
        if object_id:
            if request.POST["flag_type"] == "PM":
                flagged_object = Message.objects.get(id = object_id)
            elif request.POST["flag_type"] == "FP":
                flagged_object = Post.objects.get(id = object_id)
            elif request.POST["flag_type"] == "SC":
                flagged_object = Comment.objects.get(id = object_id)
            else:
                return HttpResponse(json.dumps({"errors":True}), mimetype='application/javascript')
        else:
            return HttpResponse(json.dumps({"errors":True}), mimetype='application/javascript')

        previous_reports_count = UserFlag.objects.filter(user__username=flagged_user.username)\
            .values('reporting_user').distinct().count()
        uflag = UserFlag(user=flagged_user, reporting_user=reporting_user, content_object=flagged_object)
        uflag.save()

        reports_count = UserFlag.objects.filter(user__username = flagged_user.username)\
            .values('reporting_user').distinct().count()
        if reports_count != previous_reports_count and \
                (reports_count == settings.USERFLAG_THRESHOLD_FOR_NOTIFICATION or
                 reports_count == settings.USERFLAG_THRESHOLD_FOR_AUTOMATIC_BLOCKING):

            # Get all flagged objects by the user, create links to admin pages and send email
            flagged_objects = UserFlag.objects.filter(user__username=flagged_user.username)
            urls = []
            added_objects = []
            for f_object in flagged_objects:
                key = str(f_object.content_type) + str(f_object.object_id)
                if key not in added_objects:
                    added_objects.append(key)
                    try:
                        obj = f_object.content_type.get_object_for_this_type(id=f_object.object_id)
                        url = reverse('admin:%s_%s_change' %
                                      (obj._meta.app_label,  obj._meta.module_name), args=[obj.id])
                        urls.append([str(f_object.content_type), request.build_absolute_uri(url)])
                    except Exception:
                        urls.append([str(f_object.content_type), "url not available"])
            user_url = reverse('admin:%s_%s_delete' %
                               (flagged_user._meta.app_label, flagged_user._meta.module_name), args=[flagged_user.id])
            user_url = request.build_absolute_uri(user_url)
            clear_url = reverse("clear-flags-user", args=[flagged_user.username])
            clear_url = request.build_absolute_uri(clear_url)
            if reports_count < settings.USERFLAG_THRESHOLD_FOR_AUTOMATIC_BLOCKING:
                template_to_use = 'accounts/report_spammer_admins.txt'
            else:
                template_to_use = 'accounts/report_blocked_spammer_admins.txt'
            to_emails = []
            for mail in settings.ADMINS:
                to_emails.append(mail[1])
            send_mail_template(u'Spam report for user ' + flagged_user.username,
                               template_to_use, locals(), None, to_emails)
        return HttpResponse(json.dumps({"errors": None}), mimetype='application/javascript')
    else:
        return HttpResponse(json.dumps({"errors": True}), mimetype='application/javascript')
开发者ID:oriolromani,项目名称:freesound,代码行数:60,代码来源:views.py

示例3: contact

def contact(request):
    email_sent = False
    user = None
    
    if request.user.is_authenticated():
        user = request.user 

    if request.POST:
        form = ContactForm(request, request.POST)
        if form.is_valid():
            subject = u"[support] " + form.cleaned_data['subject']
            email_from = form.cleaned_data['your_email']
            message = form.cleaned_data['message']

            # append some useful admin information to the email:
            if not user:
                try:
                    user = User.objects.get(email__iexact=email_from)
                except User.DoesNotExist: #@UndefinedVariable
                    pass
            
            send_mail_template(subject, "support/email_support.txt", locals(), email_from)

            email_sent = True
    else:
        if user:
            form = ContactForm(request, initial={"your_email": user.email})
        else:
            form = ContactForm(request)

    return render_to_response('support/contact.html', locals(), context_instance=RequestContext(request))
开发者ID:darad,项目名称:freesound,代码行数:31,代码来源:views.py

示例4: flag

def flag(request, username, sound_id):
    sound = get_object_or_404(Sound, user__username__iexact=username, id=sound_id, moderation_state="OK", processing_state="OK")

    user = None
    email = None
    if request.user.is_authenticated():
        user = request.user
        email = request.user.email

    if request.method == "POST":
        flag_form = FlagForm(request, request.POST)
        if flag_form.is_valid():
            flag = flag_form.save()
            flag.reporting_user=user
            flag.sound = sound
            flag.save()

            send_mail_template(u"[flag] flagged file", "sounds/email_flag.txt", dict(flag=flag), flag.email)

            return HttpResponseRedirect(sound.get_absolute_url())
    else:
        if user:
            flag_form = FlagForm(request,initial=dict(email=email))
        else:
            flag_form = FlagForm(request)

    return render_to_response('sounds/sound_flag.html', locals(), context_instance=RequestContext(request))
开发者ID:digitalzoomstudio,项目名称:freesound,代码行数:27,代码来源:views.py

示例5: sound

def sound(request, username, sound_id):
    try:
        sound = Sound.objects.select_related("license", "user", "user__profile", "pack", "remix_group").get(id=sound_id)
        if sound.user.username.lower() != username.lower():
            raise Http404
        user_is_owner = request.user.is_authenticated() and (
            sound.user == request.user
            or request.user.is_superuser
            or request.user.is_staff
            or Group.objects.get(name="moderators") in request.user.groups.all()
        )
        # If the user is authenticated and this file is his, don't worry about moderation_state and processing_state
        if user_is_owner:
            if sound.moderation_state != "OK":
                messages.add_message(request, messages.INFO, "Be advised, this file has <b>not been moderated</b> yet.")
            if sound.processing_state != "OK":
                messages.add_message(request, messages.INFO, "Be advised, this file has <b>not been processed</b> yet.")
        else:
            if sound.moderation_state != "OK" or sound.processing_state != "OK":
                raise Http404
    except Sound.DoesNotExist:  # @UndefinedVariable
        try:
            DeletedSound.objects.get(sound_id=sound_id)
            return render_to_response("sounds/deleted_sound.html", {}, context_instance=RequestContext(request))
        except DeletedSound.DoesNotExist:
            raise Http404

    tags = sound.tags.select_related("tag__name")

    if request.method == "POST":
        form = CommentForm(request, request.POST)
        if request.user.profile.is_blocked_for_spam_reports():
            messages.add_message(
                request,
                messages.INFO,
                "You're not allowed to post the comment because your account has been temporaly blocked after multiple spam reports",
            )
        else:
            if form.is_valid():
                comment_text = form.cleaned_data["comment"]
                sound.comments.add(Comment(content_object=sound, user=request.user, comment=comment_text))
                sound.num_comments = sound.num_comments + 1
                sound.save()
                try:
                    # send the user an email to notify him of the new comment!
                    logger.debug(
                        "Notifying user %s of a new comment by %s" % (sound.user.username, request.user.username)
                    )
                    send_mail_template(
                        u"You have a new comment.",
                        "sounds/email_new_comment.txt",
                        {"sound": sound, "user": request.user, "comment": comment_text},
                        None,
                        sound.user.email,
                    )
                except Exception, e:
                    # if the email sending fails, ignore...
                    logger.error("Problem sending email to '%s' about new comment: %s" % (request.user.email, e))

                return HttpResponseRedirect(sound.get_absolute_url())
开发者ID:yanomamo,项目名称:freesound,代码行数:60,代码来源:views.py

示例6: contact

def contact(request):
    email_sent = False
    user = None
    
    if request.user.is_authenticated():
        user = request.user 

    if request.POST:
        form = ContactForm(request, request.POST)
        if form.is_valid():
            subject = u"[support] " + form.cleaned_data['subject']
            email_from = settings.DEFAULT_FROM_EMAIL
            message = form.cleaned_data['message']
            # append some useful admin information to the email:
            if not user:
                try:
                    user = User.objects.get(email__iexact=form.cleaned_data['your_email'])
                except User.DoesNotExist:
                    pass
            send_mail_template(subject, "support/email_support.txt", locals(), email_from,
                               reply_to=form.cleaned_data['your_email'])
            email_sent = True
    else:
        if user:
            form = ContactForm(request, initial={"your_email": user.email})
        else:
            form = ContactForm(request)
    tvars = {'form': form, 'email_sent': email_sent}
    return render(request, 'support/contact.html', tvars)
开发者ID:giuband,项目名称:freesound,代码行数:29,代码来源:views.py

示例7: save

    def save(self):
        #print "before save", ",".join([str(source.id) for source in self.sound.sources.all()])

        new_sources = self.cleaned_data['sources']

        old_sources = set(source["id"] for source in self.sound.sources.all().values("id"))

        try:
            new_sources.remove(self.sound.id) # stop the universe from collapsing :-D
        except KeyError:
            pass

        for id in old_sources - new_sources: # in old but not in new
            try:
                source = Sound.objects.get(id=id)
                self.sound.sources.remove(source)
                
                # modify remix_group
                
                
                send_mail_template(
                    u'Sound removed as remix source', 'sounds/email_remix_update.txt',
                    {'source': source, 'action': 'removed', 'remix': self.sound},
                    None, source.user.email
                )
            except Sound.DoesNotExist:
                pass
            except Exception, e:
                # Report any other type of exception and fail silently
                print ("Problem removing source from remix or sending mail: %s" \
                     % e)
开发者ID:LoodVogel,项目名称:freesound,代码行数:31,代码来源:forms.py

示例8: send_activation

def send_activation(user):
    uid_hash = create_hash(user.id)
    username = user.username
    tvars = {
        'user': user,
        'username': username,
        'hash': uid_hash
    }
    send_mail_template(u'activation link.', 'accounts/email_activation.txt', tvars, None, user.email)
开发者ID:oriolromani,项目名称:freesound,代码行数:9,代码来源:views.py

示例9: _save_donation

def _save_donation(encoded_data, email, amount, currency, transaction_id, source):
    extra_data = json.loads(base64.b64decode(encoded_data))
    campaign = DonationCampaign.objects.get(id=extra_data['campaign_id'])
    is_anonymous = False
    user = None
    user_id = None
    display_name = None

    if 'user_id' in extra_data:
        user = User.objects.get(id=extra_data['user_id'])
        user_id = user.id
        email = user.profile.get_email_for_delivery()
        # Reset the reminder flag to False so that in a year time user is reminded to donate
        user.profile.donations_reminder_email_sent = False
        user.profile.save()

    if 'name' in extra_data:
        is_anonymous = True
        display_name = extra_data['name']

    donation_data = {
        'email': email,
        'display_name': display_name,
        'amount': amount,
        'currency': currency,
        'display_amount': extra_data['display_amount'],
        'is_anonymous': is_anonymous,
        'user': user,
        'campaign': campaign,
        'source': source
    }
    donation, created = Donation.objects.get_or_create(transaction_id=transaction_id, defaults=donation_data)

    if created:
        email_to = None if user is not None else email
        send_mail_template(
                u'Thanks for your donation!',
                'donations/email_donation.txt', {
                    'user': user,
                    'amount': amount,
                    'display_name': display_name
                    }, user_to=user, email_to=email_to)

        log_data = donation_data
        log_data.update({'user_id': user_id})
        log_data.update({'created': str(donation.created)})
        del log_data['user']  # Don't want to serialize user
        del log_data['campaign']  # Don't want to serialize campaign
        log_data['amount_float'] = float(log_data['amount'])
        logger.info('Recevied donation (%s)' % json.dumps(log_data))
    return True
开发者ID:MTG,项目名称:freesound,代码行数:51,代码来源:views.py

示例10: username_reminder

def username_reminder(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse("accounts-home"))

    if request.method == "POST":
        form = UsernameReminderForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data["user"]
            send_mail_template(u'username reminder.', 'accounts/email_username_reminder.txt', dict(user=user), None, user.email)

            return render_to_response('accounts/username_reminder.html', dict(form=form, sent=True), context_instance=RequestContext(request))
    else:
        form = UsernameReminderForm()

    return render_to_response('accounts/username_reminder.html', dict(form=form, sent=False), context_instance=RequestContext(request))
开发者ID:djzikario,项目名称:freesound,代码行数:15,代码来源:views.py

示例11: username_reminder

def username_reminder(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('accounts-home'))

    if request.method == 'POST':
        form = UsernameReminderForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data['user']
            send_mail_template(u'username reminder.', 'accounts/email_username_reminder.txt', {'user': user},
                               None, user.email)

            return render(request, 'accounts/username_reminder.html', {'form': form, 'sent': True})
    else:
        form = UsernameReminderForm()

    return render(request, 'accounts/username_reminder.html', {'form': form, 'sent': False})
开发者ID:oriolromani,项目名称:freesound,代码行数:16,代码来源:views.py

示例12: username_reminder

def username_reminder(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse("accounts-home"))

    if request.method == "POST":
        form = UsernameReminderForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data["user"]
            send_mail_template(
                u"username reminder.", "accounts/email_username_reminder.txt", {"user": user}, None, user.email
            )

            return render(request, "accounts/username_reminder.html", {"form": form, "sent": True})
    else:
        form = UsernameReminderForm()

    return render(request, "accounts/username_reminder.html", {"form": form, "sent": False})
开发者ID:harish211,项目名称:freesound,代码行数:17,代码来源:views.py

示例13: send_notification_emails

 def send_notification_emails(self, notification_type, sender_moderator):
     # send message to assigned moderator
     if sender_moderator in [Ticket.MODERATOR_ONLY, Ticket.USER_AND_MODERATOR]:
         if self.assignee:
             tvars = {'ticket': self,
                      'user_to': self.assignee}
             send_mail_template(u'A freesound moderator handled your upload.',
                                notification_type,
                                tvars,
                                user_to=self.assignee)
     # send message to user
     if sender_moderator in [Ticket.USER_ONLY, Ticket.USER_AND_MODERATOR]:
         if self.sender:
             tvars = {'ticket': self,
                      'user_to': self.sender}
             send_mail_template(u'A freesound moderator handled your upload.',
                                notification_type,
                                tvars,
                                user_to=self.sender)
开发者ID:MTG,项目名称:freesound,代码行数:19,代码来源:models.py

示例14: save

    def save(self):
        new_sources = self.cleaned_data['sources']
        old_sources = set(source["id"] for source in self.sound.sources.all().values("id"))
        try:
            new_sources.remove(self.sound.id)  # stop the universe from collapsing :-D
        except KeyError:
            pass

        for sid in old_sources - new_sources:  # in old but not in new
            try:
                source = Sound.objects.get(id=sid)
                self.sound.sources.remove(source)

                source.invalidate_template_caches()

                # modify remix_group
                send_mail_template(
                    u'Sound removed as remix source', 'sounds/email_remix_update.txt',
                    {'source': source, 'action': 'removed', 'remix': self.sound},
                    user_to=source.user
                )
            except Sound.DoesNotExist:
                pass
            except Exception as e:
                # Report any other type of exception and fail silently
                print ("Problem removing source from remix or sending mail: %s" % e)

        for sid in new_sources - old_sources:  # in new but not in old
            source = Sound.objects.get(id=sid)

            source.invalidate_template_caches()

            self.sound.sources.add(source)
            try:
                send_mail_template(
                    u'Sound added as remix source', 'sounds/email_remix_update.txt',
                    {'source': source, 'action': 'added', 'remix': self.sound},
                    user_to=source.user
                )
            except Exception as e:
                # Report any exception but fail silently
                print ("Problem sending mail about source added to remix: %s" % e)
开发者ID:MTG,项目名称:freesound,代码行数:42,代码来源:forms.py

示例15: send_notification_emails

 def send_notification_emails(self, notification_type, sender_moderator):
     ticket = self
     send_to = []
     #send message to assigned moderator
     if sender_moderator in [Ticket.MODERATOR_ONLY, Ticket.USER_AND_MODERATOR]:
         if self.assignee:
             user_to = self.assignee if self.assignee else False
             send_mail_template(u'A freesound moderator handled your upload.',
                                notification_type,
                                locals(),
                                '[email protected]',
                                self.assignee.email)
     # send message to user
     if sender_moderator in [Ticket.USER_ONLY, Ticket.USER_AND_MODERATOR]:
         user_to = self.sender if self.sender else False
         email_to = user_to.email if user_to else ticket.sender_email
         if self.sender:
             send_mail_template(u'A freesound moderator handled your upload.',
                                notification_type,
                                locals(),
                                '[email protected]',
                                email_to)
开发者ID:LoodVogel,项目名称:freesound,代码行数:22,代码来源:models.py


注:本文中的utils.mail.send_mail_template函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。