예제 #1
0
def dashboard(request):
    """
    Graph SES send statistics over time.
    """
    cache_key = 'vhash:django_ses_stats'
    cached_view = cache.get(cache_key)
    if cached_view:
        return cached_view

    region = RegionInfo(name=getattr(settings, 'AWS_SES_REGION_NAME',
                                     SESConnection.DefaultRegionName),
                        endpoint=getattr(settings, 'AWS_SES_REGION_ENDPOINT',
                                         SESConnection.DefaultRegionEndpoint))

    ses_conn = SESConnection(
        aws_access_key_id=getattr(settings, 'AWS_ACCESS_KEY_ID', None),
        aws_secret_access_key=getattr(settings, 'AWS_SECRET_ACCESS_KEY', None),
        region=region)

    quota_dict = ses_conn.get_send_quota()
    verified_emails_dict = ses_conn.list_verified_email_addresses()
    stats = ses_conn.get_send_statistics()

    quota = quota_parse(quota_dict)
    verified_emails = emails_parse(verified_emails_dict)
    ordered_data = stats_to_list(stats)
    summary = sum_stats(ordered_data)

    extra_context = {
        'title':
        'SES Statistics',
        'datapoints':
        ordered_data,
        '24hour_quota':
        quota['Max24HourSend'],
        '24hour_sent':
        quota['SentLast24Hours'],
        '24hour_remaining':
        float(quota['Max24HourSend']) - float(quota['SentLast24Hours']),
        'persecond_rate':
        quota['MaxSendRate'],
        'verified_emails':
        verified_emails,
        'summary':
        summary,
        'access_key':
        ses_conn.gs_access_key_id,
        'local_time':
        True if pytz else False,
    }

    response = render_to_response('django_ses/send_stats.html',
                                  extra_context,
                                  context_instance=RequestContext(request))

    cache.set(cache_key, response, 60 * 15)  # Cache for 15 minutes
    return response
예제 #2
0
def dashboard(request):
    """
    Graph SES send statistics over time.
    """
    cache_key = 'vhash:django_ses_stats'
    cached_view = cache.get(cache_key)
    if cached_view:
        return cached_view

    region = RegionInfo(name=settings.AWS_SES_REGION_NAME,
                        endpoint=settings.AWS_SES_REGION_ENDPOINT)

    ses_conn = SESConnection(
        aws_access_key_id=settings.ACCESS_KEY,
        aws_secret_access_key=settings.SECRET_KEY,
        region=region,
        proxy=settings.AWS_SES_PROXY,
        proxy_port=settings.AWS_SES_PROXY_PORT,
    )

    quota_dict = ses_conn.get_send_quota()
    verified_emails_dict = ses_conn.list_verified_email_addresses()
    stats = ses_conn.get_send_statistics()

    quota = quota_parse(quota_dict)
    verified_emails = emails_parse(verified_emails_dict)
    ordered_data = stats_to_list(stats)
    summary = sum_stats(ordered_data)

    extra_context = {
        'title':
        'SES Statistics',
        'datapoints':
        ordered_data,
        '24hour_quota':
        quota['Max24HourSend'],
        '24hour_sent':
        quota['SentLast24Hours'],
        '24hour_remaining':
        float(quota['Max24HourSend']) - float(quota['SentLast24Hours']),
        'persecond_rate':
        quota['MaxSendRate'],
        'verified_emails':
        verified_emails,
        'summary':
        summary,
        'access_key':
        ses_conn.gs_access_key_id,
        'local_time':
        True,
    }

    response = render(request, 'django_ses/send_stats.html', extra_context)

    cache.set(cache_key, response, 60 * 15)  # Cache for 15 minutes
    return response
예제 #3
0
def dashboard(request):
    """
    Graph SES send statistics over time.
    """
    cache_key = 'vhash:django_ses_stats'
    cached_view = cache.get(cache_key)
    if cached_view:
        return cached_view

    region = RegionInfo(
        name=getattr(settings, 'AWS_SES_REGION_NAME',
            SESConnection.DefaultRegionName),
        endpoint=getattr(settings, 'AWS_SES_REGION_ENDPOINT',
            SESConnection.DefaultRegionEndpoint))

    ses_conn = SESConnection(
        aws_access_key_id=getattr(settings, 'AWS_ACCESS_KEY_ID', None),
        aws_secret_access_key=getattr(settings, 'AWS_SECRET_ACCESS_KEY', None),
        region=region)

    quota_dict = ses_conn.get_send_quota()
    verified_emails_dict = ses_conn.list_verified_email_addresses()
    stats = ses_conn.get_send_statistics()

    quota = quota_parse(quota_dict)
    verified_emails = emails_parse(verified_emails_dict)
    ordered_data = stats_to_list(stats)
    summary = sum_stats(ordered_data)

    extra_context = {
        'title': 'SES Statistics',
        'datapoints': ordered_data,
        '24hour_quota': quota['Max24HourSend'],
        '24hour_sent': quota['SentLast24Hours'],
        '24hour_remaining': float(quota['Max24HourSend']) -
                            float(quota['SentLast24Hours']),
        'persecond_rate': quota['MaxSendRate'],
        'verified_emails': verified_emails,
        'summary': summary,
        'access_key': ses_conn.gs_access_key_id,
        'local_time': True if pytz else False,
    }

    response = render_to_response(
        'django_ses/send_stats.html',
        extra_context,
        context_instance=RequestContext(request))

    cache.set(cache_key, response, 60 * 15)  # Cache for 15 minutes
    return response
예제 #4
0
def dashboard(request):
    """
    Graph SES send statistics over time.
    """
    cache_key = 'vhash:django_ses_stats'
    cached_view = cache.get(cache_key)
    if cached_view:
        return cached_view

    region = RegionInfo(
        name=settings.AWS_SES_REGION_NAME,
        endpoint=settings.AWS_SES_REGION_ENDPOINT)

    ses_conn = SESConnection(
        aws_access_key_id=settings.ACCESS_KEY,
        aws_secret_access_key=settings.SECRET_KEY,
        region=region,
        proxy=settings.AWS_SES_PROXY,
        proxy_port=settings.AWS_SES_PROXY_PORT,
    )

    quota_dict = ses_conn.get_send_quota()
    verified_emails_dict = ses_conn.list_verified_email_addresses()
    stats = ses_conn.get_send_statistics()

    quota = quota_parse(quota_dict)
    verified_emails = emails_parse(verified_emails_dict)
    ordered_data = stats_to_list(stats)
    summary = sum_stats(ordered_data)

    extra_context = {
        'title': 'SES Statistics',
        'datapoints': ordered_data,
        '24hour_quota': quota['Max24HourSend'],
        '24hour_sent': quota['SentLast24Hours'],
        '24hour_remaining': float(quota['Max24HourSend']) -
                            float(quota['SentLast24Hours']),
        'persecond_rate': quota['MaxSendRate'],
        'verified_emails': verified_emails,
        'summary': summary,
        'access_key': ses_conn.gs_access_key_id,
        'local_time': True,
    }

    response = render(request, 'django_ses/send_stats.html', extra_context)

    cache.set(cache_key, response, 60 * 15)  # Cache for 15 minutes
    return response
예제 #5
0
def dashboard(request):
    """
    Graph SES send statistics over time.
    """
    cache_key = "vhash:django_ses_stats"
    cached_view = cache.get(cache_key)
    if cached_view:
        return cached_view

    region = RegionInfo(name=settings.AWS_SES_REGION_NAME, endpoint=settings.AWS_SES_REGION_ENDPOINT)

    ses_conn = SESConnection(
        aws_access_key_id=settings.ACCESS_KEY,
        aws_secret_access_key=settings.SECRET_KEY,
        region=region,
        boto_profile_name=settings.BOTO_PROFILE_NAME,
    )

    quota_dict = ses_conn.get_send_quota()
    verified_emails_dict = ses_conn.list_verified_email_addresses()
    stats = ses_conn.get_send_statistics()

    quota = quota_parse(quota_dict)
    verified_emails = emails_parse(verified_emails_dict)
    ordered_data = stats_to_list(stats)
    summary = sum_stats(ordered_data)

    extra_context = {
        "title": "SES Statistics",
        "datapoints": ordered_data,
        "24hour_quota": quota["Max24HourSend"],
        "24hour_sent": quota["SentLast24Hours"],
        "24hour_remaining": float(quota["Max24HourSend"]) - float(quota["SentLast24Hours"]),
        "persecond_rate": quota["MaxSendRate"],
        "verified_emails": verified_emails,
        "summary": summary,
        "access_key": ses_conn.gs_access_key_id,
        "local_time": True if pytz else False,
    }

    response = render_to_response("django_ses/send_stats.html", extra_context, context_instance=RequestContext(request))

    cache.set(cache_key, response, 60 * 15)  # Cache for 15 minutes
    return response
    def handle(self, *args, **options):

        connection = SESConnection(
            aws_access_key_id=settings.ACCESS_KEY,
            aws_secret_access_key=settings.SECRET_KEY,
            proxy=settings.AWS_SES_PROXY,
            proxy_port=settings.AWS_SES_PROXY_PORT,
            proxy_user=settings.AWS_SES_PROXY_USER,
            proxy_pass=settings.AWS_SES_PROXY_PASS,
        )
        stats = connection.get_send_statistics()
        data_points = stats_to_list(stats, localize=False)
        stats_dict = defaultdict(stat_factory)

        for data in data_points:
            attempts = int(data['DeliveryAttempts'])
            bounces = int(data['Bounces'])
            complaints = int(data['Complaints'])
            rejects = int(data['Rejects'])
            date = data['Timestamp'].split('T')[0]
            stats_dict[date]['delivery_attempts'] += attempts
            stats_dict[date]['bounces'] += bounces
            stats_dict[date]['complaints'] += complaints
            stats_dict[date]['rejects'] += rejects

        for k, v in stats_dict.items():
            stat, created = SESStat.objects.get_or_create(
                date=k,
                defaults={
                    'delivery_attempts': v['delivery_attempts'],
                    'bounces': v['bounces'],
                    'complaints': v['complaints'],
                    'rejects': v['rejects'],
            })

            # If statistic is not new, modify data if values are different
            if not created and stat.delivery_attempts != v['delivery_attempts']:
                stat.delivery_attempts = v['delivery_attempts']
                stat.bounces = v['bounces']
                stat.complaints = v['complaints']
                stat.rejects = v['rejects']
                stat.save()
예제 #7
0
    def handle(self, *args, **options):

        connection = SESConnection(
            aws_access_key_id=settings.ACCESS_KEY,
            aws_secret_access_key=settings.SECRET_KEY,
            proxy=settings.AWS_SES_PROXY,
            proxy_port=settings.AWS_SES_PROXY_PORT,
            proxy_user=settings.AWS_SES_PROXY_USER,
            proxy_pass=settings.AWS_SES_PROXY_PASS,
        )
        stats = connection.get_send_statistics()
        data_points = stats_to_list(stats, localize=False)
        stats_dict = defaultdict(stat_factory)

        for data in data_points:
            attempts = int(data['DeliveryAttempts'])
            bounces = int(data['Bounces'])
            complaints = int(data['Complaints'])
            rejects = int(data['Rejects'])
            date = data['Timestamp'].split('T')[0]
            stats_dict[date]['delivery_attempts'] += attempts
            stats_dict[date]['bounces'] += bounces
            stats_dict[date]['complaints'] += complaints
            stats_dict[date]['rejects'] += rejects

        for k, v in stats_dict.items():
            stat, created = SESStat.objects.get_or_create(
                date=k,
                defaults={
                    'delivery_attempts': v['delivery_attempts'],
                    'bounces': v['bounces'],
                    'complaints': v['complaints'],
                    'rejects': v['rejects'],
                })

            # If statistic is not new, modify data if values are different
            if not created and stat.delivery_attempts != v['delivery_attempts']:
                stat.delivery_attempts = v['delivery_attempts']
                stat.bounces = v['bounces']
                stat.complaints = v['complaints']
                stat.rejects = v['rejects']
                stat.save()
예제 #8
0
    def handle(self, *args, **options):

        connection = SESConnection(
            aws_access_key_id=getattr(settings, "AWS_ACCESS_KEY_ID", None),
            aws_secret_access_key=getattr(settings, "AWS_SECRET_ACCESS_KEY", None),
        )
        stats = connection.get_send_statistics()
        data_points = stats_to_list(stats, localize=False)
        stats_dict = defaultdict(stat_factory)

        for data in data_points:
            attempts = int(data["DeliveryAttempts"])
            bounces = int(data["Bounces"])
            complaints = int(data["Complaints"])
            rejects = int(data["Rejects"])
            date = data["Timestamp"].split("T")[0]
            stats_dict[date]["delivery_attempts"] += attempts
            stats_dict[date]["bounces"] += bounces
            stats_dict[date]["complaints"] += complaints
            stats_dict[date]["rejects"] += rejects

        for k, v in stats_dict.items():
            stat, created = SESStat.objects.get_or_create(
                date=k,
                defaults={
                    "delivery_attempts": v["delivery_attempts"],
                    "bounces": v["bounces"],
                    "complaints": v["complaints"],
                    "rejects": v["rejects"],
                },
            )

            # If statistic is not new, modify data if values are different
            if not created and stat.delivery_attempts != v["delivery_attempts"]:
                stat.delivery_attempts = v["delivery_attempts"]
                stat.bounces = v["bounces"]
                stat.complaints = v["complaints"]
                stat.rejects = v["rejects"]
                stat.save()