Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ media
static
*.dat
.env
.idea/
fortytwo_test_task/local_settings.py
78 changes: 64 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions apps/hello/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class HelloConfig(AppConfig):
name = 'apps.hello'
Empty file.
6 changes: 4 additions & 2 deletions apps/hello/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Empty file modified check_noqa.sh
100644 → 100755
Empty file.
110 changes: 51 additions & 59 deletions fortytwo_test_task/settings/common.py
Original file line number Diff line number Diff line change
@@ -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': {
Expand All @@ -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'

Expand All @@ -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
14 changes: 14 additions & 0 deletions fortytwo_test_task/settings/test.py
Original file line number Diff line number Diff line change
@@ -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',
}
}
28 changes: 18 additions & 10 deletions fortytwo_test_task/urls.py
Original file line number Diff line number Diff line change
@@ -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),
]
6 changes: 4 additions & 2 deletions fortytwo_test_task/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
20 changes: 15 additions & 5 deletions manage.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Django==1.6.7
Django==3.0.8
42cc-pystyle