diff --git a/app/e11sync/settings.py b/app/e11sync/settings.py index 350b95b..f3f046d 100644 --- a/app/e11sync/settings.py +++ b/app/e11sync/settings.py @@ -34,8 +34,8 @@ if not environ.get("E11SYNC_DEBUG_PRINTED"): print("DATABASE_PATH={}".format(_DATABASE_PATH)) environ["E11SYNC_DEBUG_PRINTED"] = "1" -######################################## -## No more side effects after this place +####################################### +# No more side effects after this place SECRET_KEY = _SECRET_KEY @@ -50,7 +50,7 @@ INTERNAL_IPS = ["127.0.0.1"] INSTALLED_APPS = (['debug_toolbar'] if DEBUG else []) + [ 'compressor', 'signup.apps.SignupConfig', - + 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/app/e11sync/urls.py b/app/e11sync/urls.py index 951d390..30d4255 100644 --- a/app/e11sync/urls.py +++ b/app/e11sync/urls.py @@ -22,6 +22,7 @@ from django.conf import settings urlpatterns = [ path('admin/', admin.site.urls), ] + [ - path("__debug__/", include("debug_toolbar.urls"))] if settings.DEBUG else [] + [ + path("__debug__/", include("debug_toolbar.urls")) + ] if settings.DEBUG else [] + [ path('', include('signup.urls')), ] diff --git a/app/manage.py b/app/manage.py index b5c8355..cbf2c82 100755 --- a/app/manage.py +++ b/app/manage.py @@ -3,6 +3,7 @@ import os import sys + def main(): """Run administrative tasks.""" os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'e11sync.settings') diff --git a/app/signup/admin.py b/app/signup/admin.py index 9949bce..c3582de 100644 --- a/app/signup/admin.py +++ b/app/signup/admin.py @@ -2,9 +2,16 @@ from django.contrib import admin from .models import Signup + @admin.register(Signup) class SignupAdmin(admin.ModelAdmin): - _all_fields = ["email", "created_at", "anonymized_ip", "user_agent", "geoip"] + _all_fields = [ + "email", + "created_at", + "anonymized_ip", + "user_agent", + "geoip" + ] date_hierarchy = "created_at" list_display = ["email", "created_at", "user_agent"] + ["place_name"] diff --git a/app/signup/models.py b/app/signup/models.py index 6bc4755..b7ee79d 100644 --- a/app/signup/models.py +++ b/app/signup/models.py @@ -1,15 +1,16 @@ from django.db import models + class Signup(models.Model): email = models.EmailField() - created_at = models.DateTimeField(auto_now_add = True) + created_at = models.DateTimeField(auto_now_add=True) anonymized_ip = models.GenericIPAddressField() - user_agent = models.CharField(max_length = 255) - geoip = models.JSONField(null = True, blank = True) + user_agent = models.CharField(max_length=255) + geoip = models.JSONField(null=True, blank=True) class Meta: constraints = [ - models.UniqueConstraint(name = "unique_email", fields = ["email"]), + models.UniqueConstraint(name="unique_email", fields=["email"]), ] def __str__(self): diff --git a/app/signup/tests.py b/app/signup/tests.py index 2d93829..9655774 100644 --- a/app/signup/tests.py +++ b/app/signup/tests.py @@ -3,6 +3,7 @@ from django.urls import reverse from .models import Signup + class SignupViewTest(TestCase): def setUp(self): self.client = Client() @@ -14,9 +15,9 @@ class SignupViewTest(TestCase): def test_ok_signup(self): resp = self.client.post(reverse("index"), {"email": "foo@example.com"}, - follow = True, - HTTP_USER_AGENT = "foo-agent", - REMOTE_ADDR = "127.0.0.2") + follow=True, + HTTP_USER_AGENT="foo-agent", + REMOTE_ADDR="127.0.0.2") self.assertEqual(resp.redirect_chain, [('/?success=subscribed', 302)]) self.assertContains(resp, "You are now subscribed!") obj = Signup.objects.get() diff --git a/app/signup/views.py b/app/signup/views.py index 3e24669..7515d4b 100644 --- a/app/signup/views.py +++ b/app/signup/views.py @@ -31,10 +31,10 @@ def index(request): geoip = None s = Signup( - email = request.POST.get("email"), - anonymized_ip = anonymous_ip, - user_agent = request.META["HTTP_USER_AGENT"], - geoip = geoip, + email=request.POST.get("email"), + anonymized_ip=anonymous_ip, + user_agent=request.META["HTTP_USER_AGENT"], + geoip=geoip, ) try: @@ -42,7 +42,7 @@ def index(request): except ValidationError as e: print(e) return render(request, "signup/index.html", - {"error_message": e.message}) + {"error_message": e.message}) logging.info("registering email={}".format(request.POST.get("email"))) try: @@ -52,7 +52,7 @@ def index(request): return redirect(reverse("index") + "?success=already_subscribed") except DatabaseError: logger.exception("database error when registering an email") - err = "Sorry, database error. Please come back later." + err = "Sorry, database error. Please come back later." return render(request, "signup/index.html", {"error_message": err}) return redirect(reverse("index") + "?success=subscribed") diff --git a/flake.nix b/flake.nix index e21a743..3513cdc 100644 --- a/flake.nix +++ b/flake.nix @@ -70,6 +70,12 @@ statix.enable = true; }; }; + format = pkgs.runCommand "check-format" {} '' + ${pkgs.python3Packages.flake8}/bin/flake8 \ + --max-line-length 99 \ + --exclude ${./.}/app/signup/migrations/ ${./.} + mkdir -p $out + ''; }; apps.e11sync-gunicorn = { @@ -83,12 +89,15 @@ devShells.default = pkgs.mkShellNoCC { packages = with pkgs; [ - python3Packages.django-debug-toolbar python3Packages.django_5 python3Packages.django-compressor python3Packages.geoip2 libmaxminddb dart-sass + + python3Packages.django-debug-toolbar + python3Packages.flake8 + python3Packages.autopep8 ]; GEOIP_PATH = "${geoip-archive}"; E11SYNC_DEBUG = "1";