1

signup: add referrer

This commit is contained in:
Motiejus Jakštys 2024-02-27 18:30:20 +02:00
parent 31ff6d5606
commit 429555c4bd
4 changed files with 24 additions and 2 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 5.0.2 on 2024-02-27 16:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('signup', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='signup',
name='referrer',
field=models.CharField(blank=True, max_length=255),
),
]

View File

@ -7,6 +7,7 @@ class Signup(models.Model):
anonymized_ip = models.GenericIPAddressField()
user_agent = models.CharField(max_length=255)
geoip = models.JSONField(null=True, blank=True)
referrer = models.CharField(max_length=255, blank=True)
class Meta:
constraints = [

View File

@ -17,10 +17,12 @@ class SignupViewTest(TestCase):
resp = self.client.post(reverse("index"), {"email": "foo@example.com"},
follow=True,
HTTP_USER_AGENT="foo-agent",
REMOTE_ADDR="127.0.0.2")
REMOTE_ADDR="127.0.0.2",
HTTP_REFERRER="example.org/good-place")
self.assertEqual(resp.redirect_chain, [('/?success=subscribed', 302)])
self.assertContains(resp, "You are now subscribed!")
obj = Signup.objects.get()
self.assertEqual(obj.email, "foo@example.com")
self.assertEqual(obj.anonymized_ip, "127.0.0.0")
self.assertEqual(obj.user_agent, "foo-agent")
self.assertEqual(obj.referrer, "example.org/good-place")

View File

@ -33,8 +33,9 @@ def index(request):
s = Signup(
email=request.POST.get("email"),
anonymized_ip=anonymous_ip,
user_agent=request.META["HTTP_USER_AGENT"],
user_agent=request.META['HTTP_USER_AGENT'],
geoip=geoip,
referrer=request.META.get('HTTP_REFERRER', ''),
)
try: