From 1594a78ab13266d8e1f3bfa04d115aea96c4db21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Fri, 12 Jan 2024 00:58:20 +0200 Subject: [PATCH] wip: geoip --- app/e11sync/settings.py | 5 +++++ app/signup/admin.py | 2 +- app/signup/models.py | 6 ++++++ flake.nix | 8 ++++---- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/e11sync/settings.py b/app/e11sync/settings.py index 886a117..8964884 100644 --- a/app/e11sync/settings.py +++ b/app/e11sync/settings.py @@ -1,4 +1,5 @@ from pathlib import Path +from os import environ # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -124,3 +125,7 @@ LOGGING = { "level": "WARNING", }, } + +#GEOIP_PATH = environ["GEOIP_PATH"] +#GEOIP_COUNTRY = "GeoIP.dat" +#GEOIP_CITY = "GeoIPCity.dat" diff --git a/app/signup/admin.py b/app/signup/admin.py index 47fbfec..9e76a83 100644 --- a/app/signup/admin.py +++ b/app/signup/admin.py @@ -7,7 +7,7 @@ class SignupAdmin(admin.ModelAdmin): _all_fields = ["email", "created_at", "anonymized_ip", "user_agent"] date_hierarchy = "created_at" - list_display = ["email", "created_at", "anonymized_ip", "user_agent"] + list_display = ["email", "created_at", "anonymized_ip", "user_agent"]# + ["country"] list_filter = ["email", "user_agent"] ordering = ["created_at"] readonly_fields = _all_fields diff --git a/app/signup/models.py b/app/signup/models.py index 053b324..1157761 100644 --- a/app/signup/models.py +++ b/app/signup/models.py @@ -1,5 +1,7 @@ from django.db import models +#from django.contrib.gis.geoip2 import GeoIP2 + class Signup(models.Model): email = models.EmailField() created_at = models.DateTimeField(auto_now_add = True) @@ -13,3 +15,7 @@ class Signup(models.Model): def __str__(self): return self.email + + #def country(self): + # g = GeoIP2() + # return g.country(self.anonymized_ip) diff --git a/flake.nix b/flake.nix index 5c18893..192f4b2 100644 --- a/flake.nix +++ b/flake.nix @@ -22,14 +22,14 @@ python3Packages.django-compressor dart-sass - hugo - brotli - zopfli - parallel + geoipWithDatabase + python3Packages.geoip2 + libmaxminddb ]; in { devShells.default = pkgs.mkShell { LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; + GEOIP_PATH = "${pkgs.geolite-legacy}/share/GeoIP"; packages = devDeps; };