Пример #1
0
    def change_view(self, request, object_id, form_url = '', extra_context=None):
        get_placeholders(request)

        click_data = clicks_for_ad(object_id)

        month_list = Click.objects.filter(ad__pk=object_id).dates('datetime', 'month')

        extra_context = {'clicks': click_data['clicks'], 'start_date': click_data['start'], 'end_date': click_data['end'], 'month_list': month_list }

        return super(AdvertisementAdmin, self).change_view(request, object_id, form_url, extra_context)
Пример #2
0
def ad_click_by_month(request, ad_id, date):
    date = datetime.datetime.strptime(date, "%m-%Y")

    click_data = clicks_for_ad(ad_id, date)

    data = {
        "clicks": click_data["clicks"],
        "start_date": click_data["start"].strftime("%Y/%m/%d"),
        "end_date": click_data["end"].strftime("%Y/%m/%d"),
    }

    return HttpResponse(simplejson.dumps(data), mimetype="application/json")
Пример #3
0
def campaign_click_by_month(request, campaign_id, date):
    date = datetime.datetime.strptime(date, "%m-%Y")

    campaign = Campaign.objects.get(pk=campaign_id)

    campaign_data = {}
    for ad in campaign.ad.all():
        ad_data = {}
        clicks = clicks_for_ad(ad.pk, date)
        ad_data["data"] = clicks["clicks"]
        ad_data["label"] = ad.title

        start_date = date.replace(day=1)
        end_date = start_date + datetime.timedelta(days=31)
        end_date.replace(day=1)

        ad_data["start"] = start_date.strftime("%Y/%m/%d")
        ad_data["end"] = end_date.strftime("%Y/%m/%d")

        campaign_data[ad.title] = ad_data

    return HttpResponse(simplejson.dumps(campaign_data), mimetype="application/json")