Esempio n. 1
0
    def test_get_newsletter_top_links(self):
        stats = get_newsletter_top_links(self.status)
        self.assertEquals(stats['top_links'], [])

        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            link=self.links[0],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            link=self.links[0],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            link=self.links[1],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[1],
                                            link=self.links[0],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[2],
                                            link=self.links[0],
                                            status=ContactMailingStatus.LINK_OPENED)
        status = ContactMailingStatus.objects.filter(newsletter=self.newsletter)

        stats = get_newsletter_top_links(status)
        self.assertEquals(len(stats['top_links']), 2)
        self.assertEquals(stats['top_links'][0]['link'], self.links[0])
        self.assertEquals(stats['top_links'][0]['total_clicks'], 4)
        self.assertEquals(stats['top_links'][0]['unique_clicks'], 3)
        self.assertEquals(stats['top_links'][1]['link'], self.links[1])
        self.assertEquals(stats['top_links'][1]['total_clicks'], 1)
        self.assertEquals(stats['top_links'][1]['unique_clicks'], 1)
Esempio n. 2
0
    def test_get_newsletter_top_links(self):
        stats = get_newsletter_top_links(self.status)
        self.assertEquals(stats['top_links'], [])

        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            link=self.links[0],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            link=self.links[0],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            link=self.links[1],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[1],
                                            link=self.links[0],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[2],
                                            link=self.links[0],
                                            status=ContactMailingStatus.LINK_OPENED)
        status = ContactMailingStatus.objects.filter(newsletter=self.newsletter)

        stats = get_newsletter_top_links(status)
        self.assertEquals(len(stats['top_links']), 2)
        self.assertEquals(stats['top_links'][0]['link'], self.links[0])
        self.assertEquals(stats['top_links'][0]['total_clicks'], 4)
        self.assertEquals(stats['top_links'][0]['unique_clicks'], 3)
        self.assertEquals(stats['top_links'][1]['link'], self.links[1])
        self.assertEquals(stats['top_links'][1]['total_clicks'], 1)
        self.assertEquals(stats['top_links'][1]['unique_clicks'], 1)
def view_newsletter_density(request, slug):
    newsletter = get_object_or_404(Newsletter, slug=slug)
    status = ContactMailingStatus.objects.filter(newsletter=newsletter,
                                                 creation_date__gte=newsletter.sending_date)
    context = {'object': newsletter,
               'top_links': get_newsletter_top_links(status)['top_links']}

    return render_to_response('newsletter/newsletter_density.html',
                              context, context_instance=RequestContext(request))
Esempio n. 4
0
def view_newsletter_density(request, slug):
    newsletter = get_object_or_404(Newsletter, slug=slug)
    status = ContactMailingStatus.objects.filter(
        newsletter=newsletter, creation_date__gte=newsletter.sending_date)
    context = {
        'object': newsletter,
        'top_links': get_newsletter_top_links(status)['top_links']
    }

    return render('newsletter/newsletter_density.html', context)