From ddcb33e20d650e1bc75c7d7ae07ba2d4f72142e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 14 Dec 2023 18:27:56 +0200 Subject: [PATCH] model --- .gitignore | 4 ++++ {e11mail => app}/e11mail/__init__.py | 0 {e11mail => app}/e11mail/asgi.py | 0 {e11mail => app}/e11mail/settings.py | 34 ++------------------------- {e11mail => app}/e11mail/urls.py | 4 +++- {e11mail => app}/e11mail/wsgi.py | 0 {e11mail => app}/manage.py | 2 +- app/signup/__init__.py | 0 app/signup/admin.py | 5 ++++ app/signup/apps.py | 6 +++++ app/signup/migrations/0001_initial.py | 28 ++++++++++++++++++++++ app/signup/migrations/__init__.py | 0 app/signup/models.py | 15 ++++++++++++ app/signup/tests.py | 3 +++ app/signup/urls.py | 7 ++++++ app/signup/views.py | 4 ++++ 16 files changed, 78 insertions(+), 34 deletions(-) rename {e11mail => app}/e11mail/__init__.py (100%) rename {e11mail => app}/e11mail/asgi.py (100%) rename {e11mail => app}/e11mail/settings.py (75%) rename {e11mail => app}/e11mail/urls.py (90%) rename {e11mail => app}/e11mail/wsgi.py (100%) rename {e11mail => app}/manage.py (89%) create mode 100644 app/signup/__init__.py create mode 100644 app/signup/admin.py create mode 100644 app/signup/apps.py create mode 100644 app/signup/migrations/0001_initial.py create mode 100644 app/signup/migrations/__init__.py create mode 100644 app/signup/models.py create mode 100644 app/signup/tests.py create mode 100644 app/signup/urls.py create mode 100644 app/signup/views.py diff --git a/.gitignore b/.gitignore index ee57e5e..621bc82 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ /resources/_gen /public /result + +__pycache__ + +db.sqlite3 diff --git a/e11mail/e11mail/__init__.py b/app/e11mail/__init__.py similarity index 100% rename from e11mail/e11mail/__init__.py rename to app/e11mail/__init__.py diff --git a/e11mail/e11mail/asgi.py b/app/e11mail/asgi.py similarity index 100% rename from e11mail/e11mail/asgi.py rename to app/e11mail/asgi.py diff --git a/e11mail/e11mail/settings.py b/app/e11mail/settings.py similarity index 75% rename from e11mail/e11mail/settings.py rename to app/e11mail/settings.py index 800585d..3405fbc 100644 --- a/e11mail/e11mail/settings.py +++ b/app/e11mail/settings.py @@ -1,21 +1,8 @@ -""" -Django settings for e11mail project. - -Generated by 'django-admin startproject' using Django 5.0. - -For more information on this file, see -https://docs.djangoproject.com/en/5.0/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/5.0/ref/settings/ -""" - from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent - # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ @@ -25,12 +12,13 @@ SECRET_KEY = 'django-insecure-$e2!=equ(efm0e%f9&t+xjtz0)$*$@pw%rnjdqcl8f@5o5hw!l # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True +#ALLOWED_HOSTS = ["100.89.176.6"] ALLOWED_HOSTS = [] - # Application definition INSTALLED_APPS = [ + 'signup.apps.SignupConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -69,10 +57,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'e11mail.wsgi.application' - -# Database -# https://docs.djangoproject.com/en/5.0/ref/settings/#databases - DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', @@ -80,10 +64,6 @@ DATABASES = { } } - -# Password validation -# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators - AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', @@ -100,9 +80,6 @@ AUTH_PASSWORD_VALIDATORS = [ ] -# Internationalization -# https://docs.djangoproject.com/en/5.0/topics/i18n/ - LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' @@ -111,13 +88,6 @@ USE_I18N = True USE_TZ = True - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/5.0/howto/static-files/ - STATIC_URL = 'static/' -# Default primary key field type -# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field - DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/e11mail/e11mail/urls.py b/app/e11mail/urls.py similarity index 90% rename from e11mail/e11mail/urls.py rename to app/e11mail/urls.py index f694c57..80a189a 100644 --- a/e11mail/e11mail/urls.py +++ b/app/e11mail/urls.py @@ -14,9 +14,11 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from django.contrib import admin -from django.urls import path +from django.urls import include, path urlpatterns = [ path('admin/', admin.site.urls), + path('', include('signup.urls')), ] diff --git a/e11mail/e11mail/wsgi.py b/app/e11mail/wsgi.py similarity index 100% rename from e11mail/e11mail/wsgi.py rename to app/e11mail/wsgi.py diff --git a/e11mail/manage.py b/app/manage.py similarity index 89% rename from e11mail/manage.py rename to app/manage.py index a267928..104ea23 100755 --- a/e11mail/manage.py +++ b/app/manage.py @@ -1,4 +1,4 @@ -#!/nix/store/5k91mg4qjylxbfvrv748smfh51ppjq0g-python3-3.11.6/bin/python +#!/usr/bin/env python """Django's command-line utility for administrative tasks.""" import os import sys diff --git a/app/signup/__init__.py b/app/signup/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/signup/admin.py b/app/signup/admin.py new file mode 100644 index 0000000..0774788 --- /dev/null +++ b/app/signup/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin + +from .models import Signup + +admin.site.register(Signup) diff --git a/app/signup/apps.py b/app/signup/apps.py new file mode 100644 index 0000000..7c36efe --- /dev/null +++ b/app/signup/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class SignupConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'signup' diff --git a/app/signup/migrations/0001_initial.py b/app/signup/migrations/0001_initial.py new file mode 100644 index 0000000..5a2299c --- /dev/null +++ b/app/signup/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0 on 2023-12-14 20:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Signup', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('email', models.EmailField(max_length=254)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('anonymized_ip', models.GenericIPAddressField()), + ('user_agent', models.CharField(max_length=255)), + ], + ), + migrations.AddConstraint( + model_name='signup', + constraint=models.UniqueConstraint(fields=('email',), name='unique_email'), + ), + ] diff --git a/app/signup/migrations/__init__.py b/app/signup/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/signup/models.py b/app/signup/models.py new file mode 100644 index 0000000..053b324 --- /dev/null +++ b/app/signup/models.py @@ -0,0 +1,15 @@ +from django.db import models + +class Signup(models.Model): + email = models.EmailField() + created_at = models.DateTimeField(auto_now_add = True) + anonymized_ip = models.GenericIPAddressField() + user_agent = models.CharField(max_length = 255) + + class Meta: + constraints = [ + models.UniqueConstraint(name = "unique_email", fields = ["email"]), + ] + + def __str__(self): + return self.email diff --git a/app/signup/tests.py b/app/signup/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/app/signup/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/app/signup/urls.py b/app/signup/urls.py new file mode 100644 index 0000000..5119061 --- /dev/null +++ b/app/signup/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path("", views.index, name="index"), +] diff --git a/app/signup/views.py b/app/signup/views.py new file mode 100644 index 0000000..ac2b4a8 --- /dev/null +++ b/app/signup/views.py @@ -0,0 +1,4 @@ +from django.http import HttpResponse + +def index(request): + return HttpResponse("Hello. You're at the signup index.")