diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..3aee38a8d7 --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +max-line-length = 120 +exclude = *migrations*,fortytwo_test_task/settings/__init__.py,fortytwo_test_task/settings/test.py +max-complexity = 6 diff --git a/.gitignore b/.gitignore index e2d2938d35..0aa1d3633b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ media static *.dat .env +.idea/ +fortytwo_test_task/local_settings.py diff --git a/Makefile b/Makefile index 9d5e8e9235..c70467ef18 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,73 @@ -MANAGE=django-admin.py +# +# constants +# + +SHELL=/bin/bash + +PROJECT_NAME=fortytwo_test_task +BIND_TO=localhost +RUNSERVER_PORT=8000 SETTINGS=fortytwo_test_task.settings +TEST_SETTINGS=fortytwo_test_task.settings.test +TEST_APP?=apps +flake8=flake8 -test: check_noqa - PYTHONPATH=`pwd` DJANGO_SETTINGS_MODULE=$(SETTINGS) $(MANAGE) test - flake8 --exclude '*migrations*,fortytwo_test_task/settings/__init__.py' \ - --max-complexity=6 apps fortytwo_test_task +PYTHONPATH=$(CURDIR) -check_noqa: - bash check_noqa.sh +MANAGE_PREFIX= PYTHONPATH=$(PYTHONPATH) DJANGO_SETTINGS_MODULE=$(SETTINGS) +MANAGE_CMD=./manage.py +MANAGE= PYTHONPATH=$(PYTHONPATH) DJANGO_SETTINGS_MODULE=$(SETTINGS) $(MANAGE_CMD) + +-include Makefile.def + +# +# end of constants +# + +# +# targets +# + +.PHONY: run syncdb initproject dumpdata shell flake8 djangotest collectstatic clean manage migrate only_migrate init_migrate run: - PYTHONPATH=`pwd` DJANGO_SETTINGS_MODULE=$(SETTINGS) $(MANAGE) runserver + @echo Starting $(PROJECT_NAME)... + $(MANAGE) runserver $(BIND_TO):$(RUNSERVER_PORT) + +createcachetable: + @echo Creating cache table + $(MANAGE) createcachetable -syncdb: - PYTHONPATH=`pwd` DJANGO_SETTINGS_MODULE=$(SETTINGS) $(MANAGE) syncdb --noinput +initproject: migrate createcachetable + +shell: + @echo Starting shell... + $(MANAGE) shell + +flake8: + $(flake8) apps + +djangotest: + TESTING=1 PYTHONWARNINGS=ignore $(MANAGE_CMD) test --settings=$(TEST_SETTINGS) $(TEST_APP) + +test: flake8 djangotest + +collectstatic: clean + @echo Collecting static + $(MANAGE) collectstatic --noinput + @echo Done + +clean: + @echo Cleaning up... + find ./ -name '__pycache__' -print|xargs -I {} rm -r {} + find staticfiles/generated/ -type f | xargs -I {} rm {} + @echo Done migrate: - PYTHONPATH=`pwd` DJANGO_SETTINGS_MODULE=$(SETTINGS) $(MANAGE) migrate + $(MANAGE) migrate -collectstatic: - PYTHONPATH=`pwd` DJANGO_SETTINGS_MODULE=$(SETTINGS) $(MANAGE) collectstatic --noinput -.PHONY: test syncdb migrate +migrations: + $(MANAGE) makemigrations + +check_noqa: + ./check_noqa.sh diff --git a/apps/hello/apps.py b/apps/hello/apps.py new file mode 100755 index 0000000000..6ff8fd1f97 --- /dev/null +++ b/apps/hello/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class HelloConfig(AppConfig): + name = 'apps.hello' diff --git a/apps/hello/migrations/__init__.py b/apps/hello/migrations/__init__.py new file mode 100755 index 0000000000..e69de29bb2 diff --git a/apps/hello/tests.py b/apps/hello/tests.py index 9ca667b4d0..59f80b0726 100644 --- a/apps/hello/tests.py +++ b/apps/hello/tests.py @@ -5,5 +5,7 @@ class SomeTests(TestCase): def test_math(self): - "put docstrings in your tests" - assert(2 + 2 == 5) + """ + put docstrings in your tests + """ + self.assertEqual(2 + 2, 5) diff --git a/check_noqa.sh b/check_noqa.sh old mode 100644 new mode 100755 diff --git a/fortytwo_test_task/settings/common.py b/fortytwo_test_task/settings/common.py index a23c0f5bb6..1cf469b0ff 100644 --- a/fortytwo_test_task/settings/common.py +++ b/fortytwo_test_task/settings/common.py @@ -1,66 +1,78 @@ """ Django settings for fortytwo_test_task project. +Generated by 'django-admin startproject' using Django 2.2.5. + For more information on this file, see -https://docs.djangoproject.com/en/1.6/topics/settings/ +https://docs.djangoproject.com/en/2.2/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.6/ref/settings/ +https://docs.djangoproject.com/en/2.2/ref/settings/ """ -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os -import sys +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) PROJECT_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(PROJECT_DIR) -# App/Library Paths -sys.path.append(os.path.join(BASE_DIR, 'apps')) # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'x=c0_e(onjn^80irdy2c221#)2t^qi&6yrc$31i(&ti*_jf3l8' +SECRET_KEY = 'nwvy4v3acf*oxu$k(_bkue3m1x6nzaw$a=z^uk1e82)ou#d&8l' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -TEMPLATE_DEBUG = True - ALLOWED_HOSTS = [] # Application definition -INSTALLED_APPS = ( +INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', +] - 'apps.hello', -) - -MIDDLEWARE_CLASSES = ( +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', -) +] ROOT_URLCONF = 'fortytwo_test_task.urls' +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + WSGI_APPLICATION = 'fortytwo_test_task.wsgi.application' # Database -# https://docs.djangoproject.com/en/1.6/ref/settings/#databases +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases DATABASES = { 'default': { @@ -69,8 +81,28 @@ } } + +# Password validation +# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + # Internationalization -# https://docs.djangoproject.com/en/1.6/topics/i18n/ +# https://docs.djangoproject.com/en/2.2/topics/i18n/ LANGUAGE_CODE = 'en-us' @@ -82,48 +114,8 @@ USE_TZ = True -# Upload Media -# Absolute filesystem path to the directory that will hold user-uploaded files. -# Example: "/home/media/media.lawrence.com/media/" -MEDIA_ROOT = os.path.join(BASE_DIR, '..', 'uploads') - -# URL that handles the media served from MEDIA_ROOT. Make sure to use a -# trailing slash. -# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" -MEDIA_URL = '/uploads/' - # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.6/howto/static-files/ - -# Absolute path to the directory static files should be collected to. -# Don't put anything in this directory yourself; store your static files -# in apps' "static/" subdirectories and in STATICFILES_DIRS. -# Example: "/home/media/media.lawrence.com/static/" -STATIC_ROOT = os.path.join(BASE_DIR, 'static') - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.6/howto/static-files/ +# https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = '/static/' - -# Additional locations of static files -STATICFILES_DIRS = ( - # Put strings here, like "/home/html/static" or "C:/www/django/static". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. - os.path.join(BASE_DIR, 'assets'), -) - - -# Template Settings -TEMPLATE_DIRS = ( - # Put strings here, like "/home/html/django_templates" or - # "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. - os.path.join(BASE_DIR, 'templates'), -) - -# Turn off south during test -SOUTH_TESTS_MIGRATE = False diff --git a/fortytwo_test_task/settings/test.py b/fortytwo_test_task/settings/test.py new file mode 100644 index 0000000000..d2d00c4f4a --- /dev/null +++ b/fortytwo_test_task/settings/test.py @@ -0,0 +1,14 @@ +from .common import * + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + }, +} + +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', + } +} diff --git a/fortytwo_test_task/urls.py b/fortytwo_test_task/urls.py index c378eb1ad8..896bfc5855 100644 --- a/fortytwo_test_task/urls.py +++ b/fortytwo_test_task/urls.py @@ -1,13 +1,21 @@ -from django.conf.urls import patterns, include, url +"""fortytwo_test_task URL Configuration +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +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 -admin.autodiscover() +from django.urls import path -urlpatterns = patterns( - '', - # Examples: - # url(r'^$', 'fortytwo_test_task.views.home', name='home'), - # url(r'^blog/', include('blog.urls')), - - url(r'^admin/', include(admin.site.urls)), -) +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/fortytwo_test_task/wsgi.py b/fortytwo_test_task/wsgi.py index d9ccbd8e72..e08869b1b9 100644 --- a/fortytwo_test_task/wsgi.py +++ b/fortytwo_test_task/wsgi.py @@ -4,11 +4,13 @@ It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ """ import os + from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fortytwo_test_task.settings") + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fortytwo_test_task.settings') application = get_wsgi_application() diff --git a/manage.py b/manage.py index 968f40e9f6..891c0839af 100755 --- a/manage.py +++ b/manage.py @@ -1,11 +1,21 @@ #!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" import os import sys -if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", - "fortytwo_test_task.settings") - - from django.core.management import execute_from_command_line +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fortytwo_test_task.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt index f4ab34d3ca..d8b208f5e2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -Django==1.6.7 +Django==3.0.8 42cc-pystyle