Commit f77be91f authored by fred's avatar fred

store ip and user agent for stats

parent bc1fd6d8
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2021-01-31 17:21
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('newsletter', '0004_auto_20210131_1714'),
]
operations = [
migrations.AddField(
model_name='subscriber',
name='source_ip',
field=models.CharField(blank=True, max_length=100),
),
migrations.AddField(
model_name='subscriber',
name='user_agent',
field=models.CharField(blank=True, max_length=1000),
),
]
......@@ -35,6 +35,8 @@ class Subscriber(models.Model) :
password = models.CharField(max_length=100)
bot_check1 = models.BooleanField(default=False)
bot_check2 = models.BooleanField(default=False)
user_agent = models.CharField(max_length=1000, blank=True)
source_ip = models.CharField(max_length=100, blank=True)
def __unicode__(self) :
return self.email
......
......@@ -38,6 +38,13 @@ class SubscribeView(CreateView):
# but redirect to success page nevertheless
self.object.bot_check1 = bool('validation' in self.request.POST)
self.object.bot_check2 = bool('validation2' not in self.request.POST)
# keep various data, for bot stats
self.object.source_ip = (
self.request.META.get('HTTP_X_FORWARDED_FOR') or
self.request.META.get('HTTP_X_REAL_IP') or
self.request.META.get('REMOTE_ADDR'))
self.object.user_agent = self.request.META.get('HTTP_USER_AGENT')
self.object.save()
if not self.object.is_from_bot():
self.object.send_confirmation_email()
return resp
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment