コード例 #1
0
ファイル: admin.py プロジェクト: Feowl/API
    def send_voucher(self, request):
        if request.method == 'POST':  # If the form has been submitted...
            form = VoucherForm(request.POST)  # A form bound to the POST data
            if form.is_valid():  # All validation rules pass
                mobile_numbers = form.cleaned_data['mobile_numbers']
                voucher_text = form.cleaned_data['voucher_text']

                mobile_numbers_list = [x.strip() for x in mobile_numbers.split(',')]

                for number in mobile_numbers_list:
                    send_sms(number, voucher_text)
                return HttpResponseRedirect('..')
        else:
            form = VoucherForm()  # An unbound form

        fieldsets = [(None, {'fields': form.base_fields.keys()})]
        adminForm = admin.helpers.AdminForm(form, fieldsets, {})

        context = {
            'adminForm': adminForm,
            'form': form,
            'is_popup': '_popup' in request.REQUEST,
            'add': True,
            'change': False,
            'has_delete_permission': False,
            'has_change_permission': True,
            'has_absolute_url': False,
            'opts': self.model._meta,
            'save_as': False,
            'show_save': True,
        }
        return TemplateResponse(request, 'admin/send_voucher.html',
            context, current_app=self.admin_site.name)
コード例 #2
0
ファイル: newsletter.py プロジェクト: Feowl/API
    def handle(self, *args, **options):
        limit = options.get("limit")
        frequency = options.get("frequency")

        contributors = Contributor.objects.filter(status=Contributor.ACTIVE, frequency=frequency).exclude(name=settings.ANONYMOUS_USER_NAME).order_by('-enquiry')[:limit]
        messages = []
        plaintext = get_template('email/newsletter.txt')
        html = get_template('email/newsletter.html')
        subject = _('Hello from Feowl')
        connection = get_connection()
        connection.open()
        for i, user in enumerate(contributors):
                if user.channel == EMAIL and is_valid_email(user.email):
                    d = Context({'name': user.name, 'newsletter_language': user.language})
                    text_content = plaintext.render(d)
                    html_content = html.render(d)
                    msg = EmailMultiAlternatives(subject, text_content, settings.NEWSLETTER_FROM, [user.email], connection=connection)
                    msg.attach_alternative(html_content, "text/html")
                    messages.append(msg)
                    logger.info("Poll Email sent to {0}".format(user.email))

                else:
                    if user.channel == SMS:
                        d = Context({'name': user.name, 'newsletter_language': user.language})
                        msg = get_template('sms.txt')
                        content = msg.render(d)
                        try:
                            mobile = Device.objects.get(contributor=user)
                            send_sms(mobile.phone_number, content)
                            logger.info("Poll SMS sent to {0}".format(mobile.phone_number))
                        except:
                            logger.error("Impossible to send an SMS")

                # Update the list of targeted users
                user.enquiry = datetime.today().date()
                user.total_enquiry += 1
                user.save()

        connection.send_messages(messages)
        connection.close()
        logger.info("Poll of {0} sent".format(datetime.today().date()))
コード例 #3
0
ファイル: message_helper.py プロジェクト: Feowl/API
def send_message(mobile_number, message):
        send_sms(mobile_number, message)
コード例 #4
0
ファイル: tests.py プロジェクト: jeanfrancis/JaiSoif-API
    def test_sendSMS(self):
        msg = "hi from feowl"
        bad_phone = "915738710431"
        send_sms(bad_phone, msg)

        good_phone = "4915738710431"