add flake8 for python
This commit is contained in:
parent
94626bb28b
commit
7db77e5b24
|
@ -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',
|
||||
|
|
|
@ -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')),
|
||||
]
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'e11sync.settings')
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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")
|
||||
|
|
11
flake.nix
11
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";
|
||||
|
|
Loading…
Reference in New Issue