From 9aed55aad2ddc9d576b3b539fb39a1413b6806ca Mon Sep 17 00:00:00 2001 From: Andrey Rusakov Date: Fri, 9 Aug 2024 11:02:56 +0200 Subject: [PATCH 1/7] Using poetry y to build the project --- api/admin.py | 2 +- api/templates/rest_framework/api.html | 2 +- poetry.lock | 609 ++++++++++++++++++++++++++ pyproject.toml | 59 +++ requirements.txt | 53 --- 5 files changed, 670 insertions(+), 55 deletions(-) create mode 100644 poetry.lock create mode 100644 pyproject.toml delete mode 100644 requirements.txt diff --git a/api/admin.py b/api/admin.py index 38164add..ce973338 100644 --- a/api/admin.py +++ b/api/admin.py @@ -27,7 +27,7 @@ UserModel = get_user_model() -class CustomModelAdmin(admin.GeoModelAdmin): +class CustomModelAdmin(admin.ModelAdmin): """ This is just a cosmetic class adding custom CSS and Replacing CharField Widget by a TextField widget when Charfields are longer than 300 characters. diff --git a/api/templates/rest_framework/api.html b/api/templates/rest_framework/api.html index 53218e2f..af4400c9 100644 --- a/api/templates/rest_framework/api.html +++ b/api/templates/rest_framework/api.html @@ -14,7 +14,7 @@ Admin {% if user.is_authenticated %} - {% optional_logout request user %} + {% optional_logout request user csrf_token %} {% else %} {% optional_login request %} {% endif %} diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 00000000..9355215e --- /dev/null +++ b/poetry.lock @@ -0,0 +1,609 @@ +[[package]] +name = "asgiref" +version = "3.8.1" +description = "ASGI specs, helper code, and adapters" +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +typing-extensions = {version = ">=4", markers = "python_version < \"3.11\""} + +[package.extras] +tests = ["pytest", "pytest-asyncio", "mypy (>=0.800)"] + +[[package]] +name = "attrs" +version = "24.2.0" +description = "Classes Without Boilerplate" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.extras] +benchmark = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest-codspeed", "pytest-mypy-plugins", "pytest-xdist", "pytest (>=4.3.0)"] +cov = ["cloudpickle", "coverage[toml] (>=5.3)", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest-mypy-plugins", "pytest-xdist", "pytest (>=4.3.0)"] +dev = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pre-commit", "pympler", "pytest-mypy-plugins", "pytest-xdist", "pytest (>=4.3.0)"] +docs = ["cogapp", "furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier (<24.7)"] +tests = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest-mypy-plugins", "pytest-xdist", "pytest (>=4.3.0)"] +tests-mypy = ["mypy (>=1.11.1)", "pytest-mypy-plugins"] + +[[package]] +name = "babel" +version = "2.16.0" +description = "Internationalization utilities" +category = "main" +optional = false +python-versions = ">=3.8" + +[package.extras] +dev = ["pytest (>=6.0)", "pytest-cov", "freezegun (>=1.0,<2.0)"] + +[[package]] +name = "certifi" +version = "2024.7.4" +description = "Python package for providing Mozilla's CA Bundle." +category = "main" +optional = false +python-versions = ">=3.6" + +[[package]] +name = "cffi" +version = "1.17.0" +description = "Foreign Function Interface for Python calling C code." +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +pycparser = "*" + +[[package]] +name = "charset-normalizer" +version = "3.3.2" +description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +category = "main" +optional = false +python-versions = ">=3.7.0" + +[[package]] +name = "cryptography" +version = "43.0.0" +description = "cryptography is a package which provides cryptographic recipes and primitives to Python developers." +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +cffi = {version = ">=1.12", markers = "platform_python_implementation != \"PyPy\""} + +[package.extras] +ssh = ["bcrypt (>=3.1.5)"] +nox = ["nox"] +test = ["cryptography-vectors (==43.0.0)", "pytest (>=6.2.0)", "pytest-benchmark", "pytest-cov", "pytest-xdist", "pretend", "certifi"] +test-randomorder = ["pytest-randomly"] +docs = ["sphinx (>=5.3.0)", "sphinx-rtd-theme (>=1.1.1)"] +docstest = ["pyenchant (>=1.6.11)", "readme-renderer", "sphinxcontrib-spelling (>=4.0.1)"] +sdist = ["build"] +pep8test = ["ruff", "mypy", "check-sdist", "click"] + +[[package]] +name = "defusedxml" +version = "0.7.1" +description = "XML bomb protection for Python stdlib modules" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "django" +version = "5.1" +description = "A high-level Python web framework that encourages rapid development and clean, pragmatic design." +category = "main" +optional = false +python-versions = ">=3.10" + +[package.dependencies] +asgiref = ">=3.8.1,<4" +sqlparse = ">=0.3.1" +tzdata = {version = "*", markers = "sys_platform == \"win32\""} + +[package.extras] +argon2 = ["argon2-cffi (>=19.1.0)"] +bcrypt = ["bcrypt"] + +[[package]] +name = "django-allauth" +version = "64.0.0" +description = "Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication." +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +Django = ">=4.2" + +[package.extras] +mfa = ["qrcode (>=7.0.0)", "fido2 (>=1.1.2)"] +openid = ["python3-openid (>=3.0.8)"] +saml = ["python3-saml (>=1.15.0,<2.0.0)"] +steam = ["python3-openid (>=3.0.8)"] +socialaccount = ["requests-oauthlib (>=0.3.0)", "requests (>=2.0.0)", "pyjwt[crypto] (>=1.7)"] + +[[package]] +name = "django-cors-headers" +version = "4.4.0" +description = "django-cors-headers is a Django application for handling the server headers required for Cross-Origin Resource Sharing (CORS)." +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +asgiref = ">=3.6" +django = ">=3.2" + +[[package]] +name = "django-filter" +version = "24.3" +description = "Django-filter is a reusable Django application for allowing users to filter querysets dynamically." +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +Django = ">=4.2" + +[[package]] +name = "django-health-check" +version = "3.18.3" +description = "Run checks on services like databases, queue servers, celery processes, etc." +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +django = ">=2.2" + +[package.extras] +docs = ["sphinx"] +test = ["pytest", "pytest-cov", "pytest-django", "celery", "redis", "django-storages", "boto3"] + +[[package]] +name = "django-money" +version = "3.5.3" +description = "Adds support for using money and currency fields in django models and forms. Uses py-moneyed as the money implementation." +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +Django = ">=2.2" +py-moneyed = ">=2.0,<3.1" + +[package.extras] +exchange = ["certifi"] +test = ["pytest (>=8.2,<8.3)", "pytest-django", "pytest-cov", "mixer", "mypy", "django-stubs"] + +[[package]] +name = "djangorestframework" +version = "3.15.2" +description = "Web APIs for Django, made easy." +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +django = ">=4.2" + +[[package]] +name = "djangorestframework-gis" +version = "1.0" +description = "Geographic add-ons for Django Rest Framework" +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +djangorestframework = "*" + +[[package]] +name = "djangorestframework-simplejwt" +version = "5.3.1" +description = "A minimal JSON Web Token authentication plugin for Django REST Framework" +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +django = ">=3.2" +djangorestframework = ">=3.12" +pyjwt = ">=1.7.1,<3" + +[package.extras] +test = ["cryptography", "freezegun", "pytest-cov", "pytest-django", "pytest-xdist", "pytest", "tox"] +lint = ["flake8", "pep8", "isort"] +doc = ["Sphinx (>=1.6.5,<2)", "sphinx_rtd_theme (>=0.1.9)"] +dev = ["pytest-watch", "wheel", "twine", "ipython", "cryptography", "freezegun", "pytest-cov", "pytest-django", "pytest-xdist", "pytest", "tox", "flake8", "pep8", "isort", "Sphinx (>=1.6.5,<2)", "sphinx_rtd_theme (>=0.1.9)", "python-jose (==3.3.0)"] +python-jose = ["python-jose (==3.3.0)"] +crypto = ["cryptography (>=3.3.1)"] + +[[package]] +name = "drf-spectacular" +version = "0.27.2" +description = "Sane and flexible OpenAPI 3 schema generation for Django REST framework" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +Django = ">=2.2" +djangorestframework = ">=3.10.3" +inflection = ">=0.3.1" +jsonschema = ">=2.6.0" +PyYAML = ">=5.1" +uritemplate = ">=2.0.0" + +[package.extras] +offline = ["drf-spectacular-sidecar"] +sidecar = ["drf-spectacular-sidecar"] + +[[package]] +name = "gunicorn" +version = "22.0.0" +description = "WSGI HTTP Server for UNIX" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +packaging = "*" + +[package.extras] +eventlet = ["eventlet (>=0.24.1,!=0.36.0)"] +gevent = ["gevent (>=1.4.0)"] +setproctitle = ["setproctitle"] +testing = ["gevent", "eventlet", "coverage", "pytest", "pytest-cov"] +tornado = ["tornado (>=0.2)"] + +[[package]] +name = "idna" +version = "3.7" +description = "Internationalized Domain Names in Applications (IDNA)" +category = "main" +optional = false +python-versions = ">=3.5" + +[[package]] +name = "inflection" +version = "0.5.1" +description = "A port of Ruby on Rails inflector to Python" +category = "main" +optional = false +python-versions = ">=3.5" + +[[package]] +name = "jsonschema" +version = "4.23.0" +description = "An implementation of JSON Schema validation for Python" +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +attrs = ">=22.2.0" +jsonschema-specifications = ">=2023.03.6" +referencing = ">=0.28.4" +rpds-py = ">=0.7.1" + +[package.extras] +format = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3987", "uri-template", "webcolors (>=1.11)"] +format-nongpl = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3986-validator (>0.1.0)", "uri-template", "webcolors (>=24.6.0)"] + +[[package]] +name = "jsonschema-specifications" +version = "2023.12.1" +description = "The JSON Schema meta-schemas and vocabularies, exposed as a Registry" +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +referencing = ">=0.31.0" + +[[package]] +name = "markdown" +version = "3.6" +description = "Python implementation of John Gruber's Markdown." +category = "main" +optional = false +python-versions = ">=3.8" + +[package.extras] +docs = ["mkdocs (>=1.5)", "mkdocs-nature (>=0.6)", "mdx-gh-links (>=0.2)", "mkdocstrings", "mkdocs-gen-files", "mkdocs-section-index", "mkdocs-literate-nav"] +testing = ["coverage", "pyyaml"] + +[[package]] +name = "oauthlib" +version = "3.2.2" +description = "A generic, spec-compliant, thorough implementation of the OAuth request-signing logic" +category = "main" +optional = false +python-versions = ">=3.6" + +[package.extras] +rsa = ["cryptography (>=3.0.0)"] +signals = ["blinker (>=1.4.0)"] +signedtoken = ["cryptography (>=3.0.0)", "pyjwt (>=2.0.0,<3)"] + +[[package]] +name = "packaging" +version = "24.1" +description = "Core utilities for Python packages" +category = "main" +optional = false +python-versions = ">=3.8" + +[[package]] +name = "psycopg2" +version = "2.9.9" +description = "psycopg2 - Python-PostgreSQL Database Adapter" +category = "main" +optional = false +python-versions = ">=3.7" + +[[package]] +name = "py-moneyed" +version = "3.0" +description = "Provides Currency and Money classes for use in your Python code." +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +babel = ">=2.8.0" +typing-extensions = ">=3.7.4.3" + +[package.extras] +tests = ["pytest (>=2.3.0)", "tox (>=1.6.0)"] +type-tests = ["pytest (>=2.3.0)", "pytest-mypy-plugins", "mypy (>=0.812)"] + +[[package]] +name = "pycparser" +version = "2.22" +description = "C parser in Python" +category = "main" +optional = false +python-versions = ">=3.8" + +[[package]] +name = "pyjwt" +version = "2.9.0" +description = "JSON Web Token implementation in Python" +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +cryptography = {version = ">=3.4.0", optional = true, markers = "extra == \"crypto\""} + +[package.extras] +crypto = ["cryptography (>=3.4.0)"] +dev = ["sphinx", "sphinx-rtd-theme", "zope.interface", "cryptography (>=3.4.0)", "pytest (>=6.0.0,<7.0.0)", "coverage[toml] (==5.0.4)", "pre-commit"] +docs = ["sphinx", "sphinx-rtd-theme", "zope.interface"] +tests = ["pytest (>=6.0.0,<7.0.0)", "coverage[toml] (==5.0.4)"] + +[[package]] +name = "python-dotenv" +version = "1.0.1" +description = "Read key-value pairs from a .env file and set them as environment variables" +category = "main" +optional = false +python-versions = ">=3.8" + +[package.extras] +cli = ["click (>=5.0)"] + +[[package]] +name = "python3-openid" +version = "3.2.0" +description = "OpenID support for modern servers and consumers." +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +defusedxml = "*" + +[package.extras] +mysql = ["mysql-connector-python"] +postgresql = ["psycopg2"] + +[[package]] +name = "pytz" +version = "2024.1" +description = "World timezone definitions, modern and historical" +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "pyyaml" +version = "6.0.2" +description = "YAML parser and emitter for Python" +category = "main" +optional = false +python-versions = ">=3.8" + +[[package]] +name = "referencing" +version = "0.35.1" +description = "JSON Referencing + Python" +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +attrs = ">=22.2.0" +rpds-py = ">=0.7.0" + +[[package]] +name = "requests" +version = "2.32.3" +description = "Python HTTP for Humans." +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +certifi = ">=2017.4.17" +charset-normalizer = ">=2,<4" +idna = ">=2.5,<4" +urllib3 = ">=1.21.1,<3" + +[package.extras] +socks = ["PySocks (>=1.5.6,!=1.5.7)"] +use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] + +[[package]] +name = "requests-oauthlib" +version = "2.0.0" +description = "OAuthlib authentication support for Requests." +category = "main" +optional = false +python-versions = ">=3.4" + +[package.dependencies] +oauthlib = ">=3.0.0" +requests = ">=2.0.0" + +[package.extras] +rsa = ["oauthlib[signedtoken] (>=3.0.0)"] + +[[package]] +name = "rpds-py" +version = "0.20.0" +description = "Python bindings to Rust's persistent data structures (rpds)" +category = "main" +optional = false +python-versions = ">=3.8" + +[[package]] +name = "sqlparse" +version = "0.5.1" +description = "A non-validating SQL parser." +category = "main" +optional = false +python-versions = ">=3.8" + +[package.extras] +dev = ["build", "hatch"] +doc = ["sphinx"] + +[[package]] +name = "typing-extensions" +version = "4.12.2" +description = "Backported and Experimental Type Hints for Python 3.8+" +category = "main" +optional = false +python-versions = ">=3.8" + +[[package]] +name = "tzdata" +version = "2024.1" +description = "Provider of IANA time zone data" +category = "main" +optional = false +python-versions = ">=2" + +[[package]] +name = "unidecode" +version = "1.3.8" +description = "ASCII transliterations of Unicode text" +category = "main" +optional = false +python-versions = ">=3.5" + +[[package]] +name = "uritemplate" +version = "4.1.1" +description = "Implementation of RFC 6570 URI Templates" +category = "main" +optional = false +python-versions = ">=3.6" + +[[package]] +name = "urllib3" +version = "2.2.2" +description = "HTTP library with thread-safe connection pooling, file post, and more." +category = "main" +optional = false +python-versions = ">=3.8" + +[package.extras] +brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"] +h2 = ["h2 (>=4,<5)"] +socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] +zstd = ["zstandard (>=0.18.0)"] + +[[package]] +name = "whitenoise" +version = "6.7.0" +description = "Radically simplified static file serving for WSGI applications" +category = "main" +optional = false +python-versions = ">=3.8" + +[package.extras] +brotli = ["brotli"] + +[metadata] +lock-version = "1.1" +python-versions = "^3.10" +content-hash = "b6458f6145d7a166099a1bfc72445d6a18d031c4b2e4ec6348fadc7af1cb4fdb" + +[metadata.files] +asgiref = [] +attrs = [] +babel = [] +certifi = [] +cffi = [] +charset-normalizer = [] +cryptography = [] +defusedxml = [] +django = [] +django-allauth = [] +django-cors-headers = [] +django-filter = [] +django-health-check = [] +django-money = [] +djangorestframework = [] +djangorestframework-gis = [] +djangorestframework-simplejwt = [] +drf-spectacular = [] +gunicorn = [] +idna = [] +inflection = [] +jsonschema = [] +jsonschema-specifications = [] +markdown = [] +oauthlib = [] +packaging = [] +psycopg2 = [] +py-moneyed = [] +pycparser = [] +pyjwt = [] +python-dotenv = [] +python3-openid = [] +pytz = [] +pyyaml = [] +referencing = [] +requests = [] +requests-oauthlib = [] +rpds-py = [] +sqlparse = [] +typing-extensions = [] +tzdata = [] +unidecode = [] +uritemplate = [] +urllib3 = [] +whitenoise = [] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..adaf9c5a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,59 @@ +[tool.poetry] +name = "geoshop-back" +version = "0.1.0" +description = "Backend for the geoshop service" +authors = ["Your Name "] +license = "BSD 3-Clause License" + +[tool.poetry.dependencies] +python = "^3.10" +asgiref = "*" +attrs = "*" +Babel = "*" +certifi = "*" +cffi = "*" +charset-normalizer = "*" +cryptography = "*" +defusedxml = "*" +Django = "^5" +django-allauth = "*" +django-cors-headers = "*" +django-filter = "*" +django-health-check = "*" +django-money = "*" +djangorestframework = "*" +djangorestframework-gis = "*" +djangorestframework-simplejwt = "*" +drf-spectacular = "*" +gunicorn = "*" +idna = "*" +inflection = "*" +jsonschema = "*" +jsonschema-specifications = "*" +Markdown = "*" +oauthlib = "*" +psycopg2 = "*" +pycparser = "*" +PyJWT = {extras = ["crypto"], version = "*"} +py-moneyed = "*" +python3-openid = "*" +python-dotenv = "*" +pytz = "*" +PyYAML = "*" +referencing = "*" +requests = "*" +requests-oauthlib = "*" +rpds-py = "*" +setuptools = "*" +sqlparse = "*" +typing-extensions = "*" +Unidecode = "*" +uritemplate = "*" +urllib3 = "*" +whitenoise = "*" + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 7e112cb8..00000000 --- a/requirements.txt +++ /dev/null @@ -1,53 +0,0 @@ -# -# These requirements were autogenerated by pipenv -# To regenerate from the project's Pipfile, run: -# -# pipenv lock && pipenv requirements > requirements.txt -# - --i https://pypi.org/simple ---extra-index-url https://pypi.org/simple/ -asgiref==3.7.2; python_version >= '3.7' -attrs==23.2.0; python_version >= '3.7' -babel==2.12.1; python_version >= '3.7' -certifi==2023.7.22; python_version >= '3.6' -cffi==1.15.1 -charset-normalizer==3.1.0; python_full_version >= '3.7.0' -cryptography==41.0.1; python_version >= '3.7' -defusedxml==0.7.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' -django==4.1.10; python_version >= '3.8' -django-allauth==0.51.0 -django-cors-headers==3.13.0; python_version >= '3.7' -django-filter==22.1; python_version >= '3.7' -django-health-check==3.18.3; python_version >= '3.8' -django-money==3.0.0; python_version >= '3.7' -djangorestframework==3.14.0; python_version >= '3.6' -djangorestframework-gis==1.0 -djangorestframework-simplejwt==5.2.1; python_version >= '3.7' -drf-spectacular==0.27.1; python_version >= '3.6' -gunicorn==20.1.0; python_version >= '3.5' -idna==3.7; python_version >= '3.5' -inflection==0.5.1; python_version >= '3.5' -jsonschema==4.23.0; python_version >= '3.8' -jsonschema-specifications==2023.12.1; python_version >= '3.8' -markdown==3.4.1; python_version >= '3.7' -oauthlib==3.2.2; python_version >= '3.6' -psycopg2==2.9.4; python_version >= '3.6' -py-moneyed==2.0; python_version >= '3.6' -pycparser==2.21 -pyjwt[crypto]==2.7.0; python_version >= '3.7' -python-dotenv==0.21.0; python_version >= '3.7' -python3-openid==3.2.0 -pytz==2023.3 -pyyaml==6.0.1; python_version >= '3.6' -referencing==0.35.1; python_version >= '3.8' -requests==2.31.0; python_version >= '3.7' -requests-oauthlib==1.3.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' -rpds-py==0.19.0; python_version >= '3.8' -setuptools==70.3.0; python_version >= '3.8' -sqlparse==0.5.0; python_version >= '3.8' -typing-extensions==4.7.1; python_version >= '3.7' -unidecode==1.3.6; python_version >= '3.5' -uritemplate==4.1.1; python_version >= '3.6' -urllib3==2.0.3; python_version >= '3.7' -whitenoise==6.2.0; python_version >= '3.7' From 9119dea64c9b6469601d0e13955248f1e97167ca Mon Sep 17 00:00:00 2001 From: Andrey Rusakov Date: Fri, 9 Aug 2024 14:49:15 +0200 Subject: [PATCH 2/7] Add AccountMiddleware to avoid "ImproperlyConfigured" error --- default_settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/default_settings.py b/default_settings.py index eff4617b..feda818e 100644 --- a/default_settings.py +++ b/default_settings.py @@ -60,6 +60,7 @@ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', + 'allauth.account.middleware.AccountMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', From db4763f8e16dbe78998bc2ab295cc26ca83b5e51 Mon Sep 17 00:00:00 2001 From: Andrey Rusakov Date: Mon, 12 Aug 2024 10:25:30 +0200 Subject: [PATCH 3/7] Using exact version for packages --- poetry.lock | 7 ++-- pyproject.toml | 89 ++++++++++++++++++++++++-------------------------- 2 files changed, 45 insertions(+), 51 deletions(-) diff --git a/poetry.lock b/poetry.lock index 9355215e..49edafc9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -249,7 +249,7 @@ sidecar = ["drf-spectacular-sidecar"] [[package]] name = "gunicorn" -version = "22.0.0" +version = "23.0.0" description = "WSGI HTTP Server for UNIX" category = "main" optional = false @@ -383,9 +383,6 @@ category = "main" optional = false python-versions = ">=3.8" -[package.dependencies] -cryptography = {version = ">=3.4.0", optional = true, markers = "extra == \"crypto\""} - [package.extras] crypto = ["cryptography (>=3.4.0)"] dev = ["sphinx", "sphinx-rtd-theme", "zope.interface", "cryptography (>=3.4.0)", "pytest (>=6.0.0,<7.0.0)", "coverage[toml] (==5.0.4)", "pre-commit"] @@ -559,7 +556,7 @@ brotli = ["brotli"] [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "b6458f6145d7a166099a1bfc72445d6a18d031c4b2e4ec6348fadc7af1cb4fdb" +content-hash = "1d18b7e359ad4d0d907b1bdaf87f38da30252499dde97e1cc40b59da343c6e90" [metadata.files] asgiref = [] diff --git a/pyproject.toml b/pyproject.toml index adaf9c5a..8d3b49eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,52 +7,49 @@ license = "BSD 3-Clause License" [tool.poetry.dependencies] python = "^3.10" -asgiref = "*" -attrs = "*" -Babel = "*" -certifi = "*" -cffi = "*" -charset-normalizer = "*" -cryptography = "*" -defusedxml = "*" -Django = "^5" -django-allauth = "*" -django-cors-headers = "*" -django-filter = "*" -django-health-check = "*" -django-money = "*" -djangorestframework = "*" -djangorestframework-gis = "*" -djangorestframework-simplejwt = "*" -drf-spectacular = "*" -gunicorn = "*" -idna = "*" -inflection = "*" -jsonschema = "*" -jsonschema-specifications = "*" -Markdown = "*" -oauthlib = "*" -psycopg2 = "*" -pycparser = "*" -PyJWT = {extras = ["crypto"], version = "*"} -py-moneyed = "*" -python3-openid = "*" -python-dotenv = "*" -pytz = "*" -PyYAML = "*" -referencing = "*" -requests = "*" -requests-oauthlib = "*" -rpds-py = "*" -setuptools = "*" -sqlparse = "*" -typing-extensions = "*" -Unidecode = "*" -uritemplate = "*" -urllib3 = "*" -whitenoise = "*" - -[tool.poetry.dev-dependencies] +asgiref = "^3.8.1" +attrs = "^24.2.0" +babel = "^2.16.0" +certifi = "^2024.7.4" +cffi = "^1.17.0" +charset-normalizer = "^3.3.2" +cryptography = "^43.0.0" +defusedxml = "^0.7.1" +django-allauth = "^64.0.0" +django-cors-headers = "^4.4.0" +django-filter = "^24.3" +django-health-check = "^3.18.3" +django-money = "^3.5.3" +djangorestframework = "^3.15.2" +djangorestframework-gis = "^1.0" +djangorestframework-simplejwt = "^5.3.1" +drf-spectacular = "^0.27.2" +gunicorn = "^23.0.0" +idna = "^3.7" +inflection = "^0.5.1" +jsonschema = "^4.23.0" +jsonschema-specifications = "^2023.12.1" +Markdown = "^3.6" +oauthlib = "^3.2.2" +psycopg2 = "^2.9.9" +pycparser = "^2.22" +PyJWT = "^2.9.0" +py-moneyed = "^3.0" +python3-openid = "^3.2.0" +python-dotenv = "^1.0.1" +pytz = "^2024.1" +PyYAML = "^6.0.2" +referencing = "^0.35.1" +requests = "^2.32.3" +requests-oauthlib = "^2.0.0" +rpds-py = "^0.20.0" +setuptools = "^72.1.0" +sqlparse = "^0.5.1" +typing-extensions = "^4.12.2" +Unidecode = "^1.3.8" +uritemplate = "^4.1.1" +urllib3 = "^2.2.2" +whitenoise = "^6.7.0" [build-system] requires = ["poetry-core>=1.0.0"] From 1c3eceef2a3a112f39b6659464361a3224e8f3f0 Mon Sep 17 00:00:00 2001 From: Andrey Rusakov Date: Mon, 12 Aug 2024 10:54:21 +0200 Subject: [PATCH 4/7] Added missing dependency --- poetry.lock | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 49edafc9..6a0b5128 100644 --- a/poetry.lock +++ b/poetry.lock @@ -556,7 +556,7 @@ brotli = ["brotli"] [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "1d18b7e359ad4d0d907b1bdaf87f38da30252499dde97e1cc40b59da343c6e90" +content-hash = "d40f265cf78f88a1020b6e6d72e38a5d54f4bd998cf148426bb9b97f20334ec4" [metadata.files] asgiref = [] diff --git a/pyproject.toml b/pyproject.toml index 8d3b49eb..ed59eb5a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ Unidecode = "^1.3.8" uritemplate = "^4.1.1" urllib3 = "^2.2.2" whitenoise = "^6.7.0" +Django = "^5.1" [build-system] requires = ["poetry-core>=1.0.0"] From 43a4394722964b86b726a3143c7ffe9c96a300b9 Mon Sep 17 00:00:00 2001 From: Andrey Rusakov Date: Mon, 12 Aug 2024 16:55:20 +0200 Subject: [PATCH 5/7] Updated docker configs to work with poetry --- Dockerfile | 28 +++++++++++----------------- docker-compose.yml | 13 +++++++------ poetry.lock | 14 +++++++++++++- pyproject.toml | 3 ++- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7897bfd3..4a32c3bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,14 @@ -FROM ghcr.io/osgeo/gdal:ubuntu-small-3.5.2 +FROM ubuntu:oracular AS builder +LABEL Maintainer="andrey.rusakov@camptocamp.com" Vendor="Camptocamp" -RUN apt-get update --fix-missing && \ - apt-get install gettext python3-pip libcairo2-dev build-essential python3-dev \ - pipenv python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 \ - libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info libpq-dev -y && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -COPY ./requirements.txt /app/geoshop_back/requirements.txt WORKDIR /app/geoshop_back/ -RUN pip3 install -r requirements.txt - -# Update C env vars so compiler can find gdal -ENV CPLUS_INCLUDE_PATH=/usr/include/gdal -ENV C_INCLUDE_PATH=/usr/include/gdal -ENV PYTHONUNBUFFERED 1 - COPY . /app/geoshop_back/ -RUN mv /app/geoshop_back/default_settings.py /app/geoshop_back/settings.py + +RUN apt update && \ + apt upgrade -y && \ + apt install -y bash postgresql curl \ + python3 python3-poetry python3-setuptools gunicorn \ + libgdal-dev libffi-dev && \ + cd /app/geoshop_back/ && \ + poetry update && \ + poetry install --no-root diff --git a/docker-compose.yml b/docker-compose.yml index 236cbdde..b15b095f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,10 +39,11 @@ services: env_file: .env environment: PGHOST: "db" - command: - - bash - - -c - - "python manage.py migrate && python manage.py collectstatic --noinput && python manage.py compilemessages --locale=fr && python manage.py fixturize" + command: > + poetry run python3 manage.py migrate && + poetry run python3 manage.py collectstatic --noinput && + poetry run python3 manage.py compilemessages --locale=fr && + poetry run python3 manage.py fixturize volumes: - "static-files:/app/geoshop_back/static:rw" networks: @@ -58,12 +59,12 @@ services: env_file: .env environment: PGHOST: "db" - command: "gunicorn wsgi -b :8000 --timeout 90" + command: "poetry run gunicorn wsgi -b :8000 --timeout 90" restart: unless-stopped volumes: - "static-files:/app/geoshop_back/static:ro" ports: - - "8080:8000" + - "8000:8000" networks: - geoshop diff --git a/poetry.lock b/poetry.lock index 6a0b5128..5aa7644d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -247,6 +247,17 @@ uritemplate = ">=2.0.0" offline = ["drf-spectacular-sidecar"] sidecar = ["drf-spectacular-sidecar"] +[[package]] +name = "gdal" +version = "3.4.1" +description = "GDAL: Geospatial Data Abstraction Library" +category = "main" +optional = false +python-versions = ">=3.6.0" + +[package.extras] +numpy = ["numpy (>1.0.0)"] + [[package]] name = "gunicorn" version = "23.0.0" @@ -556,7 +567,7 @@ brotli = ["brotli"] [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "d40f265cf78f88a1020b6e6d72e38a5d54f4bd998cf148426bb9b97f20334ec4" +content-hash = "f3584eb0e4027d97596bbc423a93d522ccca5af8b80816953b66b176ed4f4b72" [metadata.files] asgiref = [] @@ -577,6 +588,7 @@ djangorestframework = [] djangorestframework-gis = [] djangorestframework-simplejwt = [] drf-spectacular = [] +gdal = [] gunicorn = [] idna = [] inflection = [] diff --git a/pyproject.toml b/pyproject.toml index ed59eb5a..e8e5daaf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "geoshop-back" version = "0.1.0" description = "Backend for the geoshop service" -authors = ["Your Name "] +authors = ["Andrey Rusakov "] license = "BSD 3-Clause License" [tool.poetry.dependencies] @@ -51,6 +51,7 @@ uritemplate = "^4.1.1" urllib3 = "^2.2.2" whitenoise = "^6.7.0" Django = "^5.1" +GDAL = "3.4.1" [build-system] requires = ["poetry-core>=1.0.0"] From e42e0b564904986b4b56e0532e7bbecc20570ad1 Mon Sep 17 00:00:00 2001 From: Andrey Rusakov Date: Wed, 14 Aug 2024 17:58:51 +0200 Subject: [PATCH 6/7] Made project run without virtualenv --- Dockerfile | 24 +++++++++++++----------- api/admin.py | 2 +- docker-compose.yml | 10 +++++----- poetry.lock | 18 +++--------------- pyproject.toml | 6 ++---- 5 files changed, 24 insertions(+), 36 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4a32c3bd..a6aabae6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,16 @@ -FROM ubuntu:oracular AS builder +FROM python:3.12.5-slim-bookworm LABEL Maintainer="andrey.rusakov@camptocamp.com" Vendor="Camptocamp" +ENV POETRY_NO_INTERACTION=1 \ + POETRY_VIRTUALENVS_CREATE=false \ + POETRY_CACHE_DIR='/var/cache/pypoetry' \ + POETRY_HOME='/usr/local' + WORKDIR /app/geoshop_back/ -COPY . /app/geoshop_back/ - -RUN apt update && \ - apt upgrade -y && \ - apt install -y bash postgresql curl \ - python3 python3-poetry python3-setuptools gunicorn \ - libgdal-dev libffi-dev && \ - cd /app/geoshop_back/ && \ - poetry update && \ - poetry install --no-root +COPY poetry.lock pyproject.toml /app/geoshop_back/ + +RUN apt update && apt install -y libgdal-dev libffi-dev && \ + pip install poetry && \ + poetry install --only=main + +COPY . /app/geoshop_back/ \ No newline at end of file diff --git a/api/admin.py b/api/admin.py index ce973338..51aa2512 100644 --- a/api/admin.py +++ b/api/admin.py @@ -27,7 +27,7 @@ UserModel = get_user_model() -class CustomModelAdmin(admin.ModelAdmin): +class CustomModelAdmin(admin.GISModelAdmin): """ This is just a cosmetic class adding custom CSS and Replacing CharField Widget by a TextField widget when Charfields are longer than 300 characters. diff --git a/docker-compose.yml b/docker-compose.yml index b15b095f..b20e3a6c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,10 +40,10 @@ services: environment: PGHOST: "db" command: > - poetry run python3 manage.py migrate && - poetry run python3 manage.py collectstatic --noinput && - poetry run python3 manage.py compilemessages --locale=fr && - poetry run python3 manage.py fixturize + python3 manage.py migrate && + python3 manage.py collectstatic --noinput && + python3 manage.py compilemessages --locale=fr && + python3 manage.py fixturize volumes: - "static-files:/app/geoshop_back/static:rw" networks: @@ -59,7 +59,7 @@ services: env_file: .env environment: PGHOST: "db" - command: "poetry run gunicorn wsgi -b :8000 --timeout 90" + command: gunicorn wsgi -b :8000 --timeout 90 restart: unless-stopped volumes: - "static-files:/app/geoshop_back/static:ro" diff --git a/poetry.lock b/poetry.lock index 5aa7644d..76b093af 100644 --- a/poetry.lock +++ b/poetry.lock @@ -247,17 +247,6 @@ uritemplate = ">=2.0.0" offline = ["drf-spectacular-sidecar"] sidecar = ["drf-spectacular-sidecar"] -[[package]] -name = "gdal" -version = "3.4.1" -description = "GDAL: Geospatial Data Abstraction Library" -category = "main" -optional = false -python-versions = ">=3.6.0" - -[package.extras] -numpy = ["numpy (>1.0.0)"] - [[package]] name = "gunicorn" version = "23.0.0" @@ -355,7 +344,7 @@ optional = false python-versions = ">=3.8" [[package]] -name = "psycopg2" +name = "psycopg2-binary" version = "2.9.9" description = "psycopg2 - Python-PostgreSQL Database Adapter" category = "main" @@ -567,7 +556,7 @@ brotli = ["brotli"] [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "f3584eb0e4027d97596bbc423a93d522ccca5af8b80816953b66b176ed4f4b72" +content-hash = "ebe7bf894d453c6048eb5a9949303d9685323d5581ed75b7e5758de0c22c68db" [metadata.files] asgiref = [] @@ -588,7 +577,6 @@ djangorestframework = [] djangorestframework-gis = [] djangorestframework-simplejwt = [] drf-spectacular = [] -gdal = [] gunicorn = [] idna = [] inflection = [] @@ -597,7 +585,7 @@ jsonschema-specifications = [] markdown = [] oauthlib = [] packaging = [] -psycopg2 = [] +psycopg2-binary = [] py-moneyed = [] pycparser = [] pyjwt = [] diff --git a/pyproject.toml b/pyproject.toml index e8e5daaf..3c643323 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ jsonschema = "^4.23.0" jsonschema-specifications = "^2023.12.1" Markdown = "^3.6" oauthlib = "^3.2.2" -psycopg2 = "^2.9.9" +psycopg2-binary = "^2.9.9" pycparser = "^2.22" PyJWT = "^2.9.0" py-moneyed = "^3.0" @@ -43,7 +43,6 @@ referencing = "^0.35.1" requests = "^2.32.3" requests-oauthlib = "^2.0.0" rpds-py = "^0.20.0" -setuptools = "^72.1.0" sqlparse = "^0.5.1" typing-extensions = "^4.12.2" Unidecode = "^1.3.8" @@ -51,8 +50,7 @@ uritemplate = "^4.1.1" urllib3 = "^2.2.2" whitenoise = "^6.7.0" Django = "^5.1" -GDAL = "3.4.1" [build-system] -requires = ["poetry-core>=1.0.0"] +requires = ["poetry-core>=1.6.0"] build-backend = "poetry.core.masonry.api" From e54b48b70293d4728db186fba49214a57db14c37 Mon Sep 17 00:00:00 2001 From: Andrey Rusakov Date: Thu, 15 Aug 2024 13:49:29 +0200 Subject: [PATCH 7/7] Copy default settings if there is no settings file already --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a6aabae6..eb5a9d3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,4 +13,7 @@ RUN apt update && apt install -y libgdal-dev libffi-dev && \ pip install poetry && \ poetry install --only=main -COPY . /app/geoshop_back/ \ No newline at end of file +COPY . /app/geoshop_back/ + +# Copy default settings to settings only if there is no such file +RUN mv -vn /app/geoshop_back/default_settings.py /app/geoshop_back/settings.py \ No newline at end of file