diff --git a/.editorconfig b/.editorconfig index 6a9a5c4..c27916e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -24,4 +24,4 @@ indent_style = tab [nginx.conf] indent_style = space -indent_size = 2 +indent_size = 2 \ No newline at end of file diff --git a/.flake8 b/.flake8 index 84b4b44..12f5db1 100644 --- a/.flake8 +++ b/.flake8 @@ -1,3 +1,4 @@ [flake8] exclude = docs max-line-length = 119 +extend-ignore = E203 \ No newline at end of file diff --git a/.github/CONTRIBUTORS-template.md b/.github/CONTRIBUTORS-template.md deleted file mode 100644 index cc76ace..0000000 --- a/.github/CONTRIBUTORS-template.md +++ /dev/null @@ -1,52 +0,0 @@ -# Contributors - -## Core Developers - -These contributors have commit flags for the repository, and are able to -accept and merge pull requests. - - - - - - - - {%- for contributor in core_contributors %} - - - - - - {%- endfor %} -
NameGithubTwitter
{{ contributor.name }} - {{ contributor.github_login }} - {{ contributor.twitter_username }}
- -_Audrey is also the creator of dxh_py. Audrey and Daniel are on -the dxh_py core team._ - -## Other Contributors - -Listed in alphabetical order. - - - - - - - - {%- for contributor in other_contributors %} - - - - - - {%- endfor %} -
NameGithubTwitter
{{ contributor.name }} - {{ contributor.github_login }} - {{ contributor.twitter_username }}
- -### Special Thanks - -The following haven't provided code directly, but have provided -guidance and advice. diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index febe12a..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,12 +0,0 @@ -# # These are supported funding model platforms - -# github: [pydanny, browniebroke] -# patreon: feldroy -# open_collective: # Replace with a single Open Collective username -# ko_fi: # Replace with a single Ko-fi username -# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -# liberapay: # Replace with a single Liberapay username -# issuehunt: # Replace with a single IssueHunt username -# otechie: # Replace with a single Otechie username -# custom: ["https://www.patreon.com/browniebroke"] diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md deleted file mode 100644 index 5ba816a..0000000 --- a/.github/ISSUE_TEMPLATE/bug.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -name: Bug Report -about: Report a bug -labels: bug ---- - -## What happened? - -## What should've happened instead? - -## Additional details - - - -- Host system configuration: - - - Version of dxh_py CLI (get it with `dxh_py --version`): - - OS name and version: - - On Linux, run - - ```bash - lsb_release -a 2> /dev/null || cat /etc/redhat-release 2> /dev/null || cat /etc/*-release 2> /dev/null || cat /etc/issue 2> /dev/null - ``` - - On MacOs, run - - ```bash - sw_vers - ``` - - On Windows, via CMD, run - - ``` - systeminfo | findstr /B /C:"OS Name" /C:"OS Version" - ``` - - ```bash - # Insert here the OS name and version - - ``` - - - Python version, run `python3 -V`: - - Docker version (if using Docker), run `docker --version`: - - docker-compose version (if using Docker), run `docker-compose --version`: - - ... - -- Options selected and/or [replay file](https://dxh_py.readthedocs.io/en/latest/advanced/replay.html): - On Linux and macOS: `cat ${HOME}/.dxh_py_replay/dxh_py-django.json` - (Please, take care to remove sensitive information) - -```json - -``` - - -Logs: -
-
-$ dxh_py https://github.com/dxh_py/dxh_py-django
-project_name [Project Name]: ...
-
-
-
diff --git a/.github/ISSUE_TEMPLATE/paid-support.md b/.github/ISSUE_TEMPLATE/paid-support.md deleted file mode 100644 index 1ff0a23..0000000 --- a/.github/ISSUE_TEMPLATE/paid-support.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name: Paid Support Request -about: Ask Core Team members to help you out ---- - -Provided your question goes beyond [regular support](https://github.com/dxh_py/dxh_py-django/issues/new?template=question.md), and/or the task at hand is of timely/high priority nature use the below information to reach out for contributors directly. - -- Bruno Alla, Core Developer ([GitHub](https://github.com/sponsors/browniebroke)). - -- Daniel Roy Greenfeld, Project Lead ([GitHub](https://github.com/pydanny), [Patreon](https://www.patreon.com/danielroygreenfeld)): expertise in Django and AWS ELB. - -- Nikita Shupeyko, Core Developer ([GitHub](https://github.com/webyneter)): expertise in Python/Django, hands-on DevOps and frontend experience. diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md deleted file mode 100644 index 679783d..0000000 --- a/.github/ISSUE_TEMPLATE/question.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -name: Question -about: Please ask your question on StackOverflow, Discord or GitHub Discussions. -labels: question ---- - -First, make sure to examine [the docs](https://dxh_py-django.readthedocs.io/en/latest/). If that doesn't help, we recommend one of these 3 main channels: - -- If your issue is related to Django + something else but was generated with dxh_py-django, the best is to post a question on [StackOverflow](https://stackoverflow.com/questions/tagged/dxh_py-django) tagged with `dxh_py-django`, you would get more visibility from other communities as well. -- Join us on [Discord](https://discord.gg/uFXweDQc5a) and ask around. -- Start [a discussion](https://github.com/dxh_py/dxh_py-django/discussions) on our project's GitHub. diff --git a/.github/changelog-template.md b/.github/changelog-template.md deleted file mode 100644 index 64bb717..0000000 --- a/.github/changelog-template.md +++ /dev/null @@ -1,11 +0,0 @@ -{%- for change_type, pulls in grouped_pulls.items() %} -{%- if pulls %} - -### {{ change_type }} - -{%- for pull_request in pulls %} - -- {{ pull_request.title }} ([#{{ pull_request.number }}]({{ pull_request.html_url }})) - {%- endfor -%} - {% endif -%} - {% endfor -%} diff --git a/.github/contributors.json b/.github/contributors.json deleted file mode 100644 index 37c85e1..0000000 --- a/.github/contributors.json +++ /dev/null @@ -1,1396 +0,0 @@ -[ - { - "name": "Daniel Roy Greenfeld", - "github_login": "pydanny", - "twitter_username": "pydanny", - "is_core": true - }, - { - "name": "Audrey Roy Greenfeld", - "github_login": "audreyr", - "twitter_username": "audreyr", - "is_core": true - }, - { - "name": "Fábio C. Barrionuevo da Luz", - "github_login": "luzfcb", - "twitter_username": "luzfcb", - "is_core": true - }, - { - "name": "Saurabh Kumar", - "github_login": "theskumar", - "twitter_username": "_theskumar", - "is_core": true - }, - { - "name": "Jannis Gebauer", - "github_login": "jayfk", - "twitter_username": "", - "is_core": true - }, - { - "name": "Burhan Khalid", - "github_login": "burhan", - "twitter_username": "burhan", - "is_core": true - }, - { - "name": "Shupeyko Nikita", - "github_login": "webyneter", - "twitter_username": "webyneter", - "is_core": true - }, - { - "name": "Bruno Alla", - "github_login": "browniebroke", - "twitter_username": "_BrunoAlla", - "is_core": true - }, - { - "name": "Wan Liuyang", - "github_login": "sfdye", - "twitter_username": "sfdye", - "is_core": true - }, - { - "name": "18", - "github_login": "dezoito", - "twitter_username": "" - }, - { - "name": "2O4", - "github_login": "2O4", - "twitter_username": "" - }, - { - "name": "a7p", - "github_login": "a7p", - "twitter_username": "" - }, - { - "name": "Aadith PM", - "github_login": "aadithpm", - "twitter_username": "" - }, - { - "name": "Aaron Eikenberry", - "github_login": "aeikenberry", - "twitter_username": "" - }, - { - "name": "Adam Bogdał", - "github_login": "bogdal", - "twitter_username": "" - }, - { - "name": "Adam Dobrawy", - "github_login": "ad-m", - "twitter_username": "" - }, - { - "name": "Adam Steele", - "github_login": "adammsteele", - "twitter_username": "" - }, - { - "name": "Agam Dua", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Agustín Scaramuzza", - "github_login": "scaramagus", - "twitter_username": "scaramagus" - }, - { - "name": "Alberto Sanchez", - "github_login": "alb3rto", - "twitter_username": "" - }, - { - "name": "Alex Tsai", - "github_login": "caffodian", - "twitter_username": "" - }, - { - "name": "Alvaro [Andor]", - "github_login": "andor-pierdelacabeza", - "twitter_username": "" - }, - { - "name": "Amjith Ramanujam", - "github_login": "amjith", - "twitter_username": "" - }, - { - "name": "Andreas Meistad", - "github_login": "ameistad", - "twitter_username": "" - }, - { - "name": "Andres Gonzalez", - "github_login": "andresgz", - "twitter_username": "" - }, - { - "name": "Andrew Mikhnevich", - "github_login": "zcho", - "twitter_username": "" - }, - { - "name": "Andrew Chen Wang", - "github_login": "Andrew-Chen-Wang", - "twitter_username": "" - }, - { - "name": "Andy Rose", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Anna Callahan", - "github_login": "jazztpt", - "twitter_username": "" - }, - { - "name": "Anna Sidwell", - "github_login": "takkaria", - "twitter_username": "" - }, - { - "name": "Antonia Blair", - "github_login": "antoniablair", - "twitter_username": "antoniablairart" - }, - { - "name": "Anuj Bansal", - "github_login": "ahhda", - "twitter_username": "" - }, - { - "name": "Arcuri Davide", - "github_login": "dadokkio", - "twitter_username": "" - }, - { - "name": "Areski Belaid", - "github_login": "areski", - "twitter_username": "" - }, - { - "name": "AsheKR", - "github_login": "ashekr", - "twitter_username": "" - }, - { - "name": "Ashley Camba", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Barclay Gauld", - "github_login": "yunti", - "twitter_username": "" - }, - { - "name": "Bartek", - "github_login": "btknu", - "twitter_username": "" - }, - { - "name": "Ben Lopatin", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Ben Warren", - "github_login": "bwarren2", - "twitter_username": "" - }, - { - "name": "Benjamin Abel", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Bert de Miranda", - "github_login": "bertdemiranda", - "twitter_username": "" - }, - { - "name": "Bo Lopker", - "github_login": "blopker", - "twitter_username": "" - }, - { - "name": "Bo Peng", - "github_login": "BoPeng", - "twitter_username": "" - }, - { - "name": "Bouke Haarsma", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Brent Payne", - "github_login": "brentpayne", - "twitter_username": "brentpayne" - }, - { - "name": "Bruce Olivier", - "github_login": "bolivierjr", - "twitter_username": "" - }, - { - "name": "Caio Ariede", - "github_login": "caioariede", - "twitter_username": "caioariede" - }, - { - "name": "Carl Johnson", - "github_login": "carlmjohnson", - "twitter_username": "carlmjohnson" - }, - { - "name": "Catherine Devlin", - "github_login": "catherinedevlin", - "twitter_username": "" - }, - { - "name": "Cédric Gaspoz", - "github_login": "cgaspoz", - "twitter_username": "" - }, - { - "name": "Charlie Smith", - "github_login": "chuckus", - "twitter_username": "" - }, - { - "name": "Chris Curvey", - "github_login": "ccurvey", - "twitter_username": "" - }, - { - "name": "Chris Franklin", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Chris Franklin", - "github_login": "hairychris", - "twitter_username": "" - }, - { - "name": "Chris Pappalardo", - "github_login": "ChrisPappalardo", - "twitter_username": "" - }, - { - "name": "Christopher Clarke", - "github_login": "chrisdev", - "twitter_username": "" - }, - { - "name": "Cole Mackenzie", - "github_login": "cmackenzie1", - "twitter_username": "" - }, - { - "name": "Cole Maclean", - "github_login": "cole", - "twitter_username": "cole" - }, - { - "name": "Collederas", - "github_login": "Collederas", - "twitter_username": "" - }, - { - "name": "Craig Margieson", - "github_login": "cmargieson", - "twitter_username": "" - }, - { - "name": "Cristian Vargas", - "github_login": "cdvv7788", - "twitter_username": "" - }, - { - "name": "Cullen Rhodes", - "github_login": "c-rhodes", - "twitter_username": "" - }, - { - "name": "Curtis St Pierre", - "github_login": "curtisstpierre", - "twitter_username": "cstpierre1388" - }, - { - "name": "Dan Shultz", - "github_login": "shultz", - "twitter_username": "" - }, - { - "name": "Dani Hodovic", - "github_login": "danihodovic", - "twitter_username": "" - }, - { - "name": "Daniel Hepper", - "github_login": "dhepper", - "twitter_username": "danielhepper" - }, - { - "name": "Daniel Hillier", - "github_login": "danifus", - "twitter_username": "" - }, - { - "name": "Daniel Sears", - "github_login": "highpost", - "twitter_username": "highpost" - }, - { - "name": "Daniele Tricoli", - "github_login": "eriol", - "twitter_username": "" - }, - { - "name": "David Díaz", - "github_login": "ddiazpinto", - "twitter_username": "DavidDiazPinto" - }, - { - "name": "Davit Tovmasyan", - "github_login": "davitovmasyan", - "twitter_username": "" - }, - { - "name": "Davur Clementsen", - "github_login": "dsclementsen", - "twitter_username": "davur" - }, - { - "name": "Delio Castillo", - "github_login": "jangeador", - "twitter_username": "jangeador" - }, - { - "name": "Demetris Stavrou", - "github_login": "demestav", - "twitter_username": "" - }, - { - "name": "Denis Bobrov", - "github_login": "delneg", - "twitter_username": "" - }, - { - "name": "Denis Orehovsky", - "github_login": "apirobot", - "twitter_username": "" - }, - { - "name": "Denis Savran", - "github_login": "blaxpy", - "twitter_username": "" - }, - { - "name": "Diane Chen", - "github_login": "purplediane", - "twitter_username": "purplediane88" - }, - { - "name": "Dónal Adams", - "github_login": "epileptic-fish", - "twitter_username": "" - }, - { - "name": "Dong Huynh", - "github_login": "trungdong", - "twitter_username": "" - }, - { - "name": "Duda Nogueira", - "github_login": "dudanogueira", - "twitter_username": "dudanogueira" - }, - { - "name": "Emanuel Calso", - "github_login": "bloodpet", - "twitter_username": "bloodpet" - }, - { - "name": "Eraldo Energy", - "github_login": "eraldo", - "twitter_username": "" - }, - { - "name": "Eric Groom", - "github_login": "ericgroom", - "twitter_username": "" - }, - { - "name": "Ernesto Cedeno", - "github_login": "codnee", - "twitter_username": "" - }, - { - "name": "Eyad Al Sibai", - "github_login": "eyadsibai", - "twitter_username": "" - }, - { - "name": "Felipe Arruda", - "github_login": "arruda", - "twitter_username": "" - }, - { - "name": "Florian Idelberger", - "github_login": "step21", - "twitter_username": "windrush" - }, - { - "name": "Gabriel Mejia", - "github_login": "elgartoinf", - "twitter_username": "elgartoinf" - }, - { - "name": "Garry Cairns", - "github_login": "garry-cairns", - "twitter_username": "" - }, - { - "name": "Garry Polley", - "github_login": "garrypolley", - "twitter_username": "" - }, - { - "name": "Gilbishkosma", - "github_login": "Gilbishkosma", - "twitter_username": "" - }, - { - "name": "Glenn Wiskur", - "github_login": "gwiskur", - "twitter_username": "" - }, - { - "name": "Guilherme Guy", - "github_login": "guilherme1guy", - "twitter_username": "" - }, - { - "name": "Hamish Durkin", - "github_login": "durkode", - "twitter_username": "" - }, - { - "name": "Hana Quadara", - "github_login": "hanaquadara", - "twitter_username": "" - }, - { - "name": "Hannah Lazarus", - "github_login": "hanhanhan", - "twitter_username": "" - }, - { - "name": "Harry Moreno", - "github_login": "morenoh149", - "twitter_username": "morenoh149" - }, - { - "name": "Harry Percival", - "github_login": "hjwp", - "twitter_username": "" - }, - { - "name": "Hendrik Schneider", - "github_login": "hendrikschneider", - "twitter_username": "" - }, - { - "name": "Henrique G. G. Pereira", - "github_login": "ikkebr", - "twitter_username": "" - }, - { - "name": "Howie Zhao", - "github_login": "howiezhao", - "twitter_username": "" - }, - { - "name": "Ian Lee", - "github_login": "IanLee1521", - "twitter_username": "" - }, - { - "name": "Irfan Ahmad", - "github_login": "erfaan", - "twitter_username": "erfaan" - }, - { - "name": "Isaac12x", - "github_login": "Isaac12x", - "twitter_username": "" - }, - { - "name": "Ivan Khomutov", - "github_login": "ikhomutov", - "twitter_username": "" - }, - { - "name": "James Williams", - "github_login": "jameswilliams1", - "twitter_username": "" - }, - { - "name": "Jan Van Bruggen", - "github_login": "jvanbrug", - "twitter_username": "" - }, - { - "name": "Jelmer Draaijer", - "github_login": "foarsitter", - "twitter_username": "" - }, - { - "name": "Jerome Caisip", - "github_login": "jeromecaisip", - "twitter_username": "" - }, - { - "name": "Jens Nilsson", - "github_login": "phiberjenz", - "twitter_username": "" - }, - { - "name": "Jerome Leclanche", - "github_login": "jleclanche", - "twitter_username": "Adys" - }, - { - "name": "Jimmy Gitonga", - "github_login": "Afrowave", - "twitter_username": "afrowave" - }, - { - "name": "John Cass", - "github_login": "jcass77", - "twitter_username": "cass_john" - }, - { - "name": "Jonathan Thompson", - "github_login": "nojanath", - "twitter_username": "" - }, - { - "name": "Jules Cheron", - "github_login": "jules-ch", - "twitter_username": "" - }, - { - "name": "Julien Almarcha", - "github_login": "sladinji", - "twitter_username": "" - }, - { - "name": "Julio Castillo", - "github_login": "juliocc", - "twitter_username": "" - }, - { - "name": "Kaido Kert", - "github_login": "kaidokert", - "twitter_username": "" - }, - { - "name": "kappataumu", - "github_login": "kappataumu", - "twitter_username": "kappataumu" - }, - { - "name": "Kaveh", - "github_login": "ka7eh", - "twitter_username": "" - }, - { - "name": "Keith Bailey", - "github_login": "keithjeb", - "twitter_username": "" - }, - { - "name": "Keith Webber", - "github_login": "townie", - "twitter_username": "" - }, - { - "name": "Kevin A. Stone", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Kevin Ndung'u", - "github_login": "kevgathuku", - "twitter_username": "" - }, - { - "name": "Keyvan Mosharraf", - "github_login": "keyvanm", - "twitter_username": "" - }, - { - "name": "Krzysztof Szumny", - "github_login": "noisy", - "twitter_username": "" - }, - { - "name": "Krzysztof Żuraw", - "github_login": "krzysztofzuraw", - "twitter_username": "" - }, - { - "name": "Leo won", - "github_login": "leollon", - "twitter_username": "" - }, - { - "name": "Leo Zhou", - "github_login": "glasslion", - "twitter_username": "" - }, - { - "name": "Leon Kim", - "github_login": "PilhwanKim", - "twitter_username": "" - }, - { - "name": "Leonardo Jimenez", - "github_login": "xpostudio4", - "twitter_username": "" - }, - { - "name": "Lin Xianyi", - "github_login": "iynaix", - "twitter_username": "" - }, - { - "name": "Luis Nell", - "github_login": "originell", - "twitter_username": "" - }, - { - "name": "Lukas Klein", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Lyla Fischer", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Malik Sulaimanov", - "github_login": "flyudvik", - "twitter_username": "flyudvik" - }, - { - "name": "Martin Blech", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Martin Saizar", - "github_login": "msaizar", - "twitter_username": "" - }, - { - "name": "Mateusz Ostaszewski", - "github_login": "mostaszewski", - "twitter_username": "" - }, - { - "name": "Mathijs Hoogland", - "github_login": "MathijsHoogland", - "twitter_username": "" - }, - { - "name": "Matt Braymer-Hayes", - "github_login": "mattayes", - "twitter_username": "mattayes" - }, - { - "name": "Matt Knapper", - "github_login": "mknapper1", - "twitter_username": "" - }, - { - "name": "Matt Linares", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Matt Menzenski", - "github_login": "menzenski", - "twitter_username": "" - }, - { - "name": "Matt Warren", - "github_login": "mfwarren", - "twitter_username": "" - }, - { - "name": "Matthew Sisley", - "github_login": "mjsisley", - "twitter_username": "" - }, - { - "name": "Matthias Sieber", - "github_login": "manonthemat", - "twitter_username": "MatzeOne" - }, - { - "name": "Meghan Heintz", - "github_login": "dot2dotseurat", - "twitter_username": "" - }, - { - "name": "Mesut Yılmaz", - "github_login": "myilmaz", - "twitter_username": "" - }, - { - "name": "Michael Gecht", - "github_login": "mimischi", - "twitter_username": "_mischi" - }, - { - "name": "Michael Samoylov", - "github_login": "msamoylov", - "twitter_username": "" - }, - { - "name": "Min ho Kim", - "github_login": "minho42", - "twitter_username": "" - }, - { - "name": "mozillazg", - "github_login": "mozillazg", - "twitter_username": "" - }, - { - "name": "Nico Stefani", - "github_login": "nicolas471", - "twitter_username": "moby_dick91" - }, - { - "name": "Oleg Russkin", - "github_login": "rolep", - "twitter_username": "" - }, - { - "name": "Pablo", - "github_login": "oubiga", - "twitter_username": "" - }, - { - "name": "Parbhat Puri", - "github_login": "parbhat", - "twitter_username": "" - }, - { - "name": "Pawan Chaurasia", - "github_login": "rjsnh1522", - "twitter_username": "" - }, - { - "name": "Peter Bittner", - "github_login": "bittner", - "twitter_username": "" - }, - { - "name": "Peter Coles", - "github_login": "mrcoles", - "twitter_username": "" - }, - { - "name": "Philipp Matthies", - "github_login": "canonnervio", - "twitter_username": "" - }, - { - "name": "Pierre Chiquet", - "github_login": "pchiquet", - "twitter_username": "" - }, - { - "name": "Raony Guimarães Corrêa", - "github_login": "raonyguimaraes", - "twitter_username": "" - }, - { - "name": "Raphael Pierzina", - "github_login": "hackebrot", - "twitter_username": "" - }, - { - "name": "Reggie Riser", - "github_login": "reggieriser", - "twitter_username": "" - }, - { - "name": "René Muhl", - "github_login": "rm--", - "twitter_username": "" - }, - { - "name": "Richard Hajdu", - "github_login": "Tusky", - "twitter_username": "" - }, - { - "name": "Roman Afanaskin", - "github_login": "siauPatrick", - "twitter_username": "" - }, - { - "name": "Roman Osipenko", - "github_login": "romanosipenko", - "twitter_username": "" - }, - { - "name": "Russell Davies", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Sam Collins", - "github_login": "MightySCollins", - "twitter_username": "" - }, - { - "name": "Sascha", - "github_login": "saschalalala", - "twitter_username": "saschalalala" - }, - { - "name": "Sławek Ehlert", - "github_login": "slafs", - "twitter_username": "" - }, - { - "name": "Sorasful", - "github_login": "sorasful", - "twitter_username": "" - }, - { - "name": "Srinivas Nyayapati", - "github_login": "shireenrao", - "twitter_username": "" - }, - { - "name": "stepmr", - "github_login": "stepmr", - "twitter_username": "" - }, - { - "name": "Steve Steiner", - "github_login": "ssteinerX", - "twitter_username": "" - }, - { - "name": "Sudarshan Wadkar", - "github_login": "wadkar", - "twitter_username": "" - }, - { - "name": "Sule Marshall", - "github_login": "suledev", - "twitter_username": "" - }, - { - "name": "Tano Abeleyra", - "github_login": "tanoabeleyra", - "twitter_username": "" - }, - { - "name": "Taylor Baldwin", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Théo Segonds", - "github_login": "show0k", - "twitter_username": "" - }, - { - "name": "Tim Claessens", - "github_login": "timclaessens", - "twitter_username": "" - }, - { - "name": "Tim Freund", - "github_login": "timfreund", - "twitter_username": "" - }, - { - "name": "Tom Atkins", - "github_login": "knitatoms", - "twitter_username": "" - }, - { - "name": "Tom Offermann", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Travis McNeill", - "github_login": "Travistock", - "twitter_username": "tavistock_esq" - }, - { - "name": "Tubo Shi", - "github_login": "Tubo", - "twitter_username": "" - }, - { - "name": "Umair Ashraf", - "github_login": "umrashrf", - "twitter_username": "fabumair" - }, - { - "name": "Vadim Iskuchekov", - "github_login": "Egregors", - "twitter_username": "egregors" - }, - { - "name": "Vicente G. Reyes", - "github_login": "reyesvicente", - "twitter_username": "highcenburg" - }, - { - "name": "Vitaly Babiy", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Vivian Guillen", - "github_login": "viviangb", - "twitter_username": "" - }, - { - "name": "Vlad Doster", - "github_login": "vladdoster", - "twitter_username": "" - }, - { - "name": "Will Farley", - "github_login": "goldhand", - "twitter_username": "g01dhand" - }, - { - "name": "William Archinal", - "github_login": "archinal", - "twitter_username": "" - }, - { - "name": "Xaver Y.R. Chen", - "github_login": "yrchen", - "twitter_username": "yrchen" - }, - { - "name": "Yaroslav Halchenko", - "github_login": "", - "twitter_username": "" - }, - { - "name": "Yuchen Xie", - "github_login": "mapx", - "twitter_username": "" - }, - { - "name": "enchance", - "github_login": "enchance", - "twitter_username": "" - }, - { - "name": "Jan Fabry", - "github_login": "janfabry", - "twitter_username": "" - }, - { - "name": "Corey Garvey", - "github_login": "coreygarvey", - "twitter_username": "" - }, - { - "name": "Arnav Choudhury", - "github_login": "arnav13081994", - "twitter_username": "" - }, - { - "name": "Wes Turner", - "github_login": "westurner", - "twitter_username": "westurner" - }, - { - "name": "Jakub Musko", - "github_login": "umgelurgel", - "twitter_username": "" - }, - { - "name": "Fabian Affolter", - "github_login": "fabaff", - "twitter_username": "fabaff" - }, - { - "name": "Simon Rey", - "github_login": "eqqe", - "twitter_username": "" - }, - { - "name": "Yotam Tal", - "github_login": "yotamtal", - "twitter_username": "" - }, - { - "name": "John", - "github_login": "thorrak", - "twitter_username": "" - }, - { - "name": "vascop", - "github_login": "vascop", - "twitter_username": "" - }, - { - "name": "PJ Hoberman", - "github_login": "pjhoberman", - "twitter_username": "" - }, - { - "name": "lcd1232", - "github_login": "lcd1232", - "twitter_username": "" - }, - { - "name": "Tames McTigue", - "github_login": "Tamerz", - "twitter_username": "" - }, - { - "name": "Ray Besiga", - "github_login": "raybesiga", - "twitter_username": "raybesiga" - }, - { - "name": "Grant McLean", - "github_login": "grantm", - "twitter_username": "grantmnz" - }, - { - "name": "Kuo Chao Cheng", - "github_login": "wwwtony5488", - "twitter_username": "" - }, - { - "name": "LECbg", - "github_login": "LECbg", - "twitter_username": "" - }, - { - "name": "Haseeb ur Rehman", - "github_login": "professorhaseeb", - "twitter_username": "professorhaseeb" - }, - { - "name": "Abdul Qoyyuum", - "github_login": "Qoyyuum", - "twitter_username": "Qoyyuum" - }, - { - "name": "mfosterw", - "github_login": "mfosterw", - "twitter_username": "" - }, - { - "name": "Keith Callenberg", - "github_login": "keithcallenberg", - "twitter_username": "" - }, - { - "name": "Mike97M", - "github_login": "Mike97M", - "twitter_username": "" - }, - { - "name": "Charlie Macfarlane Brodie", - "github_login": "tannart", - "twitter_username": "" - }, - { - "name": "Floyd Hightower", - "github_login": "fhightower", - "twitter_username": "" - }, - { - "name": "Manjit Pardeshi", - "github_login": "Manjit2003", - "twitter_username": "" - }, - { - "name": "Meraj ", - "github_login": "ichbinmeraj", - "twitter_username": "merajsafari" - }, - { - "name": "dalrrard", - "github_login": "dalrrard", - "twitter_username": "" - }, - { - "name": "Liam Brenner", - "github_login": "SableWalnut", - "twitter_username": "" - }, - { - "name": "Noah H", - "github_login": "nthall", - "twitter_username": "" - }, - { - "name": "Diego Montes", - "github_login": "d57montes", - "twitter_username": "" - }, - { - "name": "Chao Yang Wu", - "github_login": "goatwu1993", - "twitter_username": "" - }, - { - "name": "mpoli", - "github_login": "mpoli", - "twitter_username": "" - }, - { - "name": "Zach Borboa", - "github_login": "zachborboa", - "twitter_username": "" - }, - { - "name": "Timm Simpkins", - "github_login": "PoDuck", - "twitter_username": "" - }, - { - "name": "Douglas", - "github_login": "douglascdev", - "twitter_username": "" - }, - { - "name": "Will Gordon", - "github_login": "wgordon17", - "twitter_username": "" - }, - { - "name": "Bogdan Mateescu", - "github_login": "mateesville93", - "twitter_username": "" - }, - { - "name": "Fuzzwah", - "github_login": "Fuzzwah", - "twitter_username": "" - }, - { - "name": "Thibault J.", - "github_login": "thibault", - "twitter_username": "thibault" - }, - { - "name": "Pedro Campos", - "github_login": "pcampos119104", - "twitter_username": "" - }, - { - "name": "Vikas Yadav", - "github_login": "vik-y", - "twitter_username": "" - }, - { - "name": "Abdullah Adeel", - "github_login": "mabdullahadeel", - "twitter_username": "abdadeel_" - }, - { - "name": "Jorge Valdez", - "github_login": "jorgeavaldez", - "twitter_username": "" - }, - { - "name": "Ryan Fitch", - "github_login": "ryfi", - "twitter_username": "" - }, - { - "name": "ghazi-git", - "github_login": "ghazi-git", - "twitter_username": "" - }, - { - "name": "Cebrail Yılmaz", - "github_login": "b1sar", - "twitter_username": "" - }, - { - "name": "Artur Barseghyan", - "github_login": "barseghyanartur", - "twitter_username": "" - }, - { - "name": "innicoder", - "github_login": "innicoder", - "twitter_username": "" - }, - { - "name": "Naveen", - "github_login": "naveensrinivasan", - "twitter_username": "snaveen" - }, - { - "name": "Nikita Sobolev", - "github_login": "sobolevn", - "twitter_username": "" - }, - { - "name": "Sebastian Reyes Espinosa", - "github_login": "sebastian-code", - "twitter_username": "sebastianreyese" - }, - { - "name": "jugglinmike", - "github_login": "jugglinmike", - "twitter_username": "" - }, - { - "name": "monosans", - "github_login": "monosans", - "twitter_username": "" - }, - { - "name": "Marcio Mazza", - "github_login": "marciomazza", - "twitter_username": "marciomazza" - }, - { - "name": "Brandon Rumiser", - "github_login": "brumiser1550", - "twitter_username": "" - }, - { - "name": "krati yadav", - "github_login": "krati5", - "twitter_username": "" - }, - { - "name": "Abe Hanoka", - "github_login": "abe-101", - "twitter_username": "abe__101" - }, - { - "name": "Adin Hodovic", - "github_login": "adinhodovic", - "twitter_username": "" - }, - { - "name": "Leifur Halldor Asgeirsson", - "github_login": "leifurhauks", - "twitter_username": "" - }, - { - "name": "David", - "github_login": "buckldav", - "twitter_username": "" - }, - { - "name": "rguptar", - "github_login": "rguptar", - "twitter_username": "" - }, - { - "name": "Omer-5", - "github_login": "Omer-5", - "twitter_username": "" - }, - { - "name": "TAKAHASHI Shuuji", - "github_login": "shuuji3", - "twitter_username": "" - }, - { - "name": "Thomas Booij", - "github_login": "ThomasBooij95", - "twitter_username": "" - }, - { - "name": "Pamela Fox", - "github_login": "pamelafox", - "twitter_username": "pamelafox" - }, - { - "name": "Robin", - "github_login": "Kaffeetasse", - "twitter_username": "" - }, - { - "name": "Patrick Tran", - "github_login": "theptrk", - "twitter_username": "" - }, - { - "name": "tildebox", - "github_login": "tildebox", - "twitter_username": "" - }, - { - "name": "duffn", - "github_login": "duffn", - "twitter_username": "" - }, - { - "name": "Delphine LEMIRE", - "github_login": "DelphineLemire", - "twitter_username": "" - }, - { - "name": "Hoai-Thu Vuong", - "github_login": "thuvh", - "twitter_username": "" - }, - { - "name": "Arkadiusz Michał Ryś", - "github_login": "arrys", - "twitter_username": "" - }, - { - "name": "mpsantos", - "github_login": "mpsantos", - "twitter_username": "" - }, - { - "name": "Morten Kaae", - "github_login": "MortenKaae", - "twitter_username": "" - }, - { - "name": "Birtibu", - "github_login": "Birtibu", - "twitter_username": "" - } -] \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1b228e3..41544c3 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,13 +3,29 @@ version: 2 updates: + # Update Python deps for the template (not the generated project) + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "daily" + labels: + - "project infrastructure" + + # Update Python deps for the documentation + - package-ecosystem: "pip" + directory: "docs/" + schedule: + interval: "daily" + labels: + - "project infrastructure" + # Update GitHub actions in workflows - package-ecosystem: "github-actions" directory: "/" schedule: interval: "daily" labels: - - "update" + - "project infrastructure" # Update npm packages - package-ecosystem: "npm" @@ -85,4 +101,4 @@ updates: schedule: interval: "daily" labels: - - "update" + - "update" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7438d9..2f1ed80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,7 @@ name: CI on: push: + branches: ["master", "main"] pull_request: concurrency: @@ -9,17 +10,6 @@ concurrency: cancel-in-progress: true jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.11" - cache: pip - - name: Run pre-commit - uses: pre-commit/action@v3.0.0 - tests: strategy: fail-fast: false @@ -29,44 +19,44 @@ jobs: - windows-latest - macOS-latest - name: "Run tests" + name: "pytest ${{ matrix.os }}" runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: - python-version: "3.11" + python-version: "3.12" cache: pip - name: Install dependencies run: pip install -r requirements.txt - name: Run tests - run: pytest tests + run: pytest -n auto tests docker: strategy: fail-fast: false matrix: script: - - name: Basic - Postgres - args: "database_engine=postgresql database_version='postgresql@14'" - - name: Extended - Postgres - args: "use_celery=y use_drf=y frontend_pipeline=Gulp database_engine=postgresql database_version='postgresql@14'" - - name: Basic - MySQL - args: "database_engine=mysql database_version='mysql@8.0.29'" - - name: Extended - MySQL - args: "use_celery=y use_drf=y frontend_pipeline=Gulp database_engine=mysql database_version='mysql@8.0.29'" + - name: Basic + args: "ci_tool=Gitlab" + - name: Celery & DRF + args: "use_celery=y use_drf=y" + - name: Gulp + args: "frontend_pipeline=Gulp" + - name: Webpack + args: "frontend_pipeline=Webpack" - name: "${{ matrix.script.name }} Docker" + name: "Docker ${{ matrix.script.name }}" runs-on: ubuntu-latest env: DOCKER_BUILDKIT: 1 COMPOSE_DOCKER_CLI_BUILD: 1 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: - python-version: "3.11" + python-version: "3.12" cache: pip - name: Install dependencies run: pip install -r requirements.txt @@ -78,15 +68,16 @@ jobs: fail-fast: false matrix: script: - - name: With Celery - args: "use_celery=y frontend_pipeline='Django Compressor' database_engine=postgresql database_version=postgresql@14" - # postgres://user:password@host:port/database - database_url: "postgres://postgres:postgres@localhost:5432/postgres" - - name: With Gulp - args: "frontend_pipeline='Gulp' custom_bootstrap_compilation=y database_engine=postgresql database_version=postgresql@14" - database_url: "postgres://postgres:postgres@localhost:5432/postgres" + - name: Celery + args: "use_celery=y frontend_pipeline='Django Compressor'" + - name: Gulp + args: "frontend_pipeline=Gulp" + - name: Webpack + args: "frontend_pipeline=Webpack use_heroku=y" + - name: Email Username + args: "username_type=email ci_tool=Github project_name='Something superduper long - the great amazing project' project_slug=my_awesome_project" - name: "${{ matrix.script.name }} Bare metal" + name: "Bare metal ${{ matrix.script.name }}" runs-on: ubuntu-latest services: redis: @@ -102,13 +93,14 @@ jobs: env: CELERY_BROKER_URL: "redis://localhost:6379/0" - DATABASE_URL: ${{ matrix.script.database_url }} + # postgres://user:password@host:port/database + DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres" steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: - python-version: "3.11" + python-version: "3.12" cache: pip cache-dependency-path: | requirements.txt @@ -116,8 +108,8 @@ jobs: {{dxh_py.project_slug}}/requirements/local.txt - name: Install dependencies run: pip install -r requirements.txt - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: - node-version: "18" + node-version: "22" - name: Bare Metal ${{ matrix.script.name }} run: sh tests/test_bare.sh ${{ matrix.script.args }} diff --git a/.github/workflows/django-issue-checker.yml b/.github/workflows/django-issue-checker.yml deleted file mode 100644 index 5800193..0000000 --- a/.github/workflows/django-issue-checker.yml +++ /dev/null @@ -1,30 +0,0 @@ -# Creates a new issue for Major/Minor Django updates that keeps track -# of all dependencies that need to be updated/merged in order for the -# latest Django version to also be merged. -name: Django Issue Checker - -on: - schedule: - - cron: "28 5 * * *" - # Manual trigger - workflow_dispatch: - -jobs: - issue-checker: - # Disables this workflow from running in a repository that is not part of the indicated organization/user - if: github.repository_owner == 'dxh_py' - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - name: Create Django Major Issue - run: python scripts/create_django_issue.py - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/issue-manager.yml b/.github/workflows/issue-manager.yml deleted file mode 100644 index 13fd6cc..0000000 --- a/.github/workflows/issue-manager.yml +++ /dev/null @@ -1,40 +0,0 @@ -# Automatically close issues or pull requests that have a label, after a custom delay, if no one replies. -# https://github.com/tiangolo/issue-manager -name: Issue Manager - -on: - schedule: - - cron: "12 0 * * *" - issue_comment: - types: - - created - issues: - types: - - labeled - pull_request_target: - types: - - labeled - workflow_dispatch: - -jobs: - issue-manager: - # Disables this workflow from running in a repository that is not part of the indicated organization/user - if: github.repository_owner == 'dxh_py' - - runs-on: ubuntu-latest - steps: - - uses: tiangolo/issue-manager@0.4.0 - with: - token: ${{ secrets.GITHUB_TOKEN }} - config: > - { - "answered": { - "message": "Assuming the question was answered, this will be automatically closed now." - }, - "solved": { - "message": "Assuming the original issue was solved, it will be automatically closed now." - }, - "waiting": { - "message": "Automatically closing after waiting for additional info. To re-open, please provide the additional information requested." - } - } diff --git a/.github/workflows/pre-commit-autoupdate.yml b/.github/workflows/pre-commit-autoupdate.yml deleted file mode 100644 index 91e0dee..0000000 --- a/.github/workflows/pre-commit-autoupdate.yml +++ /dev/null @@ -1,47 +0,0 @@ -# Run pre-commit autoupdate every day at midnight -# and create a pull request if any changes - -name: Pre-commit auto-update - -on: - schedule: - - cron: "15 2 * * *" - workflow_dispatch: # to trigger manually - -permissions: - contents: read - -jobs: - auto-update: - # Disables this workflow from running in a repository that is not part of the indicated organization/user - if: github.repository_owner == 'dxh_py' - permissions: - contents: write # for peter-evans/create-pull-request to create branch - pull-requests: write # for peter-evans/create-pull-request to create a PR - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - - name: Install pre-commit - run: pip install pre-commit - - - name: Autoupdate template - run: pre-commit autoupdate - - - name: Autoupdate generated projects - working-directory: "{{dxh_py.project_slug}}" - run: pre-commit autoupdate - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v4 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: update/pre-commit-autoupdate - title: Auto-update pre-commit hooks - commit-message: Auto-update pre-commit hooks - body: Update versions of tools in pre-commit configs to latest version - labels: update diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml deleted file mode 100644 index 472427f..0000000 --- a/.github/workflows/update-changelog.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Update Changelog - -on: - # Every day at 2am - schedule: - - cron: "0 2 * * *" - # Manual trigger - workflow_dispatch: - -jobs: - release: - # Disables this workflow from running in a repository that is not part of the indicated organization/user - if: github.repository_owner == 'dxh_py' - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - name: Set git details - run: | - git config --global user.name "github-actions" - git config --global user.email "action@github.com" - - name: Update list - run: python scripts/update_changelog.py - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/update-contributors.yml b/.github/workflows/update-contributors.yml deleted file mode 100644 index d610a6f..0000000 --- a/.github/workflows/update-contributors.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Update Contributors - -on: - push: - branches: - - master - -permissions: - contents: read - -jobs: - build: - # Disables this workflow from running in a repository that is not part of the indicated organization/user - if: github.repository_owner == 'dxh_py' - permissions: - contents: write # for stefanzweifel/git-auto-commit-action to push code in repo - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - name: Update list - run: python scripts/update_contributors.py - - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4.16.0 - with: - commit_message: Update Contributors - file_pattern: CONTRIBUTORS.md .github/contributors.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8866b5c..0d66a9f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,12 @@ exclude: "{{dxh_py.project_slug}}|.github/contributors.json|CHANGELOG.md|CONTRIBUTORS.md" default_stages: [commit] +default_language_version: + python: python3.12 + repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -17,34 +20,34 @@ repos: - id: detect-private-key - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v3.0.0-alpha.9-for-vscode" + rev: "v4.0.0-alpha.8" hooks: - id: prettier args: ["--tab-width", "2"] - repo: https://github.com/asottile/pyupgrade - rev: v3.3.2 + rev: v3.17.0 hooks: - id: pyupgrade - args: [--py311-plus] + args: [--py312-plus] exclude: hooks/ - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 24.8.0 hooks: - id: black - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 7.1.1 hooks: - id: flake8 ci: autoupdate_schedule: weekly skip: [] - submodules: false + submodules: false \ No newline at end of file diff --git a/.readthedocs.yaml b/.readthedocs.yaml index beb30d8..ed9d8fd 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -4,12 +4,17 @@ # Required version: 2 +# Set the version of Python and other tools you might need +build: + os: ubuntu-22.04 + tools: + python: "3.12" + # Build documentation in the docs/ directory with Sphinx sphinx: configuration: docs/conf.py -# Version of Python and requirements required to build the docs +# Declare the Python requirements required to build your docs python: - version: "3.8" install: - - requirements: docs/requirements.txt + - requirements: docs/requirements.txt \ No newline at end of file diff --git a/README.md b/README.md index 71a7d3b..f70cbbd 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## Features - For Django 4.1 -- Works with Python 3.11 +- Works with Python 3.12 - Renders Django projects with 100% starting test coverage - Twitter [Bootstrap](https://github.com/twbs/bootstrap) v5 - [12-Factor](http://12factor.net/) based settings via [django-environ](https://github.com/joke2k/django-environ) @@ -103,15 +103,17 @@ Answer the prompts with your own desired. For example: 2 - mysql Choose from [1/2] (1): [15/30] Select database_version - 1 - postgresql@14 - 2 - postgresql@13 - 3 - postgresql@12 - 4 - postgresql@11 - 5 - postgresql@10 - 6 - mysql@8.0.30 - 7 - mysql@8.0 - 8 - mysql@5.7 - Choose from [1/2/3/4/5/6/7/8] (1): + 1 - postgresql@16 + 2 - postgresql@15 + 3 - postgresql@14 + 4 - postgresql@13 + 5 - postgresql@12 + 6 - postgresql@11 + 7 - postgresql@10 + 8 - mysql@8.0.30 + 9 - mysql@8.0 + 10 - mysql@5.7 + Choose from [1/2/3/4/5/6/7/8/9/10] (1): [16/30] use_tenants (n): [17/30] Select cloud_provider 1 - AWS @@ -126,7 +128,7 @@ Answer the prompts with your own desired. For example: 4 - Mandrill 5 - Postmark 6 - Sendgrid - 7 - SendinBlue + 7 - Brevo 8 - SparkPost 9 - Other SMTP Choose from [1/2/3/4/5/6/7/8/9] (1): diff --git a/docs/conf.py b/docs/conf.py index c74635e..8dfd680 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,4 @@ -# dxh_py-django documentation build configuration file. +# django boilerplate documentation build configuration file. # # This file is execfile()d with the current directory set to its containing dir. # @@ -38,8 +38,8 @@ master_doc = "index" # General information about the project. -project = "dxh_py Django" -copyright = f"2013-{now.year}, Daniel Roy Greenfeld" +project = "Django Boilerplate" +copyright = f"2013-{now.year}, DevxhuB" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -218,7 +218,7 @@ "index", "dxh_py Django", "dxh_py Django documentation", - ["Daniel Roy Greenfeld"], + ["DevxhuB"], 1, ) ] @@ -237,7 +237,7 @@ "index", "dxh_py Django", "dxh_py Django documentation", - "Daniel Roy Greenfeld", + "DevxhuB", "dxh_py Django", "A dxh_py template for creating production-ready " "Django projects quickly.", "Miscellaneous", diff --git a/docs/deployment-on-heroku.rst b/docs/deployment-on-heroku.rst index a5e8817..0eab476 100644 --- a/docs/deployment-on-heroku.rst +++ b/docs/deployment-on-heroku.rst @@ -46,7 +46,7 @@ Run these commands to deploy the project to Heroku: # Assign with AWS_STORAGE_BUCKET_NAME heroku config:set DJANGO_AWS_STORAGE_BUCKET_NAME= - git push heroku master + git push heroku main heroku run python manage.py createsuperuser @@ -69,7 +69,7 @@ The script above assumes that you've chose Mailgun as email service. If you want Heroku & Docker +++++++++++++++ -Although Heroku has some sort of `Docker support`_, it's not supported by dxh_py-django. +Although Heroku has some sort of `Docker support`_, it's not supported by django boilarplate. We invite you to follow Heroku documentation about it. .. _Docker support: https://devcenter.heroku.com/articles/build-docker-images-heroku-yml diff --git a/docs/deployment-on-pythonanywhere.rst b/docs/deployment-on-pythonanywhere.rst index 66226a4..a288ec3 100644 --- a/docs/deployment-on-pythonanywhere.rst +++ b/docs/deployment-on-pythonanywhere.rst @@ -37,7 +37,7 @@ Make sure your project is fully committed and pushed up to Bitbucket or Github o mkvirtualenv --python=/usr/bin/python3.10 my-project-name pip install -r requirements/production.txt # may take a few minutes -.. note:: We're creating the virtualenv using Python 3.10 (``--python=/usr/bin/python3.10```), although dxh_py Django generates a project for Python 3.11. This is because, at time of writing, PythonAnywhere only supports Python 3.10. It shouldn't be a problem, but if is, you may try changing the Python version to 3.11 and see if it works. If it does, please let us know, or even better, submit a pull request to update this section. +.. note:: We're creating the virtualenv using Python 3.10 (``--python=/usr/bin/python3.10```), although Django Boilarplate generates a project for Python 3.12. This is because, at time of writing, PythonAnywhere only supports Python 3.10. It shouldn't be a problem, but if is, you may try changing the Python version to 3.12 and see if it works. If it does, please let us know, or even better, submit a pull request to update this section. Setting environment variables in the console -------------------------------------------- @@ -118,7 +118,7 @@ Now run the migration, and collectstatic: Redis ----- -PythonAnywhere does NOT `offer a built-in solution `_ for Redis, however the production setup from dxh_py Django uses Redis as cache and requires one. +PythonAnywhere does NOT `offer a built-in solution `_ for Redis, however the production setup from Django Boilarplate uses Redis as cache and requires one. We recommend to signup to a separate service offering hosted Redis (e.g. `Redislab `_) and use the URL they provide. diff --git a/docs/deployment-with-docker.rst b/docs/deployment-with-docker.rst index 0ef778b..051c700 100644 --- a/docs/deployment-with-docker.rst +++ b/docs/deployment-with-docker.rst @@ -1,7 +1,7 @@ Deployment with Docker ====================== -.. index:: deployment, docker, docker-compose, compose +.. index:: deployment, docker, docker compose, compose Prerequisites @@ -89,7 +89,7 @@ You can read more about this feature and how to configure it, at `Automatic HTTP Webpack without Whitenoise limitation ------------------------------------- -If you opt for Webpack without Whitenoise, Webpack needs to know the static URL at build time, when running ``docker-compose build`` (See ``webpack/prod.config.js``). Depending on your setup, this URL may come from the following environment variables: +If you opt for Webpack without Whitenoise, Webpack needs to know the static URL at build time, when running ``docker compose build`` (See ``webpack/prod.config.js``). Depending on your setup, this URL may come from the following environment variables: - ``AWS_STORAGE_BUCKET_NAME`` - ``DJANGO_AWS_S3_CUSTOM_DOMAIN`` @@ -107,7 +107,7 @@ To solve this, you can either: 2. create a ``.env`` file in the root of the project with just variables you need. You'll need to also define them in ``.envs/.production/.django`` (hence duplicating them). 3. set these variables when running the build command:: - DJANGO_AWS_S3_CUSTOM_DOMAIN=example.com docker-compose -f production.yml build``. + DJANGO_AWS_S3_CUSTOM_DOMAIN=example.com docker compose -f production.yml build``. None of these options are ideal, we're open to suggestions on how to improve this. If you think you have one, please open an issue or a pull request. @@ -122,42 +122,42 @@ Building & Running Production Stack You will need to build the stack first. To do that, run:: - docker-compose -f production.yml build + docker compose -f production.yml build Once this is ready, you can run it with:: - docker-compose -f production.yml up + docker compose -f production.yml up To run the stack and detach the containers, run:: - docker-compose -f production.yml up -d + docker compose -f production.yml up -d To run a migration, open up a second terminal and run:: - docker-compose -f production.yml run --rm django python manage.py migrate + docker compose -f production.yml run --rm django python manage.py migrate To create a superuser, run:: - docker-compose -f production.yml run --rm django python manage.py createsuperuser + docker compose -f production.yml run --rm django python manage.py createsuperuser If you need a shell, run:: - docker-compose -f production.yml run --rm django python manage.py shell + docker compose -f production.yml run --rm django python manage.py shell To check the logs out, run:: - docker-compose -f production.yml logs + docker compose -f production.yml logs If you want to scale your application, run:: - docker-compose -f production.yml up --scale django=4 - docker-compose -f production.yml up --scale celeryworker=2 + docker compose -f production.yml up --scale django=4 + docker compose -f production.yml up --scale celeryworker=2 .. warning:: don't try to scale ``postgres``, ``celerybeat``, or ``traefik``. To see how your containers are doing run:: - docker-compose -f production.yml ps + docker compose -f production.yml ps Example: Supervisor @@ -165,12 +165,12 @@ Example: Supervisor Once you are ready with your initial setup, you want to make sure that your application is run by a process manager to survive reboots and auto restarts in case of an error. You can use the process manager you are most familiar with. All -it needs to do is to run ``docker-compose -f production.yml up`` in your projects root directory. +it needs to do is to run ``docker compose -f production.yml up`` in your projects root directory. If you are using ``supervisor``, you can use this file as a starting point:: [program:{{dxh_py.project_slug}}] - command=docker-compose -f production.yml up + command=docker compose -f production.yml up directory=/path/to/{{dxh_py.project_slug}} redirect_stderr=true autostart=true @@ -190,4 +190,4 @@ For status check, run:: Media files without cloud provider ---------------------------------- -If you chose no cloud provider and Docker, the media files will be served by an nginx service, from a ``production_django_media`` volume. Make sure to keep this around to avoid losing any media files. +If you chose no cloud provider and Docker, the media files will be served by an nginx service, from a ``production_django_media`` volume. Make sure to keep this around to avoid losing any media files. \ No newline at end of file diff --git a/docs/developing-locally-docker.rst b/docs/developing-locally-docker.rst index f951e39..6247592 100644 --- a/docs/developing-locally-docker.rst +++ b/docs/developing-locally-docker.rst @@ -16,12 +16,12 @@ Prerequisites * Docker; if you don't have it yet, follow the `installation instructions`_; * Docker Compose; refer to the official documentation for the `installation guide`_. * Pre-commit; refer to the official documentation for the `pre-commit`_. -* dxh_py; refer to the official GitHub repository of `dxh_py`_ +* django-boilerplate; refer to the official GitHub repository of `django-boilerplate`_ .. _`installation instructions`: https://docs.docker.com/install/#supported-platforms .. _`installation guide`: https://docs.docker.com/compose/install/ .. _`pre-commit`: https://pre-commit.com/#install -.. _`dxh_py`: https://github.com/dxh_py/dxh_py +.. _`django-boilerplate`: https://github.com/devxhub/django-boilerplate Before Getting Started ---------------------- @@ -32,7 +32,7 @@ Build the Stack This can take a while, especially the first time you run this particular command on your development system:: - $ docker-compose -f local.yml build + $ docker compose -f local.yml build Generally, if you want to emulate production environment use ``production.yml`` instead. And this is true for any other actions you might need to perform: whenever a switch is required, just do it! @@ -43,7 +43,6 @@ Before doing any git commit, `pre-commit`_ should be installed globally on your Failing to do so will result with a bunch of CI and Linter errors that can be avoided with pre-commit. - Run the Stack ------------- @@ -51,7 +50,7 @@ This brings up both Django and PostgreSQL. The first time it is run it might tak Open a terminal at the project root and run the following for local development:: - $ docker-compose -f local.yml up + $ docker compose -f local.yml up You can also set the environment variable ``COMPOSE_FILE`` pointing to ``local.yml`` like this:: @@ -59,30 +58,38 @@ You can also set the environment variable ``COMPOSE_FILE`` pointing to ``local.y And then run:: - $ docker-compose up + $ docker compose up To run in a detached (background) mode, just:: - $ docker-compose up -d + $ docker compose up -d + +These commands don't run the docs service. In order to run docs service you can run:: + + $ docker compose -f docs.yml up + +To run the docs with local services just use:: + $ docker compose -f local.yml -f docs.yml up + +The site should start and be accessible at http://localhost:3000 if you selected Webpack or Gulp as frontend pipeline and http://localhost:8000 otherwise. Execute Management Commands --------------------------- -As with any shell command that we wish to run in our container, this is done using the ``docker-compose -f local.yml run --rm`` command: :: +As with any shell command that we wish to run in our container, this is done using the ``docker compose -f local.yml run --rm`` command: :: - $ docker-compose -f local.yml run --rm django python manage.py migrate - $ docker-compose -f local.yml run --rm django python manage.py createsuperuser + $ docker compose -f local.yml run --rm django python manage.py migrate + $ docker compose -f local.yml run --rm django python manage.py createsuperuser Here, ``django`` is the target service we are executing the commands against. - +Also, please note that the ``docker exec`` does not work for running management commands. (Optionally) Designate your Docker Development Server IP -------------------------------------------------------- When ``DEBUG`` is set to ``True``, the host is validated against ``['localhost', '127.0.0.1', '[::1]']``. This is adequate when running a ``virtualenv``. For Docker, in the ``config.settings.local``, add your host development server IP to ``INTERNAL_IPS`` or ``ALLOWED_HOSTS`` if the variable exists. - .. _envs: Configuring the Environment @@ -108,8 +115,8 @@ The most important thing for us here now is ``env_file`` section enlisting ``./. .envs ├── .local - │   ├── .django - │   └── .postgres + │ ├── .django + │ └── .postgres └── .production ├── .django └── .postgres @@ -154,8 +161,8 @@ You have to modify the relevant requirement file: base, local or production by a To get this change picked up, you'll need to rebuild the image(s) and restart the running container: :: - docker-compose -f local.yml build - docker-compose -f local.yml up + docker compose -f local.yml build + docker compose -f local.yml up Debugging ~~~~~~~~~ @@ -169,7 +176,7 @@ If you are using the following within your code to debug: :: Then you may need to run the following for it to work as desired: :: - $ docker-compose -f local.yml run --rm --service-ports django + $ docker compose -f local.yml run --rm --service-ports django django-debug-toolbar @@ -186,7 +193,6 @@ The ``container_name`` from the yml file can be used to check on containers with $ docker logs _local_celeryworker $ docker top _local_celeryworker - Notice that the ``container_name`` is generated dynamically using your project slug as a prefix Mailhog @@ -229,97 +235,71 @@ By default, it's enabled both in local and production environments (``local.yml` Using Webpack or Gulp ~~~~~~~~~~~~~~~~~~~~~ -When using Webpack or Gulp as the ``frontend_pipeline`` option, you should access your application at the address of the ``node`` service in order to see your correct styles. This is http://localhost:3000 by default. When using any of the other ``frontend_pipeline`` options, you should use the address of the ``django`` service, http://localhost:8000. - -Developing locally with HTTPS ------------------------------ - -Increasingly it is becoming necessary to develop software in a secure environment in order that there are very few changes when deploying to production. Recently Facebook changed their policies for apps/sites that use Facebook login which requires the use of an HTTPS URL for the OAuth redirect URL. So if you want to use the ``users`` application with a OAuth provider such as Facebook, securing your communication to the local development environment will be necessary. - -In order to create a secure environment, we need to have a trusted SSL certificate installed in our Docker application. - -#. **Let's Encrypt** - - The official line from Let’s Encrypt is: +If you've opted for Gulp or Webpack as front-end pipeline, the project comes configured with `Sass`_ compilation and `live reloading`_. As you change your Sass/JS source files, the task runner will automatically rebuild the corresponding CSS and JS assets and reload them in your browser without refreshing the page. - [For local development section] ... The best option: Generate your own certificate, either self-signed or signed by a local root, and trust it in your operating system’s trust store. Then use that certificate in your local web server. See below for details. +The stack comes with a dedicated node service to build the static assets, watch for changes and proxy requests to the Django app with live reloading scripts injected in the response. For everything to work smoothly, you need to access the application at the port served by the node service, which is http://localhost:3000 by default. - See `letsencrypt.org - certificates-for-localhost`_ +.. _Sass: https://sass-lang.com/ +.. _live reloading: https://browsersync.io - .. _`letsencrypt.org - certificates-for-localhost`: https://letsencrypt.org/docs/certificates-for-localhost/ +(Optionally) Developing locally with HTTPS +------------------------------------------ -#. **mkcert: Valid Https Certificates For Localhost** - - `mkcert`_ is a simple by design tool that hides all the arcane knowledge required to generate valid TLS certificates. It works for any hostname or IP, including localhost. It supports macOS, Linux, and Windows, and Firefox, Chrome and Java. It even works on mobile devices with a couple manual steps. - - See https://blog.filippo.io/mkcert-valid-https-certificates-for-localhost/ - - .. _`mkcert`: https://github.com/FiloSottile/mkcert/blob/master/README.md#supported-root-stores - -After installing a trusted TLS certificate, configure your docker installation. We are going to configure an ``nginx`` reverse-proxy server. This makes sure that it does not interfere with our ``traefik`` configuration that is reserved for production environments. - -These are the places that you should configure to secure your local environment. - -certs +Nginx ~~~~~ -Take the certificates that you generated and place them in a folder called ``certs`` in the project's root folder. Assuming that you registered your local hostname as ``my-dev-env.local``, the certificates you will put in the folder should have the names ``my-dev-env.local.crt`` and ``my-dev-env.local.key``. +If you want to add some sort of social authentication with a OAuth provider such as Facebook, securing your communication to the local development environment will be necessary. These providers usually require that you use an HTTPS URL for the OAuth redirect URL for the Facebook login to work appropriately. -local.yml -~~~~~~~~~ +Here is a link to an article on `how to add HTTPS using Nginx`_ to your local docker installation. This also includes how to serve files from the ``media`` location, in the event that you are want to serve user-uploaded content. -#. Add the ``nginx-proxy`` service. :: +.. _`how to add HTTPS using Nginx`: https://afroshok.com/dxh_py-https - ... - - nginx-proxy: - image: jwilder/nginx-proxy:alpine - container_name: nginx-proxy - ports: - - "80:80" - - "443:443" - volumes: - - /var/run/docker.sock:/tmp/docker.sock:ro - - ./certs:/etc/nginx/certs - restart: always - depends_on: - - django - - ... +Webpack +~~~~~~~ -#. Link the ``nginx-proxy`` to ``django`` through environment variables. +If you are using Webpack, first install ``mkcert``_. It is a simple by design tool that hides all the arcane knowledge required to generate valid TLS certificates. It works for any hostname or IP, including localhost. It supports macOS, Linux, and Windows, and Firefox, Chrome and Java. It even works on mobile devices with a couple manual steps. See https://blog.filippo.io/mkcert-valid-https-certificates-for-localhost/ - ``django`` already has an ``.env`` file connected to it. Add the following variables. You should do this especially if you are working with a team and you want to keep your local environment details to yourself. +.. _`mkcert`: https://github.com/FiloSottile/mkcert/blob/master/README.md#supported-root-stores - :: +These are the places that you should configure to secure your local environment. Take the certificates that you generated and place them in a folder called ``certs`` in the project's root folder. Configure an ``nginx`` reverse-proxy server as a ``service`` in the ``local.yml``. This makes sure that it does not interfere with our ``traefik`` configuration that is reserved for production environments. - # HTTPS - # ------------------------------------------------------------------------------ - VIRTUAL_HOST=my-dev-env.local - VIRTUAL_PORT=8000 +Assuming that you registered your local hostname as ``my-dev-env.local``, the certificates you will put in the folder should have the names ``my-dev-env.local.crt`` and ``my-dev-env.local.key``. - The services run behind the reverse proxy. +1. Add the ``nginx-proxy`` service to the ``local.yml``. :: -config/settings/local.py -~~~~~~~~~~~~~~~~~~~~~~~~ + nginx-proxy: + image: jwilder/nginx-proxy:alpine + container_name: nginx-proxy + ports: + - "80:80" + - "443:443" + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ./certs:/etc/nginx/certs + restart: always + depends_on: + - node + environment: + - VIRTUAL_HOST=my-dev-env.local + - VIRTUAL_PORT=3000 -You should allow the new hostname. :: +2. Add the local secure domain to the ``config/settings/local.py``. You should allow the new hostname :: ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1", "my-dev-env.local"] -Rebuild your ``docker`` application. :: +3. Add the following configuration to the ``devServer`` section of ``webpack/dev.config.js`` :: - $ docker-compose -f local.yml up -d --build + client: { + webSocketURL: 'auto://0.0.0.0:0/ws', // note the `:0` after `0.0.0.0` + }, -Go to your browser and type in your URL bar ``https://my-dev-env.local`` -See `https with nginx`_ for more information on this configuration. +Rebuild your ``docker`` application. :: - .. _`https with nginx`: https://codewithhugo.com/docker-compose-local-https/ + $ docker compose -f local.yml up -d --build -.gitignore -~~~~~~~~~~ +Go to your browser and type in your URL bar ``https://my-dev-env.local``. -Add ``certs/*`` to the ``.gitignore`` file. This allows the folder to be included in the repo but its contents to be ignored. +For more on this configuration, see `https with nginx`_. -*This configuration is for local development environments only. Do not use this for production since you might expose your local* ``rootCA-key.pem``. +.. _`https with nginx`: https://codewithhugo.com/docker-compose-local-https/ \ No newline at end of file diff --git a/docs/developing-locally.rst b/docs/developing-locally.rst index 9057a70..6e7d9af 100644 --- a/docs/developing-locally.rst +++ b/docs/developing-locally.rst @@ -9,7 +9,7 @@ Setting Up Development Environment Make sure to have the following on your host: -* Python 3.11 +* Python 3.12 * PostgreSQL_. * Redis_, if using Celery * dxh_py_ @@ -18,7 +18,7 @@ First things first. #. Create a virtualenv: :: - $ python3.11 -m venv + $ python3.12 -m venv #. Activate the virtualenv you have just created: :: @@ -80,13 +80,15 @@ First things first. $ python manage.py runserver 0.0.0.0:8000 -or if you're running asynchronously: :: + or if you're running asynchronously: :: $ uvicorn config.asgi:application --host 0.0.0.0 --reload --reload-include '*.html' + If you've opted for Webpack or Gulp as frontend pipeline, please see the :ref:`dedicated section ` below. + .. _PostgreSQL: https://www.postgresql.org/download/ .. _Redis: https://redis.io/download -.. _dxh_py: https://github.com/dxh_py/dxh_py +.. _django-boilerplate: https://github.com/ devxhub/django-boilerplate .. _createdb: https://www.postgresql.org/docs/current/static/app-createdb.html .. _initial PostgreSQL set up: https://web.archive.org/web/20190303010033/http://suite.opengeo.org/docs/latest/dataadmin/pgGettingStarted/firstconnect.html .. _postgres documentation: https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html @@ -94,6 +96,61 @@ or if you're running asynchronously: :: .. _direnv: https://direnv.net/ +Creating Your First Django App +------------------------------- + +After setting up your environment, you're ready to add your first app. This project uses the setup from "Two Scoops of Django" with a two-tier layout: + +- **Top Level Repository Root** has config files, documentation, `manage.py`, and more. +- **Second Level Django Project Root** is where your Django apps live. +- **Second Level Configuration Root** holds settings and URL configurations. + +The project layout looks something like this: :: + + / + ├── config/ + │ ├── settings/ + │ │ ├── __init__.py + │ │ ├── base.py + │ │ ├── local.py + │ │ └── production.py + │ ├── urls.py + │ └── wsgi.py + ├── / + │ ├── / + │ │ ├── migrations/ + │ │ ├── admin.py + │ │ ├── apps.py + │ │ ├── models.py + │ │ ├── tests.py + │ │ └── views.py + │ ├── __init__.py + │ └── ... + ├── requirements/ + │ ├── base.txt + │ ├── local.txt + │ └── production.txt + ├── manage.py + ├── README.md + └── ... + + +Following this structured approach, here's how to add a new app: + +#. **Create the app** using Django's ``startapp`` command, replacing ```` with your desired app name: :: + + $ python manage.py startapp + +#. **Move the app** to the Django Project Root, maintaining the project's two-tier structure: :: + + $ mv / + +#. **Edit the app's apps.py** change ``name = ''`` to ``name = '.'``. + +#. **Register the new app** by adding it to the ``LOCAL_APPS`` list in ``config/settings/base.py``, integrating it as an official component of your project. + + + Setup Email Backend ------------------- @@ -108,9 +165,7 @@ For instance, one of the packages we depend upon, ``django-allauth`` sends verif #. `Download the latest MailHog release`_ for your OS. -#. Rename the build to ``MailHog``. - -#. Copy the file to the project root. +#. Copy the binary file to the project root. #. Make it executable: :: @@ -169,10 +224,12 @@ You can also use Django admin to queue up tasks, thanks to the `django-celerybea .. _django-celerybeat: https://django-celery-beat.readthedocs.io/en/latest/ -Sass Compilation & Live Reloading ---------------------------------- +.. _bare-metal-webpack-gulp: + +Using Webpack or Gulp +--------------------- -If you've opted for Gulp or Webpack as front-end pipeline, the project comes configured with `Sass`_ compilation and `live reloading`_. As you change you Sass/JS source files, the task runner will automatically rebuild the corresponding CSS and JS assets and reload them in your browser without refreshing the page. +If you've opted for Gulp or Webpack as front-end pipeline, the project comes configured with `Sass`_ compilation and `live reloading`_. As you change your Sass/JS source files, the task runner will automatically rebuild the corresponding CSS and JS assets and reload them in your browser without refreshing the page. #. Make sure that `Node.js`_ v18 is installed on your machine. #. In the project root, install the JS dependencies with:: @@ -183,9 +240,12 @@ If you've opted for Gulp or Webpack as front-end pipeline, the project comes con $ npm run dev - The app will now run with live reloading enabled, applying front-end changes dynamically. + This will start 2 processes in parallel: the static assets build loop on one side, and the Django server on the other. + +#. Access your application at the address of the ``node`` service in order to see your correct styles. This is http://localhost:3000 by default. + + .. note:: Do NOT access the application using the Django port (8000 by default), as it will result in broken styles and 404s when accessing static assets. -.. note:: The task will start 2 processes in parallel: the static assets build loop on one side, and the Django server on the other. You do NOT need to run Django as your would normally with ``manage.py runserver``. .. _Node.js: http://nodejs.org/download/ .. _Sass: https://sass-lang.com/ diff --git a/docs/docker-postgres-backups.rst b/docs/docker-postgres-backups.rst index 875d737..85689cb 100644 --- a/docs/docker-postgres-backups.rst +++ b/docs/docker-postgres-backups.rst @@ -8,7 +8,7 @@ Prerequisites ------------- #. the project was generated with ``use_docker`` set to ``y``; -#. the stack is up and running: ``docker-compose -f local.yml up -d postgres``. +#. the stack is up and running: ``docker compose -f local.yml up -d postgres``. Creating a Backup @@ -16,7 +16,7 @@ Creating a Backup To create a backup, run:: - $ docker-compose -f local.yml exec postgres backup + $ docker compose -f local.yml exec postgres backup Assuming your project's database is named ``my_project`` here is what you will see: :: @@ -31,7 +31,7 @@ Viewing the Existing Backups To list existing backups, :: - $ docker-compose -f local.yml exec postgres backups + $ docker compose -f local.yml exec postgres backups These are the sample contents of ``/backups``: :: @@ -55,9 +55,9 @@ With a single backup file copied to ``.`` that would be :: $ docker cp 9c5c3f055843:/backups/backup_2018_03_13T09_05_07.sql.gz . -You can also get the container ID using ``docker-compose -f local.yml ps -q postgres`` so if you want to automate your backups, you don't have to check the container ID manually every time. Here is the full command :: +You can also get the container ID using ``docker compose -f local.yml ps -q postgres`` so if you want to automate your backups, you don't have to check the container ID manually every time. Here is the full command :: - $ docker cp $(docker-compose -f local.yml ps -q postgres):/backups ./backups + $ docker cp $(docker compose -f local.yml ps -q postgres):/backups ./backups .. _`command`: https://docs.docker.com/engine/reference/commandline/cp/ @@ -66,7 +66,7 @@ Restoring from the Existing Backup To restore from one of the backups you have already got (take the ``backup_2018_03_13T09_05_07.sql.gz`` for example), :: - $ docker-compose -f local.yml exec postgres restore backup_2018_03_13T09_05_07.sql.gz + $ docker compose -f local.yml exec postgres restore backup_2018_03_13T09_05_07.sql.gz You will see something like :: @@ -92,7 +92,36 @@ You will see something like :: Backup to Amazon S3 ---------------------------------- + For uploading your backups to Amazon S3 you can use the aws cli container. There is an upload command for uploading the postgres /backups directory recursively and there is a download command for downloading a specific backup. The default S3 environment variables are used. :: - $ docker-compose -f production.yml run --rm awscli upload - $ docker-compose -f production.yml run --rm awscli download backup_2018_03_13T09_05_07.sql.gz + $ docker compose -f production.yml run --rm awscli upload + $ docker compose -f production.yml run --rm awscli download backup_2018_03_13T09_05_07.sql.gz + +Remove Backup +---------------------------------- + +To remove backup you can use the ``rmbackup`` command. This will remove the backup from the ``/backups`` directory. :: + + $ docker compose -f local.yml exec postgres rmbackup backup_2018_03_13T09_05_07.sql.gz + + +Upgrading PostgreSQL +---------------------------------- + +Upgrading PostgreSQL in your project requires a series of carefully executed steps. Start by halting all containers, excluding the postgres container. Following this, create a backup and proceed to remove the outdated data volume. :: + + $ docker compose -f local.yml down + $ docker compose -f local.yml up -d postgres + $ docker compose -f local.yml run --rm postgres backup + $ docker compose -f local.yml down + $ docker volume rm my_project_postgres_data + +.. note:: Neglecting to remove the old data volume may lead to issues, such as the new postgres container failing to start with errors like ``FATAL: database files are incompatible with server``, and ``could not translate host name "postgres" to address: Name or service not known``. + +To complete the upgrade, update the PostgreSQL version in the corresponding Dockerfile (e.g. ``compose/production/postgres/Dockerfile``) and build a new version of PostgreSQL. :: + + $ docker compose -f local.yml build postgres + $ docker compose -f local.yml up -d postgres + $ docker compose -f local.yml run --rm postgres restore backup_2018_03_13T09_05_07.sql.gz + $ docker compose -f local.yml up -d \ No newline at end of file diff --git a/docs/document.rst b/docs/document.rst index 974c66c..f93f2b6 100644 --- a/docs/document.rst +++ b/docs/document.rst @@ -11,7 +11,7 @@ After you have set up to `develop locally`_, run the following command from the If you set up your project to `develop locally with docker`_, run the following command: :: - $ docker-compose -f local.yml up docs + $ docker compose -f docs.yml up Navigate to port 9000 on your host to see the documentation. This will be opened automatically at `localhost`_ for local, non-docker development. diff --git a/docs/faq.rst b/docs/faq.rst index 7c1bb5f..965ff9d 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -3,7 +3,7 @@ FAQ .. index:: FAQ, 12-Factor App -Why is there a django.contrib.sites directory in dxh_py Django? +Why is there a django.contrib.sites directory in Django Boilarplate? --------------------------------------------------------------------- It is there to add a migration so you don't have to manually change the ``sites.Site`` record from ``example.com`` to whatever your domain is. Instead, your ``{{dxh_py.domain_name}}`` and ``{{dxh_py.project_name}}`` value is placed by **dxh_py** in the domain and name fields respectively. @@ -22,6 +22,6 @@ TODO Why doesn't this follow the layout from Two Scoops of Django? ------------------------------------------------------------- -You may notice that some elements of this project do not exactly match what we describe in chapter 3 of `Two Scoops of Django 1.11`_. The reason for that is this project, amongst other things, serves as a test bed for trying out new ideas and concepts. Sometimes they work, sometimes they don't, but the end result is that it won't necessarily match precisely what is described in the book I co-authored. +You may notice that some elements of this project do not exactly match what we describe in chapter 3 of `Two Scoops of Django 3.x`_. The reason for that is this project, amongst other things, serves as a test bed for trying out new ideas and concepts. Sometimes they work, sometimes they don't, but the end result is that it won't necessarily match precisely what is described in the book I co-authored. -.. _Two Scoops of Django 1.11: https://www.feldroy.com/collections/django/products/two-scoops-of-django-1-11 +.. _Two Scoops of Django 3.x: https://www.feldroy.com/two-scoops-press#two-scoops-of-django \ No newline at end of file diff --git a/docs/generate-project-block.rst b/docs/generate-project-block.rst index 034fa04..321c640 100644 --- a/docs/generate-project-block.rst +++ b/docs/generate-project-block.rst @@ -1,6 +1,6 @@ -Generate a new dxh_py-django project: :: +Generate a new django-boilerplate project: :: - $ dxh_py gh:dxh_py/dxh_py-django + $ dxh_py https://github.com/devxhub/django-boilerplate.git For more information refer to -:ref:`Project Generation Options `. +:ref:`Project Generation Options `. \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index f7fd00f..facb16e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,11 +1,11 @@ -.. dxh_py-django documentation master file. +.. django-boilarplate documentation master file. -Welcome to dxh_py Django's documentation! +Welcome to Django Boilarplate's documentation! =============================================== -Powered by dxh_py_, dxh_py Django is a project template for jumpstarting production-ready Django projects. The template offers a number of generation options, we invite you to check the :ref:`dedicated page ` to learn more about each of them. +Powered by DevXhuB_, Django Boilarplate is a project template for jumpstarting production-ready Django projects. The template offers a number of generation options, we invite you to check the :ref:`dedicated page ` to learn more about each of them. -.. _dxh_py: https://github.com/dxh_py/dxh_py +.. _django-boilarplate: https://github.com/devxhub/django-boilerplate Contents -------- @@ -35,4 +35,4 @@ Indices and tables * :ref:`genindex` * :ref:`search` -.. At some point it would be good to have a module index of the high level things we are doing. Then we can * :ref:`modindex` back in. +.. At some point it would be good to have a module index of the high level things we are doing. Then we can * :ref:`modindex` back in. \ No newline at end of file diff --git a/docs/linters.rst b/docs/linters.rst index a4f60cc..2b0d08d 100644 --- a/docs/linters.rst +++ b/docs/linters.rst @@ -4,40 +4,30 @@ Linters .. index:: linters -flake8 +ruff ------ -To run flake8: :: +Ruff is a Python linter and code formatter, written in Rust. +It is a aggregation of flake8, pylint, pyupgrade and many more. - $ flake8 +Ruff comes with a linter (``ruff check``) and a formatter (``ruff format``). +The linter is a wrapper around flake8, pylint, and other linters, +and the formatter is a wrapper around black, isort, and other formatters. -The config for flake8 is located in setup.cfg. It specifies: +To run ruff without modifying your files: :: -* Set max line length to 120 chars -* Exclude ``.tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules`` + $ ruff format --diff . + $ ruff check . -pylint ------- - -To run pylint: :: - - $ pylint - -The config for pylint is located in .pylintrc. It specifies: - -* Use the pylint_django plugin. If using Celery, also use pylint_celery. -* Set max line length to 120 chars -* Disable linting messages for missing docstring and invalid name -* max-parents=13 - -pycodestyle ------------ - -This is included in flake8's checks, but you can also run it separately to see a more detailed report: :: - - $ pycodestyle +Ruff is capable of fixing most of the problems it encounters. +Be sure you commit first before running `ruff` so you can restore to a savepoint (and amend afterwards to prevent a double commit. : :: -The config for pycodestyle is located in setup.cfg. It specifies: + $ ruff format . + $ ruff check --fix . + # be careful with the --unsafe-fixes option, it can break your code + $ ruff check --fix --unsafe-fixes . -* Set max line length to 120 chars -* Exclude ``.tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules`` +The config for ruff is located in pyproject.toml. +On of the most important option is `tool.ruff.lint.select`. +`select` determines which linters are run. In example, `DJ `_ refers to flake8-django. +For a full list of available linters, see `https://docs.astral.sh/ruff/rules/ `_ \ No newline at end of file diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index 4d8e6b6..ceb2f3e 100644 --- a/docs/project-generation-options.rst +++ b/docs/project-generation-options.rst @@ -3,9 +3,9 @@ Project Generation Options ========================== -This page describes all the template options that will be prompted by the `dxh_py CLI`_ prior to generating your project. +This page describes all the template options that will be prompted by the `django-boilerplate CLI`_ prior to generating your project. -.. _dxh_py CLI: https://github.com/dxh_py/dxh_py +.. _django-boilerplate CLI: https://github.com/devxhub/django-boilerplate project_name: Your project's human-readable name, capitals and spaces allowed. @@ -53,7 +53,6 @@ timezone: windows: Indicates whether the project should be configured for development on Windows. - editor: Select an editor to use. The choices are: @@ -63,7 +62,7 @@ editor: use_docker: - Indicates whether the project should be configured to use Docker_ and `Docker Compose`_. + Indicates whether the project should be configured to use Docker_, `Docker Compose`_ and `devcontainer`_. database_version: Select the version of the database you want to use for your project. @@ -75,16 +74,15 @@ database_version: *Currently, following PostgreSQL versions are supported:* - 1. 14 - 2. 13 - 3. 12 - 4. 11 - 5. 10 + 1. 16 + 2. 15 + 3. 14 + 4. 13 + 5. 12 *Currently, following MySQL versions are supported:* 1. 8.0 - cloud_provider: Select a cloud provider for static & media files. The choices are: @@ -104,7 +102,7 @@ mail_service: 4. Mandrill_ 5. Postmark_ 6. SendGrid_ - 7. SendinBlue_ + 7. `Brevo (formerly SendinBlue)`_ 8. SparkPost_ 9. `Other SMTP`_ @@ -150,6 +148,7 @@ ci_tool: 2. `Travis CI`_ 3. `Gitlab CI`_ 4. `Github Actions`_ + 5. `Drone CI`_ keep_local_envs_in_vcs: Indicates whether the project's ``.envs/.local/`` should be kept in VCS @@ -159,7 +158,7 @@ keep_local_envs_in_vcs: debug: Indicates whether the project should be configured for debugging. - This option is relevant for dxh_py Django developers only. + This option is relevant for Django Boilarplate developers only. .. _MIT: https://opensource.org/licenses/MIT @@ -172,6 +171,7 @@ debug: .. _Docker: https://github.com/docker/docker .. _Docker Compose: https://docs.docker.com/compose/ +.. _devcontainer: https://containers.dev/ .. _PostgreSQL: https://www.postgresql.org/docs/ @@ -188,7 +188,7 @@ debug: .. _Mandrill: http://mandrill.com .. _Postmark: https://postmarkapp.com .. _SendGrid: https://sendgrid.com -.. _SendinBlue: https://www.sendinblue.com +.. _Brevo (formerly SendinBlue): https://www.brevo.com .. _SparkPost: https://www.sparkpost.com .. _Other SMTP: https://anymail.readthedocs.io/en/stable/ @@ -212,4 +212,6 @@ debug: .. _GitLab CI: https://docs.gitlab.com/ee/ci/ -.. _Github Actions: https://docs.github.com/en/actions +.. _Drone CI: https://docs.drone.io/pipeline/overview/ + +.. _Github Actions: https://docs.github.com/en/actions \ No newline at end of file diff --git a/docs/requirements.txt b/docs/requirements.txt index d3dd61d..1980465 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,3 +1,3 @@ -sphinx==6.2.1 -sphinx-rtd-theme==1.2.0 -myst-parser==1.0.0 +sphinx==7.4.7 +sphinx-rtd-theme==2.0.0 +myst-parser==4.0.0 \ No newline at end of file diff --git a/docs/settings.rst b/docs/settings.rst index 6dacb74..fbea398 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -69,8 +69,8 @@ SENDGRID_API_KEY SENDGRID_API_KEY n/a SENDGRID_GENERATE_MESSAGE_ID True n/a raises error SENDGRID_MERGE_FIELD_FORMAT None n/a raises error SENDGRID_API_URL n/a n/a "https://api.sendgrid.com/v3/" -SENDINBLUE_API_KEY SENDINBLUE_API_KEY n/a raises error -SENDINBLUE_API_URL n/a n/a "https://api.sendinblue.com/v3/" +BREVO_API_KEY BREVO_API_KEY n/a raises error +BREVO_API_URL n/a n/a "https://api.brevo.com/v3/" SPARKPOST_API_KEY SPARKPOST_API_KEY n/a raises error SPARKPOST_API_URL n/a n/a "https://api.sparkpost.com/api/v1" ======================================= =========================== ============================================== ====================================================================== @@ -81,3 +81,6 @@ Other Environment Settings DJANGO_ACCOUNT_ALLOW_REGISTRATION (=True) Allow enable or disable user registration through `django-allauth` without disabling other characteristics like authentication and account management. (Django Setting: ACCOUNT_ALLOW_REGISTRATION) + +DJANGO_ADMIN_FORCE_ALLAUTH (=False) + Force the `admin` sign in process to go through the `django-allauth` workflow. \ No newline at end of file diff --git a/docs/testing.rst b/docs/testing.rst index bea45c6..9fb18cc 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -19,7 +19,7 @@ You will get a readout of the `users` app that has already been set up with test If you set up your project to `develop locally with docker`_, run the following command: :: - $ docker-compose -f local.yml run --rm django pytest + $ docker compose -f local.yml run --rm django pytest Targeting particular apps for testing in ``docker`` follows a similar pattern as previously shown above. @@ -36,14 +36,14 @@ Once the tests are complete, in order to see the code coverage, run the followin If you're running the project locally with Docker, use these commands instead: :: - $ docker-compose -f local.yml run --rm django coverage run -m pytest - $ docker-compose -f local.yml run --rm django coverage report + $ docker compose -f local.yml run --rm django coverage run -m pytest + $ docker compose -f local.yml run --rm django coverage report .. note:: At the root of the project folder, you will find the `pytest.ini` file. You can use this to customize_ the ``pytest`` to your liking. - There is also the `.coveragerc`. This is the configuration file for the ``coverage`` tool. You can find out more about `configuring`_ ``coverage``. + The configuration for ``coverage`` can be found in ``pyproject.toml``. You can find out more about `configuring`_ ``coverage``. .. seealso:: @@ -58,4 +58,4 @@ If you're running the project locally with Docker, use these commands instead: : .. _develop locally with docker: ./developing-locally-docker.html .. _customize: https://docs.pytest.org/en/latest/customize.html .. _unittest: https://docs.python.org/3/library/unittest.html#module-unittest -.. _configuring: https://coverage.readthedocs.io/en/latest/config.html +.. _configuring: https://coverage.readthedocs.io/en/latest/config.html \ No newline at end of file diff --git a/docs/troubleshooting.rst b/docs/troubleshooting.rst index ab2ca67..a45b45e 100644 --- a/docs/troubleshooting.rst +++ b/docs/troubleshooting.rst @@ -57,5 +57,5 @@ Others #. New apps not getting created in project root: This is the expected behavior, because dxh_py-django does not change the way that django startapp works, you'll have to fix this manually (see `#1725`_) -.. _#528: https://github.com/dxh_py/dxh_py-django/issues/528#issuecomment-212650373 -.. _#1725: https://github.com/dxh_py/dxh_py-django/issues/1725#issuecomment-407493176 +.. _#528: https://github.com/devxhub/django-boilerplateissues/528#issuecomment-212650373 +.. _#1725: https://github.com/devxhub/django-boilerplateissues/1725#issuecomment-407493176 diff --git a/docs/websocket.rst b/docs/websocket.rst index 9d2e326..370a33d 100644 --- a/docs/websocket.rst +++ b/docs/websocket.rst @@ -22,4 +22,4 @@ JavaScript example: :: If you don't use Traefik, you might have to configure your reverse proxy accordingly (example with Nginx_). -.. _Nginx: https://www.nginx.com/blog/websocket-nginx/ +.. _Nginx: https://www.nginx.com/blog/websocket-nginx/ \ No newline at end of file diff --git a/dxh_py.json b/dxh_py.json index 2b1a754..07f930b 100644 --- a/dxh_py.json +++ b/dxh_py.json @@ -1,5 +1,5 @@ { - "project_name": "My Project", + "project_name": "My Awesome Project", "project_slug": "{{ dxh_py.project_name.lower()|replace(' ', '_')|replace('-', '_')|replace('.', '_')|trim() }}", "description": "Behold My Awesome Project!", "author_name": "DEVxHUB", @@ -20,11 +20,11 @@ "use_docker": "n", "database_engine": ["postgresql", "mysql"], "database_version": [ + "postgresql@16", + "postgresql@15", "postgresql@14", "postgresql@13", "postgresql@12", - "postgresql@11", - "postgresql@10", "mysql@8.0.30", "mysql@8.0", "mysql@5.7" @@ -38,7 +38,7 @@ "Mandrill", "Postmark", "Sendgrid", - "SendinBlue", + "Brevo", "SparkPost", "Other SMTP" ], @@ -53,7 +53,7 @@ "use_sentry": "n", "use_whitenoise": "n", "use_heroku": "n", - "ci_tool": ["None", "Travis", "Gitlab", "Github"], + "ci_tool": ["None", "Travis", "Gitlab", "Github", "Drone"], "keep_local_envs_in_vcs": "y", "debug": "n" } diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index b162b8a..3bbb307 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -8,6 +8,7 @@ TODO: restrict dxh_py Django project initialization to Python 3.x environments only """ + from __future__ import print_function import json @@ -74,6 +75,7 @@ def remove_pycharm_files(): def remove_docker_files(): + shutil.rmtree(".devcontainer") shutil.rmtree("compose") file_names = ["local.yml", "production.yml", ".dockerignore"] @@ -85,11 +87,6 @@ def remove_docker_files(): os.remove(os.path.join(".idea", "runConfigurations", file_name)) -def remove_utility_files(): - shutil.rmtree("utility") - - - def remove_postgres_env_files(): local_postgres_envs_path = os.path.join(".envs", ".local", ".postgres") production_postgres_envs_path = os.path.join(".envs", ".production", ".postgres") @@ -213,6 +210,7 @@ def handle_js_runner(choice, use_docker, use_async): "browser-sync", "cssnano", "gulp", + "gulp-concat", "gulp-imagemin", "gulp-plumber", "gulp-postcss", @@ -221,7 +219,8 @@ def handle_js_runner(choice, use_docker, use_async): "gulp-uglify-es", ] if not use_docker: - dev_django_cmd = "uvicorn config.asgi:application --reload" if use_async else "python manage.py runserver" + dev_django_cmd = ("uvicorn config.asgi:application --reload" if use_async else "python manage.py runserver_plus" + ) scripts.update( { "dev": "concurrently npm:dev:*", @@ -235,6 +234,24 @@ def handle_js_runner(choice, use_docker, use_async): remove_gulp_files() +def remove_prettier_pre_commit(): + with open(".pre-commit-config.yaml", "r") as fd: + content = fd.readlines() + + removing = False + new_lines = [] + for line in content: + if removing and "- repo:" in line: + removing = False + if "mirrors-prettier" in line: + removing = True + if not removing: + new_lines.append(line) + + with open(".pre-commit-config.yaml", "w") as fd: + fd.writelines(new_lines) + + def remove_celery_files(): file_names = [ os.path.join("config", "celery_app.py"), @@ -266,6 +283,10 @@ def remove_dotgithub_folder(): shutil.rmtree(".github") +def remove_dotdrone_file(): + os.remove(".drone.yml") + + def generate_random_string(length, using_digits=False, using_ascii_letters=False, using_punctuation=False): """ Example: @@ -333,6 +354,7 @@ def set_django_admin_url(file_path): ) return django_admin_url + def generate_random_user(): return generate_random_string(length=32, using_ascii_letters=True) @@ -550,7 +572,6 @@ def main(): elif "{{ dxh_py.database_engine }}".lower() == "mysql": remove_postgres_docker_folder() - remove_utility_files() else: remove_docker_files() @@ -587,6 +608,7 @@ def main(): remove_webpack_files() remove_sass_files() remove_packagejson_file() + remove_prettier_pre_commit() if "{{ dxh_py.use_docker }}".lower() == "y": remove_node_dockerfile() else: @@ -617,6 +639,9 @@ def main(): if "{{ dxh_py.ci_tool }}" != "Github": remove_dotgithub_folder() + if "{{ dxh_py.ci_tool }}" != "Drone": + remove_dotdrone_file() + if "{{ dxh_py.use_drf }}".lower() == "n": remove_drf_starter_files() diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py index 8c19843..a7e8b50 100644 --- a/hooks/pre_gen_project.py +++ b/hooks/pre_gen_project.py @@ -7,6 +7,7 @@ TODO: restrict dxh_py Django project initialization to Python 3.x environments only """ + from __future__ import print_function import sys @@ -38,7 +39,7 @@ if python_major_version == 2: print( WARNING + "You're running dxh_py under Python 2, but the generated " - "project requires Python 3.11+. Do you want to proceed (y/n)? " + TERMINATOR + "project requires Python 3.12+. Do you want to proceed (y/n)? " + TERMINATOR ) yes_options, no_options = frozenset(["y"]), frozenset(["n"]) while True: @@ -65,4 +66,4 @@ if "{{ dxh_py.mail_service }}" == "Amazon SES" and "{{ dxh_py.cloud_provider }}" != "AWS": print("You should either use AWS or select a different " "Mail Service for sending emails.") - sys.exit(1) + sys.exit(1) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 61f20a1..de7dfd5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ norecursedirs = [ # ==== black ==== [tool.black] line-length = 119 -target-version = ['py311'] +target-version = ['py312'] # ==== isort ==== @@ -27,3 +27,24 @@ known_first_party = [ "scripts", "hooks", ] + + +# ==== djLint ==== +[tool.djlint] +blank_line_after_tag = "load,extends" +close_void_tags = true +format_css = true +format_js = true +# TODO: remove T002 when fixed https://github.com/Riverside-Healthcare/djLint/issues/687 +ignore = "H006,H030,H031,T002,T028" +ignore_blocks = "raw" +include = "H017,H035" +indent = 2 +max_line_length = 119 +profile = "jinja" + +[tool.djlint.css] +indent_size = 2 + +[tool.djlint.js] +indent_size = 2 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 1454e65..08ace4a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,27 +1,29 @@ -dxh_py==2.6.0 +dxh_py==0.0.4 sh==2.0.7; sys_platform != "win32" binaryornot==0.4.4 # Code quality # ------------------------------------------------------------------------------ +ruff==0.6.2 +djlint==1.34.1 black==24.4.2 isort==5.13.2 flake8==7.0.0 -django-upgrade==1.18.0 -pre-commit==3.7.1 +django-upgrade==1.20.0 +pre-commit==3.8.0 # Testing # ------------------------------------------------------------------------------ -tox==4.15.0 -pytest==8.2.2 +tox==4.18.0 +pytest==8.3.2 pytest-xdist==3.6.1 pytest-cookies==0.7.0 pytest-instafail==0.5.0 -pyyaml==6.0.1 +pyyaml==6.0.2 # Scripting # ------------------------------------------------------------------------------ -PyGithub==2.3.0 +PyGithub==2.4.0 gitpython==3.1.43 jinja2==3.1.4 -requests==2.32.3 +requests==2.32.3 \ No newline at end of file diff --git a/scripts/create_django_issue.py b/scripts/create_django_issue.py deleted file mode 100644 index cc858e8..0000000 --- a/scripts/create_django_issue.py +++ /dev/null @@ -1,298 +0,0 @@ -""" -Creates an issue that generates a table for dependency checking whether -all packages support the latest Django version. "Latest" does not include -patches, only comparing major and minor version numbers. - -This script handles when there are multiple Django versions that need -to keep up to date. -""" -from __future__ import annotations - -import os -import re -import sys -from collections.abc import Iterable -from pathlib import Path -from typing import TYPE_CHECKING, Any, NamedTuple - -import requests -from github import Github - -if TYPE_CHECKING: - from github.Issue import Issue - -CURRENT_FILE = Path(__file__) -ROOT = CURRENT_FILE.parents[1] -REQUIREMENTS_DIR = ROOT / "{{dxh_py.project_slug}}" / "requirements" -GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", None) -GITHUB_REPO = os.getenv("GITHUB_REPOSITORY", None) - - -class DjVersion(NamedTuple): - """ - Wrapper to parse, compare and render Django versions. - - Only keeps track on (major, minor) versions, excluding patches and pre-releases. - """ - - major: int - minor: int - - def __str__(self) -> str: - """To render as string.""" - return f"{self.major}.{self.minor}" - - @classmethod - def parse(cls, version_str: str) -> DjVersion: - """Parse interesting values from the version string.""" - major, minor, *_ = version_str.split(".") - return cls(major=int(major), minor=int(minor)) - - @classmethod - def parse_to_tuple(cls, version_str: str): - version = cls.parse(version_str=version_str) - return version.major, version.minor - - -def get_package_info(package: str) -> dict: - """Get package metadata using PyPI API.""" - # "django" converts to "Django" on redirect - r = requests.get(f"https://pypi.org/pypi/{package}/json", allow_redirects=True) - if not r.ok: - print(f"Couldn't find package: {package}") - sys.exit(1) - return r.json() - - -def get_django_versions() -> Iterable[DjVersion]: - """List all django versions.""" - django_package_info: dict[str, Any] = get_package_info("django") - releases = django_package_info["releases"].keys() - for release_str in releases: - if release_str.replace(".", "").isdigit(): - # Exclude pre-releases with non-numeric characters in version - yield DjVersion.parse(release_str) - - -def get_name_and_version(requirements_line: str) -> tuple[str, ...]: - """Get the name a version of a package from a line in the requirement file.""" - full_name, version = requirements_line.split(" ", 1)[0].split("==") - name_without_extras = full_name.split("[", 1)[0] - return name_without_extras, version - - -def get_all_latest_django_versions( - django_max_version: tuple[DjVersion] = None, -) -> tuple[DjVersion, list[DjVersion]]: - """ - Grabs all Django versions that are worthy of a GitHub issue. - Depends on Django versions having higher major version or minor version. - """ - _django_max_version = (99, 99) - if django_max_version: - _django_max_version = django_max_version - - print("Fetching all Django versions from PyPI") - base_txt = REQUIREMENTS_DIR / "base.txt" - with base_txt.open() as f: - for line in f.readlines(): - if "django==" in line.lower(): - break - else: - print(f"django not found in {base_txt}") # Huh...? - sys.exit(1) - - # Begin parsing and verification - _, current_version_str = get_name_and_version(line) - # Get a tuple of (major, minor) - ignoring patch version - current_minor_version = DjVersion.parse(current_version_str) - newer_versions: set[DjVersion] = set() - for django_version in get_django_versions(): - if current_minor_version < django_version <= _django_max_version: - newer_versions.add(django_version) - - return current_minor_version, sorted(newer_versions, reverse=True) - - -_TABLE_HEADER = """ - -## {file}.txt - -| Name | Version in Master | {dj_version} Compatible Version | OK | -| ---- | :---------------: | :-----------------------------: | :-: | -""" -VITAL_BUT_UNKNOWN = [ - "django-environ", # not updated often -] - - -class GitHubManager: - def __init__(self, base_dj_version: DjVersion, needed_dj_versions: list[DjVersion]): - self.github = Github(GITHUB_TOKEN) - self.repo = self.github.get_repo(GITHUB_REPO) - - self.base_dj_version = base_dj_version - self.needed_dj_versions = needed_dj_versions - # (major+minor) Version and description - self.existing_issues: dict[DjVersion, Issue] = {} - - # Load all requirements from our requirements files and preload their - # package information like a cache: - self.requirements_files = ["base", "local", "production"] - # Format: - # requirement file name: {package name: (master_version, package_info)} - self.requirements: dict[str, dict[str, tuple[str, dict]]] = {x: {} for x in self.requirements_files} - - def setup(self) -> None: - self.load_requirements() - self.load_existing_issues() - - def load_requirements(self): - print("Reading requirements") - for requirements_file in self.requirements_files: - with (REQUIREMENTS_DIR / f"{requirements_file}.txt").open() as f: - for line in f.readlines(): - if ( - "==" in line - and not line.startswith("{%") - and not line.startswith(" #") - and not line.startswith("#") - and not line.startswith(" ") - ): - name, version = get_name_and_version(line) - self.requirements[requirements_file][name] = ( - version, - get_package_info(name), - ) - - def load_existing_issues(self): - """Closes the issue if the base Django version is greater than needed""" - print("Load existing issues from GitHub") - qualifiers = { - "repo": GITHUB_REPO, - "author": "app/github-actions", - "state": "open", - "is": "issue", - "in": "title", - } - issues = list(self.github.search_issues("[Django Update]", "created", "desc", **qualifiers)) - print(f"Found {len(issues)} issues matching search") - for issue in issues: - matches = re.match(r"\[Update Django] Django (\d+.\d+)$", issue.title) - if not matches: - continue - issue_version = DjVersion.parse(matches.group(1)) - if self.base_dj_version > issue_version: - issue.edit(state="closed") - print(f"Closed issue {issue.title} (ID: [{issue.id}]({issue.url}))") - else: - self.existing_issues[issue_version] = issue - - def get_compatibility(self, package_name: str, package_info: dict, needed_dj_version: DjVersion): - """ - Verify compatibility via setup.py classifiers. If Django is not in the - classifiers, then default compatibility is n/a and OK is ✅. - - If it's a package that's vital but known to not be updated often, we give it - a ❓. If a package has ❓ or 🕒, then we allow manual update. Automatic updates - only include ❌ and ✅. - """ - # If issue previously existed, find package and skip any gtg, manually - # updated packages, or known releases that will happen but haven't yet - if issue := self.existing_issues.get(needed_dj_version): - if index := issue.body.find(package_name): - name, _current, prev_compat, ok = (s.strip() for s in issue.body[index:].split("|", 4)[:4]) - if ok in ("✅", "❓", "🕒"): - return prev_compat, ok - - if package_name in VITAL_BUT_UNKNOWN: - return "", "❓" - - # Check classifiers if it includes Django - supported_dj_versions: list[DjVersion] = [] - for classifier in package_info["info"]["classifiers"]: - # Usually in the form of "Framework :: Django :: 3.2" - tokens = classifier.split(" ") - if len(tokens) >= 5 and tokens[2].lower() == "django": - version = DjVersion.parse(tokens[4]) - if len(version) == 2: - supported_dj_versions.append(version) - - if supported_dj_versions: - if any(v >= needed_dj_version for v in supported_dj_versions): - return package_info["info"]["version"], "✅" - else: - return "", "❌" - - # Django classifier DNE; assume it isn't a Django lib - # Great exceptions include pylint-django, where we need to do this manually... - return "n/a", "✅" - - HOME_PAGE_URL_KEYS = [ - "home_page", - "project_url", - "docs_url", - "package_url", - "release_url", - "bugtrack_url", - ] - - def _get_md_home_page_url(self, package_info: dict): - urls = [package_info["info"].get(url_key) for url_key in self.HOME_PAGE_URL_KEYS] - try: - return f"[{{}}]({next(item for item in urls if item)})" - except StopIteration: - return "{}" - - def generate_markdown(self, needed_dj_version: DjVersion): - requirements = f"{needed_dj_version} requirements tables\n\n" - for _file in self.requirements_files: - requirements += _TABLE_HEADER.format_map({"file": _file, "dj_version": needed_dj_version}) - for package_name, (version, info) in self.requirements[_file].items(): - compat_version, icon = self.get_compatibility(package_name, info, needed_dj_version) - requirements += ( - f"| {self._get_md_home_page_url(info).format(package_name)} " - f"| {version.strip()} " - f"| {compat_version.strip()} " - f"| {icon} " - f"|\n" - ) - - return requirements - - def create_or_edit_issue(self, needed_dj_version: DjVersion, description: str): - if issue := self.existing_issues.get(needed_dj_version): - print(f"Editing issue #{issue.number} for Django {needed_dj_version}") - issue.edit(body=description) - else: - print(f"Creating new issue for Django {needed_dj_version}") - issue = self.repo.create_issue(f"[Update Django] Django {needed_dj_version}", description) - issue.add_to_labels(f"django{needed_dj_version}") - - def generate(self): - for version in self.needed_dj_versions: - print(f"Handling GitHub issue for Django {version}") - md_content = self.generate_markdown(version) - print(f"Generated markdown:\n\n{md_content}") - self.create_or_edit_issue(version, md_content) - - -def main(django_max_version=None) -> None: - # Check if there are any djs - current_dj, latest_djs = get_all_latest_django_versions(django_max_version=django_max_version) - if not latest_djs: - sys.exit(0) - manager = GitHubManager(current_dj, latest_djs) - manager.setup() - manager.generate() - - -if __name__ == "__main__": - if GITHUB_REPO is None: - raise RuntimeError("No github repo, please set the environment variable GITHUB_REPOSITORY") - max_version = None - last_arg = sys.argv[-1] - if CURRENT_FILE.name not in last_arg: - max_version = DjVersion.parse_to_tuple(version_str=last_arg) - - main(django_max_version=max_version) diff --git a/scripts/update_changelog.py b/scripts/update_changelog.py deleted file mode 100644 index 7d43a0b..0000000 --- a/scripts/update_changelog.py +++ /dev/null @@ -1,160 +0,0 @@ -import datetime as dt -import os -import re -from collections.abc import Iterable -from pathlib import Path - -import git -import github.PullRequest -import github.Repository -from github import Github -from jinja2 import Template - -CURRENT_FILE = Path(__file__) -ROOT = CURRENT_FILE.parents[1] -GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") -GITHUB_REPO = os.getenv("GITHUB_REPOSITORY") -GIT_BRANCH = os.getenv("GITHUB_REF_NAME") - - -def main() -> None: - """ - Script entry point. - """ - # Generate changelog for PRs merged yesterday - merged_date = dt.date.today() - dt.timedelta(days=1) - repo = Github(login_or_token=GITHUB_TOKEN).get_repo(GITHUB_REPO) - merged_pulls = list(iter_pulls(repo, merged_date)) - print(f"Merged pull requests: {merged_pulls}") - if not merged_pulls: - print("Nothing was merged, existing.") - return - - # Group pull requests by type of change - grouped_pulls = group_pulls_by_change_type(merged_pulls) - - # Generate portion of markdown - release_changes_summary = generate_md(grouped_pulls) - print(f"Summary of changes: {release_changes_summary}") - - # Update CHANGELOG.md file - release = f"{merged_date:%Y.%m.%d}" - changelog_path = ROOT / "CHANGELOG.md" - write_changelog(changelog_path, release, release_changes_summary) - print(f"Wrote {changelog_path}") - - # Update version - setup_py_path = ROOT / "setup.py" - update_version(setup_py_path, release) - print(f"Updated version in {setup_py_path}") - - # Commit changes, create tag and push - update_git_repo([changelog_path, setup_py_path], release) - - # Create GitHub release - github_release = repo.create_git_release( - tag=release, - name=release, - message=release_changes_summary, - ) - print(f"Created release on GitHub {github_release}") - - -def iter_pulls( - repo: github.Repository.Repository, - merged_date: dt.date, -) -> Iterable[github.PullRequest.PullRequest]: - """Fetch merged pull requests at the date we're interested in.""" - recent_pulls = repo.get_pulls( - state="closed", - sort="updated", - direction="desc", - ).get_page(0) - for pull in recent_pulls: - if pull.merged and pull.merged_at.date() == merged_date: - yield pull - - -def group_pulls_by_change_type( - pull_requests_list: list[github.PullRequest.PullRequest], -) -> dict[str, list[github.PullRequest.PullRequest]]: - """Group pull request by change type.""" - grouped_pulls = { - "Changed": [], - "Fixed": [], - "Documentation": [], - "Updated": [], - } - for pull in pull_requests_list: - label_names = {label.name for label in pull.labels} - if "project infrastructure" in label_names: - # Don't mention it in the changelog - continue - if "update" in label_names: - group_name = "Updated" - elif "bug" in label_names: - group_name = "Fixed" - elif "docs" in label_names: - group_name = "Documentation" - else: - group_name = "Changed" - grouped_pulls[group_name].append(pull) - return grouped_pulls - - -def generate_md(grouped_pulls: dict[str, list[github.PullRequest.PullRequest]]) -> str: - """Generate markdown file from Jinja template.""" - changelog_template = ROOT / ".github" / "changelog-template.md" - template = Template(changelog_template.read_text(), autoescape=True) - return template.render(grouped_pulls=grouped_pulls) - - -def write_changelog(file_path: Path, release: str, content: str) -> None: - """Write Release details to the changelog file.""" - content = f"## {release}\n{content}" - old_content = file_path.read_text() - updated_content = old_content.replace( - "", - f"\n\n{content}", - ) - file_path.write_text(updated_content) - - -def update_version(file_path: Path, release: str) -> None: - """Update template version in setup.py.""" - old_content = file_path.read_text() - updated_content = re.sub( - r'\nversion = "\d+\.\d+\.\d+"\n', - f'\nversion = "{release}"\n', - old_content, - ) - file_path.write_text(updated_content) - - -def update_git_repo(paths: list[Path], release: str) -> None: - """Commit, tag changes in git repo and push to origin.""" - repo = git.Repo(ROOT) - for path in paths: - repo.git.add(path) - message = f"Release {release}" - - user = repo.git.config("--get", "user.name") - email = repo.git.config("--get", "user.email") - - repo.git.commit( - m=message, - author=f"{user} <{email}>", - ) - repo.git.tag("-a", release, m=message) - server = f"https://{GITHUB_TOKEN}@github.com/{GITHUB_REPO}.git" - print(f"Pushing changes to {GIT_BRANCH} branch of {GITHUB_REPO}") - repo.git.push(server, GIT_BRANCH) - repo.git.push("--tags", server, GIT_BRANCH) - - -if __name__ == "__main__": - if GITHUB_REPO is None: - raise RuntimeError("No github repo, please set the environment variable GITHUB_REPOSITORY") - if GIT_BRANCH is None: - raise RuntimeError("No git branch set, please set the GITHUB_REF_NAME environment variable") - main() diff --git a/scripts/update_contributors.py b/scripts/update_contributors.py deleted file mode 100644 index 09a7082..0000000 --- a/scripts/update_contributors.py +++ /dev/null @@ -1,102 +0,0 @@ -import json -import os -from pathlib import Path - -from github import Github -from github.NamedUser import NamedUser -from jinja2 import Template - -CURRENT_FILE = Path(__file__) -ROOT = CURRENT_FILE.parents[1] -BOT_LOGINS = ["pyup-bot"] -GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", None) -GITHUB_REPO = os.getenv("GITHUB_REPOSITORY", None) - - -def main() -> None: - """ - Script entry point. - - 1. Fetch recent contributors from the Github API - 2. Add missing ones to the JSON file - 3. Generate Markdown from JSON file - """ - recent_authors = set(iter_recent_authors()) - - # Add missing users to the JSON file - contrib_file = ContributorsJSONFile() - for author in recent_authors: - print(f"Checking if {author.login} should be added") - if author.login not in contrib_file: - contrib_file.add_contributor(author) - print(f"Added {author.login} to contributors") - contrib_file.save() - - # Generate MD file from JSON file - write_md_file(contrib_file.content) - - -def iter_recent_authors(): - """ - Fetch users who opened recently merged pull requests. - - Use Github API to fetch recent authors rather than - git CLI to work with Github usernames. - """ - repo = Github(login_or_token=GITHUB_TOKEN, per_page=5).get_repo(GITHUB_REPO) - recent_pulls = repo.get_pulls(state="closed", sort="updated", direction="desc").get_page(0) - for pull in recent_pulls: - if pull.merged and pull.user.type == "User" and pull.user.login not in BOT_LOGINS: - yield pull.user - - -class ContributorsJSONFile: - """Helper to interact with the JSON file.""" - - file_path = ROOT / ".github" / "contributors.json" - content = None - - def __init__(self) -> None: - """Read initial content.""" - self.content = json.loads(self.file_path.read_text()) - - def __contains__(self, github_login: str): - """Provide a nice API to do: `username in file`.""" - return any( - # Github usernames are case insensitive - github_login.lower() == contrib["github_login"].lower() - for contrib in self.content - ) - - def add_contributor(self, user: NamedUser): - """Append the contributor data we care about at the end.""" - contributor_data = { - "name": user.name or user.login, - "github_login": user.login, - "twitter_username": user.twitter_username or "", - } - self.content.append(contributor_data) - - def save(self): - """Write the file to disk with indentation.""" - text_content = json.dumps(self.content, indent=2, ensure_ascii=False) - self.file_path.write_text(text_content) - - -def write_md_file(contributors): - """Generate markdown file from Jinja template.""" - contributors_template = ROOT / ".github" / "CONTRIBUTORS-template.md" - template = Template(contributors_template.read_text(), autoescape=True) - core_contributors = [c for c in contributors if c.get("is_core", False)] - other_contributors = (c for c in contributors if not c.get("is_core", False)) - other_contributors = sorted(other_contributors, key=lambda c: c["name"].lower()) - content = template.render(core_contributors=core_contributors, other_contributors=other_contributors) - - file_path = ROOT / "CONTRIBUTORS.md" - file_path.write_text(content) - - -if __name__ == "__main__": - if GITHUB_REPO is None: - raise RuntimeError("No github repo, please set the environment variable GITHUB_REPOSITORY") - main() diff --git a/setup.py b/setup.py index 62febaa..579307d 100644 --- a/setup.py +++ b/setup.py @@ -5,32 +5,32 @@ from distutils.core import setup # We use calendar versioning -version = "2023.04.28" +version = "2024.08.26" -with open("README.rst") as readme_file: +with open("README.md") as readme_file: long_description = readme_file.read() setup( - name="dxh_py-django", + name="django-boilerplate", version=version, description=("A dxh_py template for creating production-ready " "Django projects quickly."), long_description=long_description, author="DEVxHUB", author_email="tech@devxhub.com", - url="https://github.com/dxh_py/dxh_py-django", + url="https://github.com/devxhub/django-boilerplate", packages=[], license="MIT", zip_safe=False, classifiers=[ "Development Status :: 4 - Beta", "Environment :: Console", - "Framework :: Django :: 4.1", + "Framework :: Django :: 5.0", "Intended Audience :: Developers", "Natural Language :: English", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development", ], diff --git a/tests/test_bare.sh b/tests/test_bare.sh index e6b3860..f371451 100644 --- a/tests/test_bare.sh +++ b/tests/test_bare.sh @@ -1,5 +1,5 @@ #!/bin/sh -# this is a very simple script that tests the docker configuration for dxh_py-django +# this is a very simple script that tests the docker configuration for django boilarplate # it is meant to be run from the root directory of the repository, eg: # sh tests/test_bare.sh @@ -14,8 +14,11 @@ cd .cache/bare dxh_py ../../ --no-input --overwrite-if-exists use_docker=n "$@" cd my_awesome_project +chmod +x ./utility/install_os_dependencies.sh + # Install OS deps -sudo utility/install_os_dependencies.sh install +sudo bash ./utility/install_os_dependencies.sh install + # Install Python deps pip install -r requirements/local.txt @@ -34,4 +37,4 @@ then fi # Generate the HTML for the documentation -cd docs && make html +cd docs && make html \ No newline at end of file diff --git a/tests/test_cookiecutter_generation.py b/tests/test_django_boilarplate_generation.py similarity index 86% rename from tests/test_cookiecutter_generation.py rename to tests/test_django_boilarplate_generation.py index 5d47a38..f5c1238 100644 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_django_boilarplate_generation.py @@ -57,12 +57,12 @@ def context(): {"editor": "vscode"}, {"use_docker": "y"}, {"use_docker": "n"}, + {"database_engine": "postgresql", "database_version": "postgresql@16"}, + {"database_engine": "postgresql", "database_version": "postgresql@15"}, {"database_engine": "postgresql", "database_version": "postgresql@14"}, {"database_engine": "postgresql", "database_version": "postgresql@13"}, {"database_engine": "postgresql", "database_version": "postgresql@12"}, - {"database_engine": "postgresql", "database_version": "postgresql@11"}, - {"database_engine": "postgresql", "database_version": "postgresql@10"}, - {"database_engine": "mysql", "database_version": "mysql@8.0.29"}, + {"database_engine": "mysql", "database_version": "mysql@8.0.30"}, {"database_engine": "mysql", "database_version": "mysql@8.0"}, {"database_engine": "mysql", "database_version": "mysql@5.7"}, {"cloud_provider": "AWS", "use_whitenoise": "y"}, @@ -76,7 +76,7 @@ def context(): {"cloud_provider": "None", "use_whitenoise": "y", "mail_service": "Mandrill"}, {"cloud_provider": "None", "use_whitenoise": "y", "mail_service": "Postmark"}, {"cloud_provider": "None", "use_whitenoise": "y", "mail_service": "Sendgrid"}, - {"cloud_provider": "None", "use_whitenoise": "y", "mail_service": "SendinBlue"}, + {"cloud_provider": "None", "use_whitenoise": "y", "mail_service": "Brevo"}, {"cloud_provider": "None", "use_whitenoise": "y", "mail_service": "SparkPost"}, {"cloud_provider": "None", "use_whitenoise": "y", "mail_service": "Other SMTP"}, # Note: cloud_provider=None AND use_whitenoise=n is not supported @@ -86,7 +86,7 @@ def context(): {"cloud_provider": "AWS", "mail_service": "Mandrill"}, {"cloud_provider": "AWS", "mail_service": "Postmark"}, {"cloud_provider": "AWS", "mail_service": "Sendgrid"}, - {"cloud_provider": "AWS", "mail_service": "SendinBlue"}, + {"cloud_provider": "AWS", "mail_service": "Brevo"}, {"cloud_provider": "AWS", "mail_service": "SparkPost"}, {"cloud_provider": "AWS", "mail_service": "Other SMTP"}, {"cloud_provider": "GCP", "mail_service": "Mailgun"}, @@ -94,7 +94,7 @@ def context(): {"cloud_provider": "GCP", "mail_service": "Mandrill"}, {"cloud_provider": "GCP", "mail_service": "Postmark"}, {"cloud_provider": "GCP", "mail_service": "Sendgrid"}, - {"cloud_provider": "GCP", "mail_service": "SendinBlue"}, + {"cloud_provider": "GCP", "mail_service": "Brevo"}, {"cloud_provider": "GCP", "mail_service": "SparkPost"}, {"cloud_provider": "GCP", "mail_service": "Other SMTP"}, {"cloud_provider": "Azure", "mail_service": "Mailgun"}, @@ -102,7 +102,7 @@ def context(): {"cloud_provider": "Azure", "mail_service": "Mandrill"}, {"cloud_provider": "Azure", "mail_service": "Postmark"}, {"cloud_provider": "Azure", "mail_service": "Sendgrid"}, - {"cloud_provider": "Azure", "mail_service": "SendinBlue"}, + {"cloud_provider": "Azure", "mail_service": "Brevo"}, {"cloud_provider": "Azure", "mail_service": "SparkPost"}, {"cloud_provider": "Azure", "mail_service": "Other SMTP"}, # Note: cloud_providers GCP, Azure, and None @@ -131,6 +131,7 @@ def context(): {"ci_tool": "Travis"}, {"ci_tool": "Gitlab"}, {"ci_tool": "Github"}, + {"ci_tool": "Drone"}, {"keep_local_envs_in_vcs": "y"}, {"keep_local_envs_in_vcs": "n"}, {"debug": "y"}, @@ -183,28 +184,25 @@ def test_project_generation(cookies, context, context_override): @pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id) -def test_flake8_passes(cookies, context_override): - """Generated project should pass flake8.""" +def test_ruff_check_passes(cookies, context_override): + """Generated project should pass ruff check.""" result = cookies.bake(extra_context=context_override) try: - sh.flake8(_cwd=str(result.project_path)) + sh.ruff("check", ".", _cwd=str(result.project_path)) except sh.ErrorReturnCode as e: pytest.fail(e.stdout.decode()) @auto_fixable @pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id) -def test_black_passes(cookies, context_override): - """Check whether generated project passes black style.""" +def test_ruff_format_passes(cookies, context_override): + """Check whether generated project passes ruff format.""" result = cookies.bake(extra_context=context_override) try: - sh.black( - "--check", - "--diff", - "--exclude", - "migrations", + sh.ruff( + "format", ".", _cwd=str(result.project_path), ) @@ -237,7 +235,7 @@ def test_django_upgrade_passes(cookies, context_override): try: sh.django_upgrade( "--target-version", - "4.1", + "5.0", *python_files, _cwd=str(result.project_path), ) @@ -245,11 +243,43 @@ def test_django_upgrade_passes(cookies, context_override): pytest.fail(e.stdout.decode()) +@pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id) +def test_djlint_lint_passes(cookies, context_override): + """Check whether generated project passes djLint --lint.""" + result = cookies.bake(extra_context=context_override) + + autofixable_rules = "H014,T001" + # TODO: remove T002 when fixed https://github.com/Riverside-Healthcare/djLint/issues/687 + ignored_rules = "H006,H030,H031,T002" + try: + sh.djlint( + "--lint", + "--ignore", + f"{autofixable_rules},{ignored_rules}", + ".", + _cwd=str(result.project_path), + ) + except sh.ErrorReturnCode as e: + pytest.fail(e.stdout.decode()) + + +@auto_fixable +@pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id) +def test_djlint_check_passes(cookies, context_override): + """Check whether generated project passes djLint --check.""" + result = cookies.bake(extra_context=context_override) + + try: + sh.djlint("--check", ".", _cwd=str(result.project_path)) + except sh.ErrorReturnCode as e: + pytest.fail(e.stdout.decode()) + + @pytest.mark.parametrize( ["use_docker", "expected_test_script"], [ ("n", "pytest"), - ("y", "docker-compose -f local.yml run django pytest"), + ("y", "docker compose -f local.yml run django pytest"), ], ) def test_travis_invokes_pytest(cookies, context, use_docker, expected_test_script): @@ -264,7 +294,7 @@ def test_travis_invokes_pytest(cookies, context, use_docker, expected_test_scrip with open(f"{result.project_path}/.travis.yml") as travis_yml: try: yml = yaml.safe_load(travis_yml)["jobs"]["include"] - assert yml[0]["script"] == ["flake8"] + assert yml[0]["script"] == ["ruff check ."] assert yml[1]["script"] == [expected_test_script] except yaml.YAMLError as e: pytest.fail(str(e)) @@ -274,7 +304,7 @@ def test_travis_invokes_pytest(cookies, context, use_docker, expected_test_scrip ["use_docker", "expected_test_script"], [ ("n", "pytest"), - ("y", "docker-compose -f local.yml run django pytest"), + ("y", "docker compose -f local.yml run django pytest"), ], ) def test_gitlab_invokes_precommit_and_pytest(cookies, context, use_docker, expected_test_script): @@ -301,7 +331,7 @@ def test_gitlab_invokes_precommit_and_pytest(cookies, context, use_docker, expec ["use_docker", "expected_test_script"], [ ("n", "pytest"), - ("y", "docker-compose -f local.yml run django pytest"), + ("y", "docker compose -f local.yml run django pytest"), ], ) def test_github_invokes_linter_and_pytest(cookies, context, use_docker, expected_test_script): @@ -352,12 +382,11 @@ def test_error_if_incompatible(cookies, context, invalid_context): assert isinstance(result.exception, FailedHookException) - @pytest.mark.parametrize( ["editor", "pycharm_docs_exist"], [ - ("None", False), - ("pycharm", True) + ("none", False), + ("pycharm", True), ("vscode", False), ], ) @@ -365,7 +394,6 @@ def test_pycharm_docs_removed(cookies, context, editor, pycharm_docs_exist): context.update({"editor": editor}) result = cookies.bake(extra_context=context) - with open(f"{result.project_path}/docs/index.rst") as f: has_pycharm_docs = "pycharm/configuration" in f.read() assert has_pycharm_docs is pycharm_docs_exist @@ -388,4 +416,4 @@ def test_trim_domain_email(cookies, context): assert "DJANGO_ALLOWED_HOSTS=.example.com" in prod_django_env.read_text() base_settings = result.project_path / "config" / "settings" / "base.py" - assert '"me@example.com"' in base_settings.read_text() + assert '"me@example.com"' in base_settings.read_text() \ No newline at end of file diff --git a/tests/test_docker.sh b/tests/test_docker.sh index cc7be3b..b4e6c3d 100644 --- a/tests/test_docker.sh +++ b/tests/test_docker.sh @@ -1,5 +1,5 @@ #!/bin/sh -# this is a very simple script that tests the docker configuration for dxh_py-django +# this is a very simple script that tests the docker configuration for django-boilarplate # it is meant to be run from the root directory of the repository, eg: # sh tests/test_docker.sh @@ -15,28 +15,39 @@ dxh_py ../../ --no-input --overwrite-if-exists use_docker=y "$@" cd my_awesome_project # make sure all images build -docker-compose -f local.yml build +docker compose -f local.yml build # run the project's type checks -docker-compose -f local.yml run django mypy my_awesome_project +docker compose -f local.yml run django mypy my_awesome_project # run the project's tests -docker-compose -f local.yml run django pytest +docker compose -f local.yml run django pytest # return non-zero status code if there are migrations that have not been created -docker-compose -f local.yml run django python manage.py makemigrations --dry-run --check || { echo "ERROR: there were changes in the models, but migration listed above have not been created and are not saved in version control"; exit 1; } +docker compose -f local.yml run django python manage.py makemigrations --check || { echo "ERROR: there were changes in the models, but migration listed above have not been created and are not saved in version control"; exit 1; } # Test support for translations -docker-compose -f local.yml run django python manage.py makemessages --all +docker compose -f local.yml run django python manage.py makemessages --all # Make sure the check doesn't raise any warnings -docker-compose -f local.yml run django python manage.py check --fail-level WARNING +docker compose -f local.yml run \ + -e DJANGO_SECRET_KEY="$(openssl rand -base64 64)" \ + -e REDIS_URL=redis://redis:6379/0 \ + -e CELERY_BROKER_URL=redis://redis:6379/0 \ + -e DJANGO_AWS_ACCESS_KEY_ID=x \ + -e DJANGO_AWS_SECRET_ACCESS_KEY=x \ + -e DJANGO_AWS_STORAGE_BUCKET_NAME=x \ + -e DJANGO_ADMIN_URL=x \ + -e MAILGUN_API_KEY=x \ + -e MAILGUN_DOMAIN=x \ + django python manage.py check --settings=config.settings.production --deploy --database default --fail-level WARNING + # Generate the HTML for the documentation -docker-compose -f local.yml run docs make html +docker compose -f docs.yml run docs make html # Run npm build script if package.json is present if [ -f "package.json" ] then - docker-compose -f local.yml run node npm run build -fi + docker compose -f local.yml run node npm run build +fi \ No newline at end of file diff --git a/tests/test_hooks.py b/tests/test_hooks.py index 6afdc40..1405df2 100644 --- a/tests/test_hooks.py +++ b/tests/test_hooks.py @@ -23,4 +23,4 @@ def test_append_to_gitignore_file(working_directory): append_to_gitignore_file(".envs/*") linesep = os.linesep.encode() assert gitignore_file.read_bytes() == b"node_modules/" + linesep + b".envs/*" + linesep - assert gitignore_file.read_text() == "node_modules/\n.envs/*\n" + assert gitignore_file.read_text() == "node_modules/\n.envs/*\n" \ No newline at end of file diff --git a/scripts/__init__.py b/{{dxh_py.project_slug}}/.devcontainer/bash_history similarity index 100% rename from scripts/__init__.py rename to {{dxh_py.project_slug}}/.devcontainer/bash_history diff --git a/{{dxh_py.project_slug}}/.devcontainer/bashrc.override.sh b/{{dxh_py.project_slug}}/.devcontainer/bashrc.override.sh new file mode 100644 index 0000000..b457ce6 --- /dev/null +++ b/{{dxh_py.project_slug}}/.devcontainer/bashrc.override.sh @@ -0,0 +1,20 @@ + +# +# .bashrc.override.sh +# + +# persistent bash history +HISTFILE=~/.bash_history +PROMPT_COMMAND="history -a; $PROMPT_COMMAND" + +# set some django env vars +source /entrypoint + +# restore default shell options +set +o errexit +set +o pipefail +set +o nounset + +# start ssh-agent +# https://code.visualstudio.com/docs/remote/troubleshooting +eval "$(ssh-agent -s)" \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.devcontainer/devcontainer.json b/{{dxh_py.project_slug}}/.devcontainer/devcontainer.json new file mode 100644 index 0000000..3fe19f8 --- /dev/null +++ b/{{dxh_py.project_slug}}/.devcontainer/devcontainer.json @@ -0,0 +1,70 @@ +// For format details, see https://containers.dev/implementors/json_reference/ +{ + "name": "{{dxh_py.project_slug}}_dev", + "dockerComposeFile": [ + "../local.yml" + ], + "init": true, + "mounts": [ + { + "source": "./.devcontainer/bash_history", + "target": "/home/dev-user/.bash_history", + "type": "bind" + }, + { + "source": "~/.ssh", + "target": "/home/dev-user/.ssh", + "type": "bind" + } + ], + // Tells devcontainer.json supporting services / tools whether they should run + // /bin/sh -c "while sleep 1000; do :; done" when starting the container instead of the container’s default command + "overrideCommand": false, + "service": "django", + // "remoteEnv": {"PATH": "/home/dev-user/.local/bin:${containerEnv:PATH}"}, + "remoteUser": "dev-user", + "workspaceFolder": "/app", + // Set *default* container specific settings.json values on container create. + "customizations": { + {%- if dxh_py.editor == "VS Code" %} + "vscode": { + "settings": { + "editor.formatOnSave": true, + "[python]": { + "analysis.autoImportCompletions": true, + "analysis.typeCheckingMode": "basic", + "defaultInterpreterPath": "/usr/local/bin/python", + "editor.codeActionsOnSave": { + "source.organizeImports": "always" + }, + "editor.defaultFormatter": "charliermarsh.ruff", + "languageServer": "Pylance", + "linting.enabled": true, + "linting.mypyEnabled": true, + "linting.mypyPath": "/usr/local/bin/mypy", + } + }, + // https://code.visualstudio.com/docs/remote/devcontainerjson-reference#_vs-code-specific-properties + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "davidanson.vscode-markdownlint", + "mrmlnc.vscode-duplicate", + "visualstudioexptteam.vscodeintellicode", + "visualstudioexptteam.intellicode-api-usage-examples", + // python + "ms-python.python", + "ms-python.vscode-pylance", + "charliermarsh.ruff", + // django + "batisteo.vscode-django" + ] + } + {%- endif %} + }, + // Uncomment the next line if you want start specific services in your Docker Compose config. + // "runServices": [], + // Uncomment the next line if you want to keep your containers running after VS Code shuts down. + // "shutdownAction": "none", + // Uncomment the next line to run commands after the container is created. + "postCreateCommand": "cat .devcontainer/bashrc.override.sh >> ~/.bashrc" +} \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.dockerignore b/{{dxh_py.project_slug}}/.dockerignore index 7369480..81e7d30 100644 --- a/{{dxh_py.project_slug}}/.dockerignore +++ b/{{dxh_py.project_slug}}/.dockerignore @@ -9,3 +9,4 @@ .travis.yml venv .git +.envs/ \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.drone.yml b/{{dxh_py.project_slug}}/.drone.yml new file mode 100644 index 0000000..134ab74 --- /dev/null +++ b/{{dxh_py.project_slug}}/.drone.yml @@ -0,0 +1,49 @@ +kind: pipeline +name: default + +environment: + POSTGRES_USER: '{{ dxh_py.project_slug }}' + POSTGRES_PASSWORD: '' + POSTGRES_DB: 'test_{{ dxh_py.project_slug }}' + POSTGRES_HOST_AUTH_METHOD: trust + {%- if dxh_py.use_celery == 'y' %} + CELERY_BROKER_URL: 'redis://redis:6379/0' + {%- endif %} + +steps: +- name: lint + pull: if-not-exists + image: python:3.12 + environment: + PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit + volumes: + - name: pre-commit cache + path: ${PRE_COMMIT_HOME} + commands: + - export PRE_COMMIT_HOME=$CI_PROJECT_DIR/.cache/pre-commit + - pip install -q pre-commit + - pre-commit run --show-diff-on-failure --color=always --all-files + +- name: test + pull: if-not-exists + {%- if dxh_py.use_docker == 'y' %} + image: docker:25.0 + environment: + DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB + commands: + - docker-compose -f local.yml build + - docker-compose -f docs.yml build + - docker-compose -f local.yml run --rm django python manage.py migrate + - docker-compose -f local.yml up -d + - docker-compose -f local.yml run django pytest + {%- else %} + image: python:3.12 + commands: + - pip install -r requirements/local.txt + - pytest + {%- endif%} + +volumes: +- name: pre-commit cache + host: + path: /tmp/drone/cache/pre-commit \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.envs/.local/.django b/{{dxh_py.project_slug}}/.envs/.local/.django index 6384e01..653d2a1 100644 --- a/{{dxh_py.project_slug}}/.envs/.local/.django +++ b/{{dxh_py.project_slug}}/.envs/.local/.django @@ -10,7 +10,7 @@ REDIS_URL=redis://redis:6379/0 # Celery # ------------------------------------------------------------------------------ - +CELERY_BROKER_URL=redis://redis:6379/0 # Flower CELERY_FLOWER_USER=!!!SET CELERY_FLOWER_USER!!! CELERY_FLOWER_PASSWORD=!!!SET CELERY_FLOWER_PASSWORD!!! @@ -22,7 +22,7 @@ TRUSTED_CORS_ORIGINS="http://localhost,capacitor://localhost,http://localhost:30 # Email # ------------------------------------------------------------------------------ -DEFAULT_FROM_EMAIL={{dxh_py.project_slug}} +DEFAULT_FROM_EMAIL=noreply@{{dxh_py.project_slug}}.com EMAIL_HOST='sandbox.smtp.mailtrap.io' EMAIL_HOST_USER="a1e6903e4a929f" EMAIL_HOST_PASSWORD="cabcf313e6c7f8" @@ -39,4 +39,6 @@ EMAIL_USE_TLS=True FACEBOOK_CALLBACK_URL = http://localhost:3000/auth/social/facebook GOOGLE_CALLBACK_URL = http://localhost:3000/auth/social/google -{%- endif %} \ No newline at end of file +{%- endif %} + +DATABASE_URL= postgres://postgres:postgres@postgres:5432/{{ dxh_py.project_slug }} diff --git a/{{dxh_py.project_slug}}/.envs/.production/.django b/{{dxh_py.project_slug}}/.envs/.production/.django index 0f7e930..c1c6be3 100644 --- a/{{dxh_py.project_slug}}/.envs/.production/.django +++ b/{{dxh_py.project_slug}}/.envs/.production/.django @@ -28,8 +28,8 @@ POSTMARK_SERVER_TOKEN= SENDGRID_API_KEY= SENDGRID_GENERATE_MESSAGE_ID=True SENDGRID_MERGE_FIELD_FORMAT=None -{% elif dxh_py.mail_service == 'SendinBlue' %} -SENDINBLUE_API_KEY= +{% elif dxh_py.mail_service == 'Brevo' %} +BREVO_API_KEY= {% elif dxh_py.mail_service == 'SparkPost' %} SPARKPOST_API_KEY= {% endif %} diff --git a/{{dxh_py.project_slug}}/.github/workflows/ci.yml b/{{dxh_py.project_slug}}/.github/workflows/ci.yml index 9bc9de4..6e31536 100644 --- a/{{dxh_py.project_slug}}/.github/workflows/ci.yml +++ b/{{dxh_py.project_slug}}/.github/workflows/ci.yml @@ -23,21 +23,20 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Code Repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: "3.11" - cache: pip - cache-dependency-path: | - requirements/base.txt - requirements/local.txt + python-version: "3.12" + {%- if dxh_py.open_source_license != 'Not open source' %} + # Consider using pre-commit.ci for open source project + {%- endif %} - name: Run pre-commit - uses: pre-commit/action@v2.0.3 + uses: pre-commit/action@v3.0.1 - # With no caching at all the entire ci process takes 4m 30s to complete! + # With no caching at all the entire ci process takes 3m to complete! pytest: runs-on: ubuntu-latest {%- if dxh_py.use_docker == 'n' %} @@ -51,7 +50,7 @@ jobs: {%- endif %} {%- if dxh_py.database_engine == 'postgresql' %} postgres: - image: postgres:12 + image: postgres:{{ dxh_py.database_version.lower().split('@')[1] }} ports: - 5432:5432 env: @@ -81,28 +80,33 @@ jobs: {%- endif %} steps: - - name: Checkout Code Repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 {%- if dxh_py.use_docker == 'y' %} - name: Build the Stack - run: docker-compose -f local.yml build + run: docker compose -f local.yml build django + + - name: Build the docs + run: docker compose -f docs.yml build docs + + - name: Check DB Migrations + run: docker compose -f local.yml run --rm django python manage.py makemigrations --check - name: Run DB Migrations - run: docker-compose -f local.yml run --rm django python manage.py migrate + run: docker compose -f local.yml run --rm django python manage.py migrate - name: Run Django Tests - run: docker-compose -f local.yml run django pytest + run: docker compose -f local.yml run django pytest - name: Tear down the Stack - run: docker-compose -f local.yml down + run: docker compose -f local.yml down {%- else %} - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.11" + python-version: "3.12" cache: pip cache-dependency-path: | requirements/base.txt @@ -113,6 +117,12 @@ jobs: python -m pip install --upgrade pip pip install -r requirements/local.txt + - name: Check DB Migrations + run: python manage.py makemigrations --check + + - name: Run DB Migrations + run: python manage.py migrate + - name: Test with pytest run: pytest {%- endif %} diff --git a/{{dxh_py.project_slug}}/.gitignore b/{{dxh_py.project_slug}}/.gitignore index 94191e7..55718cc 100644 --- a/{{dxh_py.project_slug}}/.gitignore +++ b/{{dxh_py.project_slug}}/.gitignore @@ -152,7 +152,7 @@ typings/ # .nfs files are created when an open file is removed but is still being accessed .nfs* -{% if dxh_py.editor == "vscode" -%} + ### VisualStudioCode template .vscode/* !.vscode/settings.json @@ -161,13 +161,11 @@ typings/ !.vscode/extensions.json *.code-workspace -{% endif %} - - +# Local History for devcontainer +.devcontainer/bash_history # Local History for Visual Studio Code .history/ - {% if dxh_py.editor == "pycharm" -%} # Provided default Pycharm Run/Debug Configurations should be tracked by git # In case of local modifications made by Pycharm, use update-index command diff --git a/{{dxh_py.project_slug}}/.gitlab-ci.yml b/{{dxh_py.project_slug}}/.gitlab-ci.yml index a7617de..f6c6a09 100644 --- a/{{dxh_py.project_slug}}/.gitlab-ci.yml +++ b/{{dxh_py.project_slug}}/.gitlab-ci.yml @@ -21,7 +21,7 @@ variables: precommit: stage: lint - image: python:3.11 + image: python:3.12 variables: PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit cache: @@ -35,22 +35,19 @@ precommit: pytest: stage: test {%- if dxh_py.use_docker == 'y' %} - image: docker/compose:1.29.2 - tags: - - docker + image: docker:25.0 services: - docker:dind before_script: - - docker-compose -f local.yml build + - docker compose -f local.yml build + - docker compose -f docs.yml build # Ensure celerybeat does not crash due to non-existent tables - - docker-compose -f local.yml run --rm django python manage.py migrate - - docker-compose -f local.yml up -d + - docker compose -f local.yml run --rm django python manage.py migrate + - docker compose -f local.yml up -d script: - - docker-compose -f local.yml run django pytest + - docker compose -f local.yml run django pytest {%- else %} - image: python:3.11 - tags: - - python + image: python:3.12 services: {%- if dxh_py.database_engine == 'postgresql' %} - postgres:{{ dxh_py.database_version.split('@')[1] }} diff --git a/{{dxh_py.project_slug}}/.idea/misc.xml b/{{dxh_py.project_slug}}/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/modules.xml b/{{dxh_py.project_slug}}/.idea/modules.xml new file mode 100644 index 0000000..416db3c --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/runConfigurations/docker_compose_up_django.xml b/{{dxh_py.project_slug}}/.idea/runConfigurations/docker_compose_up_django.xml new file mode 100644 index 0000000..30010d9 --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/runConfigurations/docker_compose_up_django.xml @@ -0,0 +1,23 @@ + + + + + + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/runConfigurations/docker_compose_up_docs.xml b/{{dxh_py.project_slug}}/.idea/runConfigurations/docker_compose_up_docs.xml new file mode 100644 index 0000000..03246e4 --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/runConfigurations/docker_compose_up_docs.xml @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/runConfigurations/merge_production_dotenvs_in_dotenv.xml b/{{dxh_py.project_slug}}/.idea/runConfigurations/merge_production_dotenvs_in_dotenv.xml new file mode 100644 index 0000000..2924236 --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/runConfigurations/merge_production_dotenvs_in_dotenv.xml @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/runConfigurations/migrate.xml b/{{dxh_py.project_slug}}/.idea/runConfigurations/migrate.xml new file mode 100644 index 0000000..0acfb5d --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/runConfigurations/migrate.xml @@ -0,0 +1,32 @@ + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/runConfigurations/pytest___.xml b/{{dxh_py.project_slug}}/.idea/runConfigurations/pytest___.xml new file mode 100644 index 0000000..08d3405 --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/runConfigurations/pytest___.xml @@ -0,0 +1,25 @@ + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/runConfigurations/pytest__users.xml b/{{dxh_py.project_slug}}/.idea/runConfigurations/pytest__users.xml new file mode 100644 index 0000000..9096c41 --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/runConfigurations/pytest__users.xml @@ -0,0 +1,25 @@ + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/runConfigurations/runserver.xml b/{{dxh_py.project_slug}}/.idea/runConfigurations/runserver.xml new file mode 100644 index 0000000..618c2b6 --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/runConfigurations/runserver.xml @@ -0,0 +1,33 @@ + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/runConfigurations/runserver_plus.xml b/{{dxh_py.project_slug}}/.idea/runConfigurations/runserver_plus.xml new file mode 100644 index 0000000..d87c2da --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/runConfigurations/runserver_plus.xml @@ -0,0 +1,33 @@ + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/vcs.xml b/{{dxh_py.project_slug}}/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/webResources.xml b/{{dxh_py.project_slug}}/.idea/webResources.xml new file mode 100644 index 0000000..5e1897c --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/webResources.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.idea/{{dxh_py.project_slug}}.iml b/{{dxh_py.project_slug}}/.idea/{{dxh_py.project_slug}}.iml new file mode 100644 index 0000000..72dda08 --- /dev/null +++ b/{{dxh_py.project_slug}}/.idea/{{dxh_py.project_slug}}.iml @@ -0,0 +1,47 @@ + + + + + + + + + + {% if dxh_py.frontend_pipeline in ['Gulp', 'Webpack'] %} + + + + {% else %} + + {% endif %} + + + + + + + + + + + + + + \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/.pre-commit-config.yaml b/{{dxh_py.project_slug}}/.pre-commit-config.yaml index 574927f..75be9c7 100644 --- a/{{dxh_py.project_slug}}/.pre-commit-config.yaml +++ b/{{dxh_py.project_slug}}/.pre-commit-config.yaml @@ -1,9 +1,12 @@ -exclude: '^docs/|/migrations/' +exclude: '^docs/|/migrations/|devcontainer.json' default_stages: [commit] +default_language_version: + python: python3.12 + repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -18,38 +21,33 @@ repos: - id: detect-private-key - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.0-alpha.9-for-vscode + rev: v4.0.0-alpha.8 hooks: - id: prettier args: ['--tab-width', '2', '--single-quote'] exclude: '{{dxh_py.project_slug}}/templates/' - repo: https://github.com/adamchainz/django-upgrade - rev: "1.13.0" + rev: '1.20.0' hooks: - id: django-upgrade - args: ["--target-version", "4.1"] - - - repo: https://github.com/asottile/pyupgrade - rev: v3.3.2 - hooks: - - id: pyupgrade - args: [--py311-plus] + args: ['--target-version', '5.0'] - - repo: https://github.com/psf/black - rev: 23.3.0 + # Run the Ruff linter. + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.2 hooks: - - id: black - - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - - - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + # Linter + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + # Formatter + - id: ruff-format + + - repo: https://github.com/Riverside-Healthcare/djLint + rev: v1.34.1 hooks: - - id: flake8 + - id: djlint-reformat-django + - id: djlint-django # sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date ci: diff --git a/{{dxh_py.project_slug}}/.readthedocs.yml b/{{dxh_py.project_slug}}/.readthedocs.yml index d5a8ef6..5564388 100644 --- a/{{dxh_py.project_slug}}/.readthedocs.yml +++ b/{{dxh_py.project_slug}}/.readthedocs.yml @@ -8,7 +8,7 @@ version: 2 build: os: ubuntu-22.04 tools: - python: '3.11' + python: '3.12' # Build documentation in the docs/ directory with Sphinx sphinx: diff --git a/{{dxh_py.project_slug}}/.travis.yml b/{{dxh_py.project_slug}}/.travis.yml index c14b017..60f25a1 100644 --- a/{{dxh_py.project_slug}}/.travis.yml +++ b/{{dxh_py.project_slug}}/.travis.yml @@ -2,7 +2,7 @@ dist: focal language: python python: - - "3.11" + - "3.12" services: - {% if dxh_py.use_docker == 'y' %}docker{% else %}postgresql{% endif %} @@ -10,23 +10,24 @@ jobs: include: - name: "Linter" before_script: - - pip install -q flake8 + - pip install -q ruff script: - - "flake8" + - ruff check . - name: "Django Test" {%- if dxh_py.use_docker == 'y' %} before_script: - - docker-compose -v + - docker compose -v - docker -v - - docker-compose -f local.yml build + - docker compose -f local.yml build + - docker compose -f docs.yml build # Ensure celerybeat does not crash due to non-existent tables - - docker-compose -f local.yml run --rm django python manage.py migrate - - docker-compose -f local.yml up -d + - docker compose -f local.yml run --rm django python manage.py migrate + - docker compose -f local.yml up -d script: - - "docker-compose -f local.yml run django pytest" + - docker compose -f local.yml run django pytest after_failure: - - docker-compose -f local.yml logs + - docker compose -f local.yml logs {%- else %} before_install: - sudo apt-get update -qq @@ -37,9 +38,9 @@ jobs: - sudo apt-get install -qq libsqlite3-dev libxml2 libxml2-dev libssl-dev libbz2-dev wget curl llvm language: python python: - - "3.11" + - "3.12" install: - pip install -r requirements/local.txt script: - - "pytest" + - pytest {%- endif %} diff --git a/{{dxh_py.project_slug}}/COPYING b/{{dxh_py.project_slug}}/COPYING index 94a9ed0..20d40b6 100644 --- a/{{dxh_py.project_slug}}/COPYING +++ b/{{dxh_py.project_slug}}/COPYING @@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. +. \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/Procfile b/{{dxh_py.project_slug}}/Procfile index e513c4c..d78589c 100644 --- a/{{dxh_py.project_slug}}/Procfile +++ b/{{dxh_py.project_slug}}/Procfile @@ -1,6 +1,6 @@ release: python manage.py migrate {%- if dxh_py.use_async == "y" %} -web: gunicorn config.asgi:application -k uvicorn.workers.UvicornWorker +web: gunicorn config.asgi:application -k uvicorn_worker.UvicornWorker {%- else %} web: gunicorn config.wsgi:application {%- endif %} diff --git a/{{dxh_py.project_slug}}/README.md b/{{dxh_py.project_slug}}/README.md index d43996e..1f418d3 100644 --- a/{{dxh_py.project_slug}}/README.md +++ b/{{dxh_py.project_slug}}/README.md @@ -2,8 +2,9 @@ {{ dxh_py.description }} -[![Built with dxh_py Django](https://img.shields.io/badge/built%20with-dxh_py%20Django-ff69b4.svg?logo=dxh_py)](https://github.com/dxh_py/dxh_py-django/) +[![Built with Django-Boilerplate](https://img.shields.io/badge/Built%20with-Django%20Boilerplate-ff69b4.svg?logo=Django-Boilerplate)](https://github.com/devxhub/django-boilerplate/) [![Black code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black) +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) {%- if dxh_py.open_source_license != "Not open source" %} diff --git a/{{dxh_py.project_slug}}/bin/post_compile b/{{dxh_py.project_slug}}/bin/post_compile index a9c94b3..eebe43a 100644 --- a/{{dxh_py.project_slug}}/bin/post_compile +++ b/{{dxh_py.project_slug}}/bin/post_compile @@ -1,4 +1,5 @@ #!/usr/bin/env bash +{%- if dxh_py.frontend_pipeline == "Django Compressor" %} compress_enabled() { python << END @@ -19,4 +20,7 @@ if compress_enabled then python manage.py compress fi +{%- endif %} + python manage.py collectstatic --noinput +python manage.py compilemessages -i site-packages \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/compose/local/django/Dockerfile b/{{dxh_py.project_slug}}/compose/local/django/Dockerfile index bc0e67a..34062ab 100644 --- a/{{dxh_py.project_slug}}/compose/local/django/Dockerfile +++ b/{{dxh_py.project_slug}}/compose/local/django/Dockerfile @@ -1,8 +1,8 @@ # define an alias for the specific python version used in this file. -FROM python:3.11.3-slim-bullseye as python +FROM docker.io/python:3.12.5-slim-bookworm AS python # Python build stage -FROM python as python-build-stage +FROM python AS python-build-stage ARG BUILD_ENVIRONMENT=local @@ -27,17 +27,29 @@ RUN pip wheel --wheel-dir /usr/src/app/wheels \ # Python 'run' stage -FROM python as python-run-stage +FROM python AS python-run-stage ARG BUILD_ENVIRONMENT=local ARG APP_HOME=/app -ENV PYTHONUNBUFFERED 1 -ENV PYTHONDONTWRITEBYTECODE 1 -ENV BUILD_ENV ${BUILD_ENVIRONMENT} +ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 +ENV BUILD_ENV=${BUILD_ENVIRONMENT} WORKDIR ${APP_HOME} +{% if dxh_py.use_docker == "y" %} +# devcontainer dependencies and utils +RUN apt-get update && apt-get install --no-install-recommends -y \ + sudo git bash-completion nano ssh + +# Create devcontainer user and add it to sudoers +RUN groupadd --gid 1000 dev-user \ + && useradd --uid 1000 --gid dev-user --shell /bin/bash --create-home dev-user \ + && echo dev-user ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/dev-user \ + && chmod 0440 /etc/sudoers.d/dev-user +{% endif %} + # Install required system dependencies RUN apt-get update && apt-get install --no-install-recommends -y \ {%- if dxh_py.database_engine == "postgresql" %} @@ -59,7 +71,7 @@ COPY --from=python-build-stage /usr/src/app/wheels /wheels/ # use wheels to install python dependencies RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \ - && rm -rf /wheels/ + && rm -rf /wheels/ COPY ./compose/production/django/entrypoint /entrypoint RUN sed -i 's/\r$//g' /entrypoint diff --git a/{{dxh_py.project_slug}}/compose/local/django/celery/beat/start b/{{dxh_py.project_slug}}/compose/local/django/celery/beat/start index 61f8396..60bdca3 100644 --- a/{{dxh_py.project_slug}}/compose/local/django/celery/beat/start +++ b/{{dxh_py.project_slug}}/compose/local/django/celery/beat/start @@ -5,4 +5,4 @@ set -o nounset rm -f './celerybeat.pid' -exec watchfiles celery.__main__.main --args '-A config.celery_app beat -l INFO' +exec watchfiles --filter python celery.__main__.main --args '-A config.celery_app beat -l INFO' \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/compose/local/django/celery/flower/start b/{{dxh_py.project_slug}}/compose/local/django/celery/flower/start index ac3cc6b..cebb622 100644 --- a/{{dxh_py.project_slug}}/compose/local/django/celery/flower/start +++ b/{{dxh_py.project_slug}}/compose/local/django/celery/flower/start @@ -3,6 +3,14 @@ set -o errexit set -o nounset -exec watchfiles celery.__main__.main \ + +until timeout 10 celery -A config.celery_app inspect ping; do + >&2 echo "Celery workers not available" +done + +echo 'Starting flower' + + +exec watchfiles --filter python celery.__main__.main \ --args \ "-A config.celery_app -b \"${CELERY_BROKER_URL}\" flower --basic_auth=\"${CELERY_FLOWER_USER}:${CELERY_FLOWER_PASSWORD}\"" diff --git a/{{dxh_py.project_slug}}/compose/local/django/celery/worker/start b/{{dxh_py.project_slug}}/compose/local/django/celery/worker/start index 16341fd..ab45b65 100644 --- a/{{dxh_py.project_slug}}/compose/local/django/celery/worker/start +++ b/{{dxh_py.project_slug}}/compose/local/django/celery/worker/start @@ -4,4 +4,4 @@ set -o errexit set -o nounset -exec watchfiles celery.__main__.main --args '-A config.celery_app worker -l INFO' +exec watchfiles --filter python celery.__main__.main --args '-A config.celery_app worker -l INFO' \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/compose/local/django/start b/{{dxh_py.project_slug}}/compose/local/django/start index e55c887..bda59f7 100644 --- a/{{dxh_py.project_slug}}/compose/local/django/start +++ b/{{dxh_py.project_slug}}/compose/local/django/start @@ -9,5 +9,5 @@ python manage.py migrate {%- if dxh_py.use_async == 'y' %} exec uvicorn config.asgi:application --host 0.0.0.0 --reload --reload-include '*.html' {%- else %} -exec python manage.py runserver 0.0.0.0:8000 -{%- endif %} +exec python manage.py runserver_plus 0.0.0.0:8000 +{%- endif %} \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/compose/local/docs/Dockerfile b/{{dxh_py.project_slug}}/compose/local/docs/Dockerfile index fea7e8e..4bc4440 100644 --- a/{{dxh_py.project_slug}}/compose/local/docs/Dockerfile +++ b/{{dxh_py.project_slug}}/compose/local/docs/Dockerfile @@ -1,11 +1,10 @@ # define an alias for the specific python version used in this file. -FROM python:3.11.3-slim-bullseye as python - +FROM docker.io/python:3.12.5-slim-bookworm AS python # Python build stage -FROM python as python-build-stage +FROM python AS python-build-stage -ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONDONTWRITEBYTECODE=1 RUN apt-get update && apt-get install --no-install-recommends -y \ # dependencies for building Python packages @@ -30,11 +29,11 @@ RUN pip wheel --no-cache-dir --wheel-dir /usr/src/app/wheels \ # Python 'run' stage -FROM python as python-run-stage +FROM python AS python-run-stage ARG BUILD_ENVIRONMENT -ENV PYTHONUNBUFFERED 1 -ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 RUN apt-get update && apt-get install --no-install-recommends -y \ # To run the Makefile diff --git a/{{dxh_py.project_slug}}/compose/local/node/Dockerfile b/{{dxh_py.project_slug}}/compose/local/node/Dockerfile index 707ed0c..141d9ab 100644 --- a/{{dxh_py.project_slug}}/compose/local/node/Dockerfile +++ b/{{dxh_py.project_slug}}/compose/local/node/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18-bullseye-slim +FROM docker.io/node:22-bookworm-slim WORKDIR /app @@ -6,4 +6,4 @@ COPY ./package.json /app RUN npm install && npm cache clean --force -ENV PATH ./node_modules/.bin/:$PATH +ENV PATH=./node_modules/.bin/:$PATH \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/compose/production/aws/Dockerfile b/{{dxh_py.project_slug}}/compose/production/aws/Dockerfile index 4d1ecbb..ae372c3 100644 --- a/{{dxh_py.project_slug}}/compose/production/aws/Dockerfile +++ b/{{dxh_py.project_slug}}/compose/production/aws/Dockerfile @@ -1,4 +1,8 @@ -FROM garland/aws-cli-docker:1.16.140 +FROM docker.io/amazon/aws-cli:2.17.0 + +# Clear entrypoint from the base image, otherwise it's always calling the aws CLI +ENTRYPOINT [] +CMD ["/bin/bash"] COPY ./compose/production/aws/maintenance /usr/local/bin/maintenance COPY ./compose/production/postgres/maintenance/_sourced /usr/local/bin/maintenance/_sourced @@ -6,4 +10,4 @@ COPY ./compose/production/postgres/maintenance/_sourced /usr/local/bin/maintenan RUN chmod +x /usr/local/bin/maintenance/* RUN mv /usr/local/bin/maintenance/* /usr/local/bin \ - && rmdir /usr/local/bin/maintenance + && rmdir /usr/local/bin/maintenance \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/compose/production/aws/maintenance/download b/{{dxh_py.project_slug}}/compose/production/aws/maintenance/download index 0c51593..9561d91 100644 --- a/{{dxh_py.project_slug}}/compose/production/aws/maintenance/download +++ b/{{dxh_py.project_slug}}/compose/production/aws/maintenance/download @@ -3,7 +3,7 @@ ### Download a file from your Amazon S3 bucket to the postgres /backups folder ### ### Usage: -### $ docker-compose -f production.yml run --rm awscli <1> +### $ docker compose -f production.yml run --rm awscli <1> set -o errexit set -o pipefail diff --git a/{{dxh_py.project_slug}}/compose/production/aws/maintenance/upload b/{{dxh_py.project_slug}}/compose/production/aws/maintenance/upload index 9446b93..73c1b9b 100644 --- a/{{dxh_py.project_slug}}/compose/production/aws/maintenance/upload +++ b/{{dxh_py.project_slug}}/compose/production/aws/maintenance/upload @@ -3,7 +3,7 @@ ### Upload the /backups folder to Amazon S3 ### ### Usage: -### $ docker-compose -f production.yml run --rm awscli upload +### $ docker compose -f production.yml run --rm awscli upload set -o errexit set -o pipefail diff --git a/{{dxh_py.project_slug}}/compose/production/django/Dockerfile b/{{dxh_py.project_slug}}/compose/production/django/Dockerfile index a38d354..a1b1cdd 100644 --- a/{{dxh_py.project_slug}}/compose/production/django/Dockerfile +++ b/{{dxh_py.project_slug}}/compose/production/django/Dockerfile @@ -1,5 +1,5 @@ {% if dxh_py.frontend_pipeline in ['Gulp', 'Webpack'] -%} -FROM node:18-bullseye-slim as client-builder +FROM docker.io/node:20-bookworm-slim AS client-builder ARG APP_HOME=/app WORKDIR ${APP_HOME} @@ -25,10 +25,10 @@ RUN npm run build {%- endif %} # define an alias for the specific python version used in this file. -FROM python:3.11.3-slim-bullseye as python +FROM docker.io/python:3.12.5-slim-bookworm AS python # Python build stage -FROM python as python-build-stage +FROM python AS python-build-stage ARG BUILD_ENVIRONMENT=production @@ -53,14 +53,14 @@ RUN pip wheel --wheel-dir /usr/src/app/wheels \ # Python 'run' stage -FROM python as python-run-stage +FROM python AS python-run-stage ARG BUILD_ENVIRONMENT=production ARG APP_HOME=/app -ENV PYTHONUNBUFFERED 1 -ENV PYTHONDONTWRITEBYTECODE 1 -ENV BUILD_ENV ${BUILD_ENVIRONMENT} +ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 +ENV BUILD_ENV=${BUILD_ENVIRONMENT} WORKDIR ${APP_HOME} @@ -113,7 +113,7 @@ RUN sed -i 's/\r$//g' /start-celerybeat RUN chmod +x /start-celerybeat -COPY ./compose/production/django/celery/flower/start /start-flower +COPY --chown=django:django ./compose/production/django/celery/flower/start /start-flower RUN sed -i 's/\r$//g' /start-flower RUN chmod +x /start-flower {%- endif %} @@ -127,8 +127,15 @@ COPY --chown=django:django . ${APP_HOME} {%- endif %} # make django owner of the WORKDIR directory as well. -RUN chown django:django ${APP_HOME} +RUN chown -R django:django ${APP_HOME} USER django +RUN DATABASE_URL="" \ + {%- if dxh_py.use_celery == "y" %} + CELERY_BROKER_URL="" \ + {%- endif %} + DJANGO_SETTINGS_MODULE="config.settings.test" \ + python manage.py compilemessages + ENTRYPOINT ["/entrypoint"] diff --git a/{{dxh_py.project_slug}}/compose/production/django/celery/flower/start b/{{dxh_py.project_slug}}/compose/production/django/celery/flower/start index 4180d67..f903a05 100644 --- a/{{dxh_py.project_slug}}/compose/production/django/celery/flower/start +++ b/{{dxh_py.project_slug}}/compose/production/django/celery/flower/start @@ -4,6 +4,14 @@ set -o errexit set -o nounset + +until timeout 10 celery -A config.celery_app inspect ping; do + >&2 echo "Celery workers not available" +done + +echo 'Starting flower' + + exec celery \ -A config.celery_app \ -b "${CELERY_BROKER_URL}" \ diff --git a/{{dxh_py.project_slug}}/compose/production/django/entrypoint b/{{dxh_py.project_slug}}/compose/production/django/entrypoint index ba27dc8..0780b51 100644 --- a/{{dxh_py.project_slug}}/compose/production/django/entrypoint +++ b/{{dxh_py.project_slug}}/compose/production/django/entrypoint @@ -34,10 +34,10 @@ suggest_unrecoverable_after = 30 start = time.time() {%- if dxh_py.database_engine == 'postgresql' %} -import psycopg2 +import psycopg while True: try: - psycopg2.connect( + psycopg.connect( dbname="${POSTGRES_DB}", user="${POSTGRES_USER}", password="${POSTGRES_PASSWORD}", @@ -45,7 +45,7 @@ while True: port="${POSTGRES_PORT}", ) break - except psycopg2.OperationalError as error: + except psycopg.OperationalError as error: sys.stderr.write("Waiting for PostgreSQL to become available...\n") if time.time() - start > suggest_unrecoverable_after: sys.stderr.write(" This is taking longer than expected. The following exception may be indicative of an unrecoverable error: '{}'\n".format(error)) diff --git a/{{dxh_py.project_slug}}/compose/production/django/start b/{{dxh_py.project_slug}}/compose/production/django/start index 19be40d..b089cd4 100644 --- a/{{dxh_py.project_slug}}/compose/production/django/start +++ b/{{dxh_py.project_slug}}/compose/production/django/start @@ -28,7 +28,7 @@ if compress_enabled; then fi {%- endif %} {%- if dxh_py.use_async == 'y' %} -exec /usr/local/bin/gunicorn config.asgi --bind 0.0.0.0:5000 --chdir=/app -k uvicorn.workers.UvicornWorker +exec /usr/local/bin/gunicorn config.asgi --bind 0.0.0.0:5000 --chdir=/app -k uvicorn_worker.UvicornWorker {%- else %} exec /usr/local/bin/gunicorn config.wsgi --bind 0.0.0.0:5000 --chdir=/app {%- endif %} diff --git a/{{dxh_py.project_slug}}/compose/production/nginx/Dockerfile b/{{dxh_py.project_slug}}/compose/production/nginx/Dockerfile index 911b16f..ec2ad35 100644 --- a/{{dxh_py.project_slug}}/compose/production/nginx/Dockerfile +++ b/{{dxh_py.project_slug}}/compose/production/nginx/Dockerfile @@ -1,2 +1,2 @@ -FROM nginx:1.17.8-alpine +FROM docker.io/nginx:1.17.8-alpine COPY ./compose/production/nginx/default.conf /etc/nginx/conf.d/default.conf diff --git a/{{dxh_py.project_slug}}/compose/production/postgres/Dockerfile b/{{dxh_py.project_slug}}/compose/production/postgres/Dockerfile index be31a99..4dbf771 100644 --- a/{{dxh_py.project_slug}}/compose/production/postgres/Dockerfile +++ b/{{dxh_py.project_slug}}/compose/production/postgres/Dockerfile @@ -1,4 +1,4 @@ -FROM postgres:{{ dxh_py.database_version.lower().split('@')[1] }} +FROM docker.io/postgres:{{ dxh_py.database_version.lower().split('@')[1] }} COPY ./compose/production/postgres/maintenance /usr/local/bin/maintenance diff --git a/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/backup b/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/backup index ee0c9d6..f72304c 100644 --- a/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/backup +++ b/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/backup @@ -4,7 +4,7 @@ ### Create a database backup. ### ### Usage: -### $ docker-compose -f .yml (exec |run --rm) postgres backup +### $ docker compose -f .yml (exec |run --rm) postgres backup set -o errexit diff --git a/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/backups b/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/backups index 0484ccf..a18937d 100644 --- a/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/backups +++ b/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/backups @@ -4,7 +4,7 @@ ### View backups. ### ### Usage: -### $ docker-compose -f .yml (exec |run --rm) postgres backups +### $ docker compose -f .yml (exec |run --rm) postgres backups set -o errexit diff --git a/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/restore b/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/restore index 9661ca7..c68f17d 100644 --- a/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/restore +++ b/{{dxh_py.project_slug}}/compose/production/postgres/maintenance/restore @@ -7,7 +7,7 @@ ### <1> filename of an existing backup. ### ### Usage: -### $ docker-compose -f .yml (exec |run --rm) postgres restore <1> +### $ docker compose -f .yml (exec |run --rm) postgres restore <1> set -o errexit diff --git a/{{dxh_py.project_slug}}/compose/production/traefik/Dockerfile b/{{dxh_py.project_slug}}/compose/production/traefik/Dockerfile index 30470d0..2a9b2fd 100644 --- a/{{dxh_py.project_slug}}/compose/production/traefik/Dockerfile +++ b/{{dxh_py.project_slug}}/compose/production/traefik/Dockerfile @@ -1,4 +1,4 @@ -FROM traefik:2.10.0 +FROM docker.io/traefik:3.1.2 RUN mkdir -p /etc/traefik/acme \ && touch /etc/traefik/acme/acme.json \ && chmod 600 /etc/traefik/acme/acme.json diff --git a/{{dxh_py.project_slug}}/compose/production/traefik/traefik.yml b/{{dxh_py.project_slug}}/compose/production/traefik/traefik.yml index f3e8e23..fce3d00 100644 --- a/{{dxh_py.project_slug}}/compose/production/traefik/traefik.yml +++ b/{{dxh_py.project_slug}}/compose/production/traefik/traefik.yml @@ -6,7 +6,7 @@ entryPoints: # http address: ':80' http: - # https://docs.traefik.io/routing/entrypoints/#entrypoint + # https://doc.traefik.io/traefik/routing/entrypoints/#entrypoint redirections: entryPoint: to: web-secure @@ -22,11 +22,11 @@ entryPoints: certificatesResolvers: letsencrypt: - # https://docs.traefik.io/master/https/acme/#lets-encrypt + # https://doc.traefik.io/traefik/https/acme/#lets-encrypt acme: email: '{{ dxh_py.email }}' storage: /etc/traefik/acme/acme.json - # https://docs.traefik.io/master/https/acme/#httpchallenge + # https://doc.traefik.io/traefik/https/acme/#httpchallenge httpChallenge: entryPoint: web @@ -44,7 +44,7 @@ http: - csrf service: django tls: - # https://docs.traefik.io/master/routing/routers/#certresolver + # https://doc.traefik.io/traefik/routing/routers/#certresolver certResolver: letsencrypt {%- if dxh_py.use_celery == 'y' %} @@ -54,7 +54,7 @@ http: - flower service: flower tls: - # https://docs.traefik.io/master/routing/routers/#certresolver + # https://doc.traefik.io/traefik/master/routing/routers/#certresolver certResolver: letsencrypt {%- endif %} {%- if dxh_py.cloud_provider == 'None' %} @@ -76,7 +76,7 @@ http: middlewares: csrf: - # https://docs.traefik.io/master/middlewares/headers/#hostsproxyheaders + # https://doc.traefik.io/traefik/master/middlewares/http/headers/#hostsproxyheaders # https://docs.djangoproject.com/en/dev/ref/csrf/#ajax headers: hostsProxyHeaders: ['X-CSRFToken'] @@ -102,7 +102,7 @@ http: {%- endif %} providers: - # https://docs.traefik.io/master/providers/file/ + # https://doc.traefik.io/traefik/master/providers/file/ file: filename: /etc/traefik/traefik.yml watch: true diff --git a/{{dxh_py.project_slug}}/config/api_router.py b/{{dxh_py.project_slug}}/config/api_router.py index e79ac53..1dddbc9 100644 --- a/{{dxh_py.project_slug}}/config/api_router.py +++ b/{{dxh_py.project_slug}}/config/api_router.py @@ -1,12 +1,10 @@ from django.conf import settings -from rest_framework.routers import DefaultRouter, SimpleRouter +from rest_framework.routers import DefaultRouter +from rest_framework.routers import SimpleRouter from {{ dxh_py.project_slug }}.users.api.views import UserViewSet -if settings.DEBUG: - router = DefaultRouter() -else: - router = SimpleRouter() +router = DefaultRouter() if settings.DEBUG else SimpleRouter() router.register("users", UserViewSet) diff --git a/{{dxh_py.project_slug}}/config/asgi.py b/{{dxh_py.project_slug}}/config/asgi.py index 9873d49..6381d6b 100644 --- a/{{dxh_py.project_slug}}/config/asgi.py +++ b/{{dxh_py.project_slug}}/config/asgi.py @@ -1,3 +1,4 @@ +# ruff: noqa """ ASGI config for {{ dxh_py.project_name }} project. diff --git a/{{dxh_py.project_slug}}/config/settings/base.py b/{{dxh_py.project_slug}}/config/settings/base.py index 4b60bc7..d8d722a 100644 --- a/{{dxh_py.project_slug}}/config/settings/base.py +++ b/{{dxh_py.project_slug}}/config/settings/base.py @@ -1,3 +1,4 @@ +# ruff: noqa: ERA001, E501 """ Base settings to build other settings files upon. """ @@ -204,6 +205,7 @@ "crispy_bootstrap5", "allauth", "allauth.account", + "allauth.mfa", "allauth.socialaccount", "allauth.socialaccount.providers.facebook", "allauth.socialaccount.providers.google", @@ -271,7 +273,9 @@ ] # https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ - {"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"}, + { + "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"}, @@ -282,7 +286,9 @@ # https://docs.djangoproject.com/en/dev/ref/settings/#middleware MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", + {%- if dxh_py.use_drf == 'y' %} "corsheaders.middleware.CorsMiddleware", + {%- endif %} {%- if dxh_py.use_whitenoise == 'y' %} "whitenoise.middleware.WhiteNoiseMiddleware", {%- endif %} @@ -293,6 +299,7 @@ "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", + "allauth.account.middleware.AccountMiddleware", ] # STATIC @@ -341,7 +348,7 @@ "{{dxh_py.project_slug}}.users.context_processors.allauth_settings", ], }, - } + }, ] # https://docs.djangoproject.com/en/dev/ref/settings/#form-renderer @@ -383,6 +390,9 @@ ADMINS = [("""{{dxh_py.author_name}}""", "{{dxh_py.email}}")] # https://docs.djangoproject.com/en/dev/ref/settings/#managers MANAGERS = ADMINS +# https://dxh_py-django.readthedocs.io/en/latest/settings.html#other-environment-settings +# Force the `admin` sign in process to go through the `django-allauth` workflow +DJANGO_ADMIN_FORCE_ALLAUTH = env.bool("DJANGO_ADMIN_FORCE_ALLAUTH", default=False) # LOGGING # ------------------------------------------------------------------------------ @@ -402,7 +412,7 @@ "level": "DEBUG", "class": "logging.StreamHandler", "formatter": "verbose", - } + }, }, "root": {"level": "INFO", "handlers": ["console"]}, } @@ -446,25 +456,25 @@ # django-allauth # ------------------------------------------------------------------------------ ACCOUNT_ALLOW_REGISTRATION = env.bool("DJANGO_ACCOUNT_ALLOW_REGISTRATION", True) -# https://django-allauth.readthedocs.io/en/latest/configuration.html +# https://docs.allauth.org/en/latest/account/configuration.html ACCOUNT_AUTHENTICATION_METHOD = "{{dxh_py.username_type}}" -# https://django-allauth.readthedocs.io/en/latest/configuration.html +# https://docs.allauth.org/en/latest/account/configuration.html ACCOUNT_EMAIL_REQUIRED = True {%- if dxh_py.username_type == "email" %} -# https://django-allauth.readthedocs.io/en/latest/configuration.html +# https://docs.allauth.org/en/latest/account/configuration.html ACCOUNT_USERNAME_REQUIRED = False -# https://django-allauth.readthedocs.io/en/latest/configuration.html +# https://docs.allauth.org/en/latest/account/configuration.html ACCOUNT_USER_MODEL_USERNAME_FIELD = None {%- endif %} -# https://django-allauth.readthedocs.io/en/latest/configuration.html +# https://docs.allauth.org/en/latest/account/configuration.html ACCOUNT_EMAIL_VERIFICATION = "none" -# https://django-allauth.readthedocs.io/en/latest/configuration.html +# https://docs.allauth.org/en/latest/account/configuration.html ACCOUNT_ADAPTER = "{{dxh_py.project_slug}}.users.adapters.AccountAdapter" -# https://django-allauth.readthedocs.io/en/latest/forms.html +# https://docs.allauth.org/en/latest/account/forms.html ACCOUNT_FORMS = {"signup": "{{dxh_py.project_slug}}.users.forms.UserSignupForm"} -# https://django-allauth.readthedocs.io/en/latest/configuration.html +# https://docs.allauth.org/en/latest/socialaccount/configuration.html SOCIALACCOUNT_ADAPTER = "{{dxh_py.project_slug}}.users.adapters.SocialAccountAdapter" -# https://django-allauth.readthedocs.io/en/latest/forms.html +# https://docs.allauth.org/en/latest/socialaccount/configuration.html SOCIALACCOUNT_FORMS = {"signup": "{{dxh_py.project_slug}}.users.forms.UserSocialSignupForm"} {%- if dxh_py.frontend_pipeline == 'Django Compressor' %} # django-compressor @@ -508,6 +518,7 @@ "DESCRIPTION": "Documentation of API endpoints of {{ dxh_py.project_name }}", "VERSION": "1.0.0", "SERVE_PERMISSIONS": ["rest_framework.permissions.IsAdminUser"], + "SCHEMA_PATH_PREFIX": "/api/", } {%- endif %} @@ -523,7 +534,7 @@ "STATS_FILE": BASE_DIR / "webpack-stats.json", "POLL_INTERVAL": 0.1, "IGNORE": [r".+\.hot-update.js", r".+\.map"], - } + }, } {%- endif %} @@ -548,9 +559,11 @@ {%- endif %} +# Read the TRUSTED_CORS_ORIGINS from the environment variable +TRUSTED_CORS_ORIGINS = env.list("TRUSTED_CORS_ORIGINS", default=[]) + # django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup CORS_ALLOW_ALL_ORIGINS = True -TRUSTED_CORS_ORIGINS = env("TRUSTED_CORS_ORIGINS").split(',') CSRF_TRUSTED_ORIGINS = TRUSTED_CORS_ORIGINS CORS_ORIGIN_WHITELIST = TRUSTED_CORS_ORIGINS CORS_ALLOW_CREDENTIALS = True diff --git a/{{dxh_py.project_slug}}/config/settings/local.py b/{{dxh_py.project_slug}}/config/settings/local.py index ff481a2..57d23bd 100644 --- a/{{dxh_py.project_slug}}/config/settings/local.py +++ b/{{dxh_py.project_slug}}/config/settings/local.py @@ -1,4 +1,10 @@ -from .base import * # noqa +# ruff: noqa: E501 +from .base import * # noqa: F403 +from .base import INSTALLED_APPS +from .base import MIDDLEWARE +{%- if dxh_py.frontend_pipeline == 'Webpack' %} +from .base import WEBPACK_LOADER +{%- endif %} from .base import env # GENERAL @@ -7,11 +13,10 @@ DEBUG = True # https://docs.djangoproject.com/en/dev/ref/settings/#secret-key SECRET_KEY = env( - "DJANGO_SECRET_KEY", - default="!!!SET DJANGO_SECRET_KEY!!!", + "DJANGO_SECRET_KEY",default="!!!SET DJANGO_SECRET_KEY!!!" ) # https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts -ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1"] +ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1"] # noqa: S104 # CACHES # ------------------------------------------------------------------------------ @@ -20,7 +25,7 @@ "default": { "BACKEND": "django.core.cache.backends.locmem.LocMemCache", "LOCATION": "", - } + }, } # EMAIL @@ -37,14 +42,14 @@ EMAIL_PORT = 1025 {%- else %} # https://docs.djangoproject.com/en/dev/ref/settings/#email-backend -EMAIL_BACKEND = env("DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend") +EMAIL_BACKEND = env("DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.smtp.EmailBackend") -DEFAULT_FROM_EMAIL = env("DEFAULT_FROM_EMAIL") -EMAIL_HOST = env("EMAIL_HOST") -EMAIL_HOST_USER = env("EMAIL_HOST_USER") -EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD") -EMAIL_PORT = env("EMAIL_PORT") -EMAIL_USE_TLS = env("EMAIL_USE_TLS") +DEFAULT_FROM_EMAIL = env("DEFAULT_FROM_EMAIL", default="noreply@{{dxh_py.project_slug}}.com") +EMAIL_HOST = env("EMAIL_HOST", default="smtp.gmail.com") +EMAIL_HOST_USER = env("EMAIL_HOST_USER",default="noreply@{{dxh_py.project_slug}}.com") +EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD",default="your_mail_password") +EMAIL_PORT = env.int("EMAIL_PORT", default=587) +EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", default=True) {%- endif %} {%- if dxh_py.use_whitenoise == 'y' %} @@ -52,7 +57,7 @@ # WhiteNoise # ------------------------------------------------------------------------------ # http://whitenoise.evans.io/en/latest/django.html#using-whitenoise-in-development -INSTALLED_APPS = ["whitenoise.runserver_nostatic"] + INSTALLED_APPS # noqa: F405 +INSTALLED_APPS = ["whitenoise.runserver_nostatic", *INSTALLED_APPS] {%- endif %} # django-debug-toolbar @@ -63,7 +68,12 @@ MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"] # noqa: F405 # https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-config DEBUG_TOOLBAR_CONFIG = { - "DISABLE_PANELS": ["debug_toolbar.panels.redirects.RedirectsPanel"], + "DISABLE_PANELS": [ + "debug_toolbar.panels.redirects.RedirectsPanel", + # Disable profiling panel due to an issue with Python 3.12: + # https://github.com/jazzband/django-debug-toolbar/issues/1875 + "debug_toolbar.panels.profiling.ProfilingPanel", + ], "SHOW_TEMPLATE_CONTEXT": True, } # https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#internal-ips @@ -82,6 +92,15 @@ # The node container isn't started (yet?) pass {%- endif %} + {%- if dxh_py.windows == 'y' %} + # RunServerPlus + # ------------------------------------------------------------------------------ + # This is a custom setting for RunServerPlus to fix reloader issue in Windows docker environment + # Werkzeug reloader type [auto, watchdog, or stat] + RUNSERVERPLUS_POLLER_RELOADER_TYPE = 'stat' + # If you have CPU and IO load issues, you can increase this poller interval e.g) 5 + RUNSERVERPLUS_POLLER_RELOADER_INTERVAL = 1 + {%- endif %} {%- endif %} # django-extensions @@ -98,6 +117,7 @@ {%- endif %} # https://docs.celeryq.dev/en/stable/userguide/configuration.html#task-eager-propagates CELERY_TASK_EAGER_PROPAGATES = True + {%- endif %} {%- if dxh_py.frontend_pipeline == 'Webpack' %} diff --git a/{{dxh_py.project_slug}}/config/settings/production.py b/{{dxh_py.project_slug}}/config/settings/production.py index 0e9b79b..345fb62 100644 --- a/{{dxh_py.project_slug}}/config/settings/production.py +++ b/{{dxh_py.project_slug}}/config/settings/production.py @@ -1,19 +1,25 @@ -from .base import env -from sentry_sdk.integrations.redis import RedisIntegration -from sentry_sdk.integrations.logging import LoggingIntegration -from sentry_sdk.integrations.django import DjangoIntegration -from sentry_sdk.integrations.celery import CeleryIntegration -import sentry_sdk +# ruff: noqa: E501 +{% if dxh_py.use_sentry == 'y' -%} import logging -{%-if dxh_py.use_sentry == 'y' %} +import sentry_sdk {%- if dxh_py.use_celery == 'y' %} +from sentry_sdk.integrations.celery import CeleryIntegration {%- endif %} +from sentry_sdk.integrations.django import DjangoIntegration +from sentry_sdk.integrations.logging import LoggingIntegration +from sentry_sdk.integrations.redis import RedisIntegration -{%-endif %} -from .base import * # noqa +{% endif -%} +from .base import * # noqa: F403 +from .base import DATABASES +from .base import INSTALLED_APPS +{%- if dxh_py.use_drf == "y" %} +from .base import SPECTACULAR_SETTINGS +{%- endif %} +from .base import env # GENERAL # ------------------------------------------------------------------------------ @@ -24,7 +30,7 @@ # DATABASES # ------------------------------------------------------------------------------ -DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60) # noqa: F405 +DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60) # CACHES # ------------------------------------------------------------------------------ @@ -38,7 +44,7 @@ # https://github.com/jazzband/django-redis#memcached-exceptions-behavior "IGNORE_EXCEPTIONS": True, }, - } + }, } # SECURITY @@ -49,8 +55,12 @@ SECURE_SSL_REDIRECT = env.bool("DJANGO_SECURE_SSL_REDIRECT", default=True) # https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure SESSION_COOKIE_SECURE = True +# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-name +SESSION_COOKIE_NAME = "__Secure-sessionid" # https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure CSRF_COOKIE_SECURE = True +# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-name +CSRF_COOKIE_NAME = "__Secure-csrftoken" # https://docs.djangoproject.com/en/dev/topics/security/#ssl-https # https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-seconds # TODO: set this to 60 seconds first and then to 518400 once you prove the former works @@ -105,33 +115,97 @@ {%- if dxh_py.cloud_provider != 'None' or dxh_py.use_whitenoise == 'y' %} # STATIC # ------------------------ -{%- endif %} -{%- if dxh_py.use_whitenoise == 'y' %} -STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" +STORAGES = { +{%- if dxh_py.use_whitenoise == 'y' and dxh_py.cloud_provider == 'None' %} + "default": { + "BACKEND": "django.core.files.storage.FileSystemStorage", + }, + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + }, {%- elif dxh_py.cloud_provider == 'AWS' %} -STATICFILES_STORAGE = "{{dxh_py.project_slug}}.utils.storages.StaticRootS3Boto3Storage" -COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy" -STATIC_URL = f"https://{aws_s3_domain}/static/" + "default": { + "BACKEND": "storages.backends.s3.S3Storage", + "OPTIONS": { + "location": "media", + "file_overwrite": False, + }, + }, + {%- if dxh_py.use_whitenoise == 'y' %} + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + }, + {%- else %} + "staticfiles": { + "BACKEND": "storages.backends.s3.S3Storage", + "OPTIONS": { + "location": "static", + "default_acl": "public-read", + }, + }, + {%- endif %} {%- elif dxh_py.cloud_provider == 'GCP' %} -STATICFILES_STORAGE = "{{dxh_py.project_slug}}.utils.storages.StaticRootGoogleCloudStorage" -COLLECTFAST_STRATEGY = "collectfast.strategies.gcloud.GoogleCloudStrategy" -STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/" + "default": { + "BACKEND": "storages.backends.gcloud.GoogleCloudStorage", + "OPTIONS": { + "location": "media", + "file_overwrite": False, + }, + }, + {%- if dxh_py.use_whitenoise == 'y' %} + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + }, + {%- else %} + "staticfiles": { + "BACKEND": "storages.backends.gcloud.GoogleCloudStorage", + "OPTIONS": { + "location": "static", + "default_acl": "publicRead", + }, + }, + {%- endif %} {%- elif dxh_py.cloud_provider == 'Azure' %} -STATICFILES_STORAGE = "{{dxh_py.project_slug}}.utils.storages.StaticRootAzureStorage" -STATIC_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/static/" + "default": { + "BACKEND": "storages.backends.azure_storage.AzureStorage", + "OPTIONS": { + "location": "media", + "file_overwrite": False, + }, + }, + {%- if dxh_py.use_whitenoise == 'y' %} + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + }, + {%- else %} + "staticfiles": { + "BACKEND": "storages.backends.azure_storage.AzureStorage", + "OPTIONS": { + "location": "static", + }, + }, + {%- endif %} +{%- endif %} +} {%- endif %} -# MEDIA -# ------------------------------------------------------------------------------ {%- if dxh_py.cloud_provider == 'AWS' %} -DEFAULT_FILE_STORAGE = "{{dxh_py.project_slug}}.utils.storages.MediaRootS3Boto3Storage" MEDIA_URL = f"https://{aws_s3_domain}/media/" +{%- if dxh_py.use_whitenoise == 'n' %} +COLLECTFASTA_STRATEGY = "collectfasta.strategies.boto3.Boto3Strategy" +STATIC_URL = f"https://{aws_s3_domain}/static/" +{%- endif %} {%- elif dxh_py.cloud_provider == 'GCP' %} -DEFAULT_FILE_STORAGE = "{{dxh_py.project_slug}}.utils.storages.MediaRootGoogleCloudStorage" MEDIA_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/media/" +{%- if dxh_py.use_whitenoise == 'n' %} +COLLECTFASTA_STRATEGY = "collectfasta.strategies.gcloud.GoogleCloudStrategy" +STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/" +{%- endif %} {%- elif dxh_py.cloud_provider == 'Azure' %} -DEFAULT_FILE_STORAGE = "{{dxh_py.project_slug}}.utils.storages.MediaRootAzureStorage" MEDIA_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/media/" +{%- if dxh_py.use_whitenoise == 'n' %} +STATIC_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/static/" +{%- endif %} {%- endif %} # EMAIL @@ -200,12 +274,12 @@ "SENDGRID_API_KEY": env("SENDGRID_API_KEY"), "SENDGRID_API_URL": env("SENDGRID_API_URL", default="https://api.sendgrid.com/v3/"), } -{%- elif dxh_py.mail_service == 'SendinBlue' %} -# https://anymail.readthedocs.io/en/stable/esps/sendinblue/ -EMAIL_BACKEND = "anymail.backends.sendinblue.EmailBackend" +{%- elif dxh_py.mail_service == 'Brevo' %} +# https://anymail.readthedocs.io/en/stable/esps/brevo/ +EMAIL_BACKEND = "anymail.backends.brevo.EmailBackend" ANYMAIL = { - "SENDINBLUE_API_KEY": env("SENDINBLUE_API_KEY"), - "SENDINBLUE_API_URL": env("SENDINBLUE_API_URL", default="https://api.sendinblue.com/v3/"), + "BREVO_API_KEY": env("BREVO_API_KEY"), + "BREVO_API_URL": env("BREVO_API_URL", default="https://api.brevo.com/v3/"), } {%- elif dxh_py.mail_service == 'SparkPost' %} # https://anymail.readthedocs.io/en/stable/esps/sparkpost/ @@ -230,10 +304,11 @@ COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage" {%- elif dxh_py.cloud_provider in ('AWS', 'GCP', 'Azure') and dxh_py.use_whitenoise == 'n' %} # https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE -COMPRESS_STORAGE = STATICFILES_STORAGE +COMPRESS_STORAGE = STORAGES["staticfiles"]["BACKEND"] {%- endif %} # https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL -COMPRESS_URL = STATIC_URL{%-if dxh_py.use_whitenoise == 'y' or dxh_py.cloud_provider == 'None' %} # noqa: F405{%-endif %} +COMPRESS_URL = STATIC_URL{%-if dxh_py.use_whitenoise == 'y' or dxh_py.cloud_provider == 'None' %} # noqa: F405 +{%- endif %} {%- if dxh_py.use_whitenoise == 'y' %} # https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE COMPRESS_OFFLINE = True # Offline compression is required when using Whitenoise @@ -248,10 +323,10 @@ } {%- endif %} {%- if dxh_py.use_whitenoise == 'n' %} -# Collectfast +# Collectfasta # ------------------------------------------------------------------------------ -# https://github.com/antonagestam/collectfast#installation -INSTALLED_APPS = ["collectfast"] + INSTALLED_APPS # noqa: F405 +# https://github.com/jasongi/collectfasta#installation +INSTALLED_APPS = ["collectfasta", *INSTALLED_APPS] {%- endif %} # LOGGING # ------------------------------------------------------------------------------ @@ -311,7 +386,7 @@ "level": "DEBUG", "class": "logging.StreamHandler", "formatter": "verbose", - } + }, }, "root": {"level": "INFO", "handlers": ["console"]}, "loggers": { diff --git a/{{dxh_py.project_slug}}/config/settings/test.py b/{{dxh_py.project_slug}}/config/settings/test.py index 05b11ad..ec0ce7a 100644 --- a/{{dxh_py.project_slug}}/config/settings/test.py +++ b/{{dxh_py.project_slug}}/config/settings/test.py @@ -2,7 +2,8 @@ With these settings, tests run faster. """ -from .base import * # noqa +from .base import * # noqa: F403 +from .base import TEMPLATES from .base import env # GENERAL @@ -27,12 +28,17 @@ # DEBUGGING FOR TEMPLATES # ------------------------------------------------------------------------------ -TEMPLATES[0]["OPTIONS"]["debug"] = True # type: ignore # noqa: F405 +TEMPLATES[0]["OPTIONS"]["debug"] = True # type: ignore[index] + +# MEDIA +# ------------------------------------------------------------------------------ +# https://docs.djangoproject.com/en/dev/ref/settings/#media-url +MEDIA_URL = "http://media.testserver" {%- if dxh_py.frontend_pipeline == 'Webpack' %} # django-webpack-loader # ------------------------------------------------------------------------------ -WEBPACK_LOADER["DEFAULT"]["LOADER_CLASS"] = "webpack_loader.loader.FakeWebpackLoader" # noqa: F405 +WEBPACK_LOADER["DEFAULT"]["LOADER_CLASS"] = "webpack_loader.loaders.FakeWebpackLoader" # noqa: F405 {%- endif %} # Your stuff... diff --git a/{{dxh_py.project_slug}}/docs.yml b/{{dxh_py.project_slug}}/docs.yml new file mode 100644 index 0000000..6265e0e --- /dev/null +++ b/{{dxh_py.project_slug}}/docs.yml @@ -0,0 +1,16 @@ +services: + docs: + image: {{ dxh_py.project_slug }}_local_docs + container_name: {{ dxh_py.project_slug }}_local_docs + build: + context: . + dockerfile: ./compose/local/docs/Dockerfile + env_file: + - ./.envs/.local/.django + volumes: + - ./docs:/docs:z + - ./config:/app/config:z + - ./{{ dxh_py.project_slug }}:/app/{{ dxh_py.project_slug }}:z + ports: + - '9000:9000' + command: /start-docs \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/docs/conf.py b/{{dxh_py.project_slug}}/docs/conf.py index 1d9aacc..00be7ca 100644 --- a/{{dxh_py.project_slug}}/docs/conf.py +++ b/{{dxh_py.project_slug}}/docs/conf.py @@ -1,3 +1,4 @@ +# ruff: noqa # Configuration file for the Sphinx documentation builder. # # This file only contains a selection of the most common options. For a full diff --git a/{{dxh_py.project_slug}}/docs/howto.rst b/{{dxh_py.project_slug}}/docs/howto.rst index c8c5e40..f85f79f 100644 --- a/{{dxh_py.project_slug}}/docs/howto.rst +++ b/{{dxh_py.project_slug}}/docs/howto.rst @@ -15,7 +15,7 @@ from inside the `{{dxh_py.project_slug}}/docs` directory. {% else %} To build and serve docs, use the commands:: - docker-compose -f local.yml up docs + docker-compose -f docs.yml up {% endif %} @@ -34,12 +34,12 @@ For an in-use example, see the `page source <_sources/users.rst.txt>`_ for :ref: To compile all docstrings automatically into documentation source files, use the command: :: - + make apidocs {% if dxh_py.use_docker == 'y' %} This can be done in the docker container: - :: - + :: + docker run --rm docs make apidocs {% endif -%} diff --git a/{{dxh_py.project_slug}}/gulpfile.js b/{{dxh_py.project_slug}}/gulpfile.js index 08fd40f..714b7d1 100644 --- a/{{dxh_py.project_slug}}/gulpfile.js +++ b/{{dxh_py.project_slug}}/gulpfile.js @@ -106,7 +106,7 @@ function imgCompression() { function asyncRunServer() { const cmd = spawn( 'gunicorn', - ['config.asgi', '-k', 'uvicorn.workers.UvicornWorker', '--reload'], + ['config.asgi', '-k', 'uvicorn_worker.UvicornWorker', '--reload'], {stdio: 'inherit'}, ); cmd.on('close', function (code) { diff --git a/{{dxh_py.project_slug}}/local.yml b/{{dxh_py.project_slug}}/local.yml index 66ed291..857b8b0 100644 --- a/{{dxh_py.project_slug}}/local.yml +++ b/{{dxh_py.project_slug}}/local.yml @@ -1,5 +1,3 @@ -version: '3' - volumes: {%- if dxh_py.database_engine == 'postgresql' %} {{ dxh_py.project_slug }}_local_postgres_data: {} @@ -10,6 +8,7 @@ volumes: {{ dxh_py.project_slug }}_local_mysql_data: {} {{ dxh_py.project_slug }}_local_mysql_data_backups: {} {%- endif %} + {% if dxh_py.use_celery == 'y' %}{{ dxh_py.project_slug }}_local_redis_data: {}{% endif %} services: django:{% if dxh_py.use_celery == 'y' %} &django{% endif %} @@ -94,24 +93,7 @@ services: ports: - '3406:3306' {%- endif %} - - docs: - image: {{ dxh_py.project_slug }}_local_docs - container_name: {{ dxh_py.project_slug }}_local_docs - build: - context: . - dockerfile: ./compose/local/docs/Dockerfile - env_file: - - ./.envs/.local/.django - volumes: - - ./docs:/docs:z - - ./config:/app/config:z - - ./{{ dxh_py.project_slug }}:/app/{{ dxh_py.project_slug }}:z - ports: - - '9000:9000' - command: /start-docs - {%- if dxh_py.use_mailhog == 'y' %} - + {%- if dxh_py.use_mailhog == 'y' %} mailhog: image: mailhog/mailhog:v1.0.0 container_name: {{ dxh_py.project_slug }}_local_mailhog @@ -122,8 +104,12 @@ services: {%- if dxh_py.use_celery == 'y' %} redis: - image: redis:6 + image: docker.io/redis:6 container_name: {{ dxh_py.project_slug }}_local_redis + {% if dxh_py.use_celery == 'y' %} + volumes: + - {{ dxh_py.project_slug }}_local_redis_data:/data + {% endif %} celeryworker: <<: *django @@ -165,7 +151,6 @@ services: - selenium {%- endif %} ports: [] - ports: [] command: /start-celerybeat flower: @@ -206,4 +191,4 @@ services: container_name: {{ dxh_py.project_slug }}_local_selenium ports: - '4444:4444' - {%- endif %} + {%- endif %} \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/locale/README.rst b/{{dxh_py.project_slug}}/locale/README.rst index c2f1dcd..21b6354 100644 --- a/{{dxh_py.project_slug}}/locale/README.rst +++ b/{{dxh_py.project_slug}}/locale/README.rst @@ -1,6 +1,32 @@ -Translations -============ +# Translations -Translations will be placed in this folder when running:: +Start by configuring the `LANGUAGES` settings in `base.py`, by uncommenting languages you are willing to support. Then, translations strings will be placed in this folder when running: - python manage.py makemessages +```bash +{% if dxh_py.use_docker == 'y' %}docker compose -f local.yml run --rm django {% endif %}python manage.py makemessages --all --no-location +``` + +This should generate `django.po` (stands for Portable Object) files under each locale `/LC_MESSAGES/django.po`. Each translatable string in the codebase is collected with its `msgid` and need to be translated as `msgstr`, for example: + +```po +msgid "users" +msgstr "utilisateurs" +``` + +Once all translations are done, they need to be compiled into `.mo` files (stands for Machine Object), which are the actual binary files used by the application: + +```bash +{% if dxh_py.use_docker == 'y' %}docker compose -f local.yml run --rm django {% endif %}python manage.py compilemessages +``` + +Note that the `.po` files are NOT used by the application directly, so if the `.mo` files are out of dates, the content won't appear as translated even if the `.po` files are up-to-date. + +## Production + +The production image runs `compilemessages` automatically at build time, so as long as your translated source files (PO) are up-to-date, you're good to go. + +## Add a new language + +1. Update the [`LANGUAGES` setting](https://docs.djangoproject.com/en/stable/ref/settings/#std-setting-LANGUAGES) to your project's base settings. +2. Create the locale folder for the language next to this file, e.g. `fr_FR` for French. Make sure the case is correct. +3. Run `makemessages` (as instructed above) to generate the PO files for the new language. \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/locale/en_US/LC_MESSAGES/django.po b/{{dxh_py.project_slug}}/locale/en_US/LC_MESSAGES/django.po new file mode 100644 index 0000000..4400847 --- /dev/null +++ b/{{dxh_py.project_slug}}/locale/en_US/LC_MESSAGES/django.po @@ -0,0 +1,12 @@ +# Translations for the {{ dxh_py.project_name }} project +# Copyright (C) {% now 'utc', '%Y' %} {{ dxh_py.author_name }} +# {{ dxh_py.author_name }} <{{ dxh_py.email }}>, {% now 'utc', '%Y' %}. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: {{ dxh_py.version }}\n" +"Language: en-US\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/locale/fr_FR/LC_MESSAGES/django.po b/{{dxh_py.project_slug}}/locale/fr_FR/LC_MESSAGES/django.po new file mode 100644 index 0000000..236a00d --- /dev/null +++ b/{{dxh_py.project_slug}}/locale/fr_FR/LC_MESSAGES/django.po @@ -0,0 +1,335 @@ +# Translations for the {{ dxh_py.project_name }} project +# Copyright (C) {% now 'utc', '%Y' %} {{ dxh_py.author_name }} +# {{ dxh_py.author_name }} <{{ dxh_py.email }}>, {% now 'utc', '%Y' %}. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: {{ dxh_py.version }}\n" +"Language: fr-FR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" +#: {{dxh_py.project_slug}}/templates/account/account_inactive.html:5 +#: {{dxh_py.project_slug}}/templates/account/account_inactive.html:8 +msgid "Account Inactive" +msgstr "Compte inactif" + +#: {{dxh_py.project_slug}}/templates/account/account_inactive.html:10 +msgid "This account is inactive." +msgstr "Ce compte est inactif." + +#: {{dxh_py.project_slug}}/templates/account/email.html:7 +msgid "Account" +msgstr "Compte" + +#: {{dxh_py.project_slug}}/templates/account/email.html:10 +msgid "E-mail Addresses" +msgstr "Adresses e-mail" + +#: {{dxh_py.project_slug}}/templates/account/email.html:13 +msgid "The following e-mail addresses are associated with your account:" +msgstr "Les adresses e-mail suivantes sont associées à votre compte :" + +#: {{dxh_py.project_slug}}/templates/account/email.html:27 +msgid "Verified" +msgstr "Vérifié" + +#: {{dxh_py.project_slug}}/templates/account/email.html:29 +msgid "Unverified" +msgstr "Non vérifié" + +#: {{dxh_py.project_slug}}/templates/account/email.html:31 +msgid "Primary" +msgstr "Primaire" + +#: {{dxh_py.project_slug}}/templates/account/email.html:37 +msgid "Make Primary" +msgstr "Changer Primaire" + +#: {{dxh_py.project_slug}}/templates/account/email.html:38 +msgid "Re-send Verification" +msgstr "Renvoyer vérification" + +#: {{dxh_py.project_slug}}/templates/account/email.html:39 +msgid "Remove" +msgstr "Supprimer" + +#: {{dxh_py.project_slug}}/templates/account/email.html:46 +msgid "Warning:" +msgstr "Avertissement:" + +#: {{dxh_py.project_slug}}/templates/account/email.html:46 +msgid "" +"You currently do not have any e-mail address set up. You should really add " +"an e-mail address so you can receive notifications, reset your password, etc." +msgstr "" +"Vous n'avez actuellement aucune adresse e-mail configurée. Vous devriez ajouter " +"une adresse e-mail pour reçevoir des notifications, réinitialiser votre mot " +"de passe, etc." + +#: {{dxh_py.project_slug}}/templates/account/email.html:51 +msgid "Add E-mail Address" +msgstr "Ajouter une adresse e-mail" + +#: {{dxh_py.project_slug}}/templates/account/email.html:56 +msgid "Add E-mail" +msgstr "Ajouter e-mail" + +#: {{dxh_py.project_slug}}/templates/account/email.html:66 +msgid "Do you really want to remove the selected e-mail address?" +msgstr "Voulez-vous vraiment supprimer l'adresse e-mail sélectionnée ?" + +#: {{dxh_py.project_slug}}/templates/account/email_confirm.html:6 +#: {{dxh_py.project_slug}}/templates/account/email_confirm.html:10 +msgid "Confirm E-mail Address" +msgstr "Confirmez votre adresse email" + +#: {{dxh_py.project_slug}}/templates/account/email_confirm.html:16 +#, python-format +msgid "" +"Please confirm that %(email)s is an e-mail " +"address for user %(user_display)s." +msgstr "" +"Veuillez confirmer que %(email)s est un e-mail " +"adresse de l'utilisateur %(user_display)s." + +#: {{dxh_py.project_slug}}/templates/account/email_confirm.html:20 +msgid "Confirm" +msgstr "Confirm" + +#: {{dxh_py.project_slug}}/templates/account/email_confirm.html:27 +#, python-format +msgid "" +"This e-mail confirmation link expired or is invalid. Please issue a new e-mail confirmation request." +msgstr "" +"Ce lien de confirmation par e-mail a expiré ou n'est pas valide. Veuillez" + "émettre une nouvelle demande de confirmation " +"par e-mail." + +#: {{dxh_py.project_slug}}/templates/account/login.html:7 +#: {{dxh_py.project_slug}}/templates/account/login.html:11 +#: {{dxh_py.project_slug}}/templates/account/login.html:56 +#: {{dxh_py.project_slug}}/templates/base.html:72 +msgid "Sign In" +msgstr "S'identifier" + +#: {{dxh_py.project_slug}}/templates/account/login.html:17 +msgid "Please sign in with one of your existing third party accounts:" +msgstr "Veuillez vous connecter avec l'un de vos comptes tiers existants :" + +#: {{dxh_py.project_slug}}/templates/account/login.html:19 +#, python-format +msgid "" +"Or, sign up for a %(site_name)s account and " +"sign in below:" +msgstr "" +"Ou, créez un compte %(site_name)s et " +"connectez-vous ci-dessous :" + +#: {{dxh_py.project_slug}}/templates/account/login.html:32 +msgid "or" +msgstr "ou" + +#: {{dxh_py.project_slug}}/templates/account/login.html:41 +#, python-format +msgid "" +"If you have not created an account yet, then please sign up first." +msgstr "" +"Si vous n'avez pas encore créé de compte, veuillez d'abord vous inscrire." + +#: {{dxh_py.project_slug}}/templates/account/login.html:55 +msgid "Forgot Password?" +msgstr "Mot de passe oublié?" + +#: {{dxh_py.project_slug}}/templates/account/logout.html:5 +#: {{dxh_py.project_slug}}/templates/account/logout.html:8 +#: {{dxh_py.project_slug}}/templates/account/logout.html:17 +#: {{dxh_py.project_slug}}/templates/base.html:61 +msgid "Sign Out" +msgstr "Se déconnecter" + +#: {{dxh_py.project_slug}}/templates/account/logout.html:10 +msgid "Are you sure you want to sign out?" +msgstr "Êtes-vous certain de vouloir vous déconnecter?" + +#: {{dxh_py.project_slug}}/templates/account/password_change.html:6 +#: {{dxh_py.project_slug}}/templates/account/password_change.html:9 +#: {{dxh_py.project_slug}}/templates/account/password_change.html:14 +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:5 +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:8 +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key_done.html:4 +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key_done.html:7 +msgid "Change Password" +msgstr "Changer le mot de passe" + +#: {{dxh_py.project_slug}}/templates/account/password_reset.html:7 +#: {{dxh_py.project_slug}}/templates/account/password_reset.html:11 +#: {{dxh_py.project_slug}}/templates/account/password_reset_done.html:6 +#: {{dxh_py.project_slug}}/templates/account/password_reset_done.html:9 +msgid "Password Reset" +msgstr "Réinitialisation du mot de passe" + +#: {{dxh_py.project_slug}}/templates/account/password_reset.html:16 +msgid "" +"Forgotten your password? Enter your e-mail address below, and we'll send you " +"an e-mail allowing you to reset it." +msgstr "" +"Mot de passe oublié? Entrez votre adresse e-mail ci-dessous, et nous vous " +"enverrons un e-mail vous permettant de le réinitialiser." + +#: {{dxh_py.project_slug}}/templates/account/password_reset.html:21 +msgid "Reset My Password" +msgstr "Réinitialiser mon mot de passe" + +#: {{dxh_py.project_slug}}/templates/account/password_reset.html:24 +msgid "Please contact us if you have any trouble resetting your password." +msgstr "" +"Veuillez nous contacter si vous rencontrez des difficultés pour réinitialiser" +"votre mot de passe." + +#: {{dxh_py.project_slug}}/templates/account/password_reset_done.html:15 +msgid "" +"We have sent you an e-mail. Please contact us if you do not receive it " +"within a few minutes." +msgstr "" +"Nous vous avons envoyé un e-mail. Veuillez nous contacter si vous ne le " +"recevez pas d'ici quelques minutes." + +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:8 +msgid "Bad Token" +msgstr "Token Invalide" + +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:12 +#, python-format +msgid "" +"The password reset link was invalid, possibly because it has already been " +"used. Please request a new password reset." +msgstr "" +"Le lien de réinitialisation du mot de passe n'était pas valide, peut-être parce " +"qu'il a déjà été utilisé. Veuillez faire une " +"nouvelle demande de réinitialisation de mot de passe." + +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:18 +msgid "change password" +msgstr "changer le mot de passe" + +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:21 +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key_done.html:8 +msgid "Your password is now changed." +msgstr "Votre mot de passe est maintenant modifié." + +#: {{dxh_py.project_slug}}/templates/account/password_set.html:6 +#: {{dxh_py.project_slug}}/templates/account/password_set.html:9 +#: {{dxh_py.project_slug}}/templates/account/password_set.html:14 +msgid "Set Password" +msgstr "Définir le mot de passe" + +#: {{dxh_py.project_slug}}/templates/account/signup.html:6 +msgid "Signup" +msgstr "S'inscrire" + +#: {{dxh_py.project_slug}}/templates/account/signup.html:9 +#: {{dxh_py.project_slug}}/templates/account/signup.html:19 +#: {{dxh_py.project_slug}}/templates/base.html:67 +msgid "Sign Up" +msgstr "S'inscrire" + +#: {{dxh_py.project_slug}}/templates/account/signup.html:11 +#, python-format +msgid "" +"Already have an account? Then please sign in." +msgstr "" +"Vous avez déjà un compte? Alors veuillez vous connecter." + +#: {{dxh_py.project_slug}}/templates/account/signup_closed.html:5 +#: {{dxh_py.project_slug}}/templates/account/signup_closed.html:8 +msgid "Sign Up Closed" +msgstr "Inscriptions closes" + +#: {{dxh_py.project_slug}}/templates/account/signup_closed.html:10 +msgid "We are sorry, but the sign up is currently closed." +msgstr "Désolé, mais l'inscription est actuellement fermée." + +#: {{dxh_py.project_slug}}/templates/account/verification_sent.html:5 +#: {{dxh_py.project_slug}}/templates/account/verification_sent.html:8 +#: {{dxh_py.project_slug}}/templates/account/verified_email_required.html:5 +#: {{dxh_py.project_slug}}/templates/account/verified_email_required.html:8 +msgid "Verify Your E-mail Address" +msgstr "Vérifiez votre adresse e-mail" + +#: {{dxh_py.project_slug}}/templates/account/verification_sent.html:10 +msgid "" +"We have sent an e-mail to you for verification. Follow the link provided to " +"finalize the signup process. Please contact us if you do not receive it " +"within a few minutes." +msgstr "Nous vous avons envoyé un e-mail pour vérification. Suivez le lien fourni " +"pour finalisez le processus d'inscription. Veuillez nous contacter si vous ne le " +"recevez pas d'ici quelques minutes." + +#: {{dxh_py.project_slug}}/templates/account/verified_email_required.html:12 +msgid "" +"This part of the site requires us to verify that\n" +"you are who you claim to be. For this purpose, we require that you\n" +"verify ownership of your e-mail address. " +msgstr "" +"Cette partie du site nous oblige à vérifier que\n" +"vous êtes qui vous prétendez être. Nous vous demandons donc de\n" +"vérifier la propriété de votre adresse e-mail." + +#: {{dxh_py.project_slug}}/templates/account/verified_email_required.html:16 +msgid "" +"We have sent an e-mail to you for\n" +"verification. Please click on the link inside this e-mail. Please\n" +"contact us if you do not receive it within a few minutes." +msgstr "" +"Nous vous avons envoyé un e-mail pour\n" +"vérification. Veuillez cliquer sur le lien contenu dans cet e-mail. Veuillez nous\n" +"contacter si vous ne le recevez pas d'ici quelques minutes." + +#: {{dxh_py.project_slug}}/templates/account/verified_email_required.html:20 +#, python-format +msgid "" +"Note: you can still change your e-" +"mail address." +msgstr "" +"Remarque : vous pouvez toujours changer votre e-" +"adresse e-mail." + +#: {{dxh_py.project_slug}}/templates/base.html:57 +msgid "My Profile" +msgstr "Mon Profil" + +#: {{dxh_py.project_slug}}/users/admin.py:17 +msgid "Personal info" +msgstr "Personal info" + +#: {{dxh_py.project_slug}}/users/admin.py:19 +msgid "Permissions" +msgstr "Permissions" + +#: {{dxh_py.project_slug}}/users/admin.py:30 +msgid "Important dates" +msgstr "Dates importantes" + +#: {{dxh_py.project_slug}}/users/apps.py:7 +msgid "Users" +msgstr "Utilisateurs" + +#: {{dxh_py.project_slug}}/users/forms.py:24 +#: {{dxh_py.project_slug}}/users/tests/test_forms.py:36 +msgid "This username has already been taken." +msgstr "Ce nom d'utilisateur est déjà pris." + +#: {{dxh_py.project_slug}}/users/models.py:15 +msgid "Name of User" +msgstr "Nom de l'utilisateur" + +#: {{dxh_py.project_slug}}/users/views.py:23 +msgid "Information successfully updated" +msgstr "Informations mises à jour avec succès" \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/locale/pt_BR/LC_MESSAGES/django.po b/{{dxh_py.project_slug}}/locale/pt_BR/LC_MESSAGES/django.po new file mode 100644 index 0000000..c3c1804 --- /dev/null +++ b/{{dxh_py.project_slug}}/locale/pt_BR/LC_MESSAGES/django.po @@ -0,0 +1,315 @@ +# Translations for the {{ dxh_py.project_name }} project +# Copyright (C) {% now 'utc', '%Y' %} {{ dxh_py.author_name }} +# {{ dxh_py.author_name }} <{{ dxh_py.email }}>, {% now 'utc', '%Y' %}. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: {{ dxh_py.version }}\n" +"Language: pt-BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" +#: {{dxh_py.project_slug}}/templates/account/account_inactive.html:5 +#: {{dxh_py.project_slug}}/templates/account/account_inactive.html:8 +msgid "Account Inactive" +msgstr "Conta Inativa" + +#: {{dxh_py.project_slug}}/templates/account/account_inactive.html:10 +msgid "This account is inactive." +msgstr "Esta conta está inativa." + +#: {{dxh_py.project_slug}}/templates/account/email.html:7 +msgid "Account" +msgstr "Conta" + +#: {{dxh_py.project_slug}}/templates/account/email.html:10 +msgid "E-mail Addresses" +msgstr "Endereços de E-mail" + +#: {{dxh_py.project_slug}}/templates/account/email.html:13 +msgid "The following e-mail addresses are associated with your account:" +msgstr "Os seguintes endereços de e-mail estão associados à sua conta:" + +#: {{dxh_py.project_slug}}/templates/account/email.html:27 +msgid "Verified" +msgstr "Verificado" + +#: {{dxh_py.project_slug}}/templates/account/email.html:29 +msgid "Unverified" +msgstr "Não verificado" + +#: {{dxh_py.project_slug}}/templates/account/email.html:31 +msgid "Primary" +msgstr "Primário" + +#: {{dxh_py.project_slug}}/templates/account/email.html:37 +msgid "Make Primary" +msgstr "Tornar Primário" + +#: {{dxh_py.project_slug}}/templates/account/email.html:38 +msgid "Re-send Verification" +msgstr "Reenviar verificação" + +#: {{dxh_py.project_slug}}/templates/account/email.html:39 +msgid "Remove" +msgstr "Remover" + +#: {{dxh_py.project_slug}}/templates/account/email.html:46 +msgid "Warning:" +msgstr "Aviso:" + +#: {{dxh_py.project_slug}}/templates/account/email.html:46 +msgid "" +"You currently do not have any e-mail address set up. You should really add " +"an e-mail address so you can receive notifications, reset your password, etc." +msgstr "" +"No momento, você não tem nenhum endereço de e-mail configurado. Você " +"realmente deve adicionar um endereço de e-mail para receber notificações, " +"redefinir sua senha etc." + +#: {{dxh_py.project_slug}}/templates/account/email.html:51 +msgid "Add E-mail Address" +msgstr "Adicionar Endereço de E-mail" + +#: {{dxh_py.project_slug}}/templates/account/email.html:56 +msgid "Add E-mail" +msgstr "Adicionar E-mail" + +#: {{dxh_py.project_slug}}/templates/account/email.html:66 +msgid "Do you really want to remove the selected e-mail address?" +msgstr "Você realmente deseja remover o endereço de e-mail selecionado?" + +#: {{dxh_py.project_slug}}/templates/account/email_confirm.html:6 +#: {{dxh_py.project_slug}}/templates/account/email_confirm.html:10 +msgid "Confirm E-mail Address" +msgstr "Confirme o endereço de e-mail" + +#: {{dxh_py.project_slug}}/templates/account/email_confirm.html:16 +#, python-format +msgid "" +"Please confirm that %(email)s is an e-mail " +"address for user %(user_display)s." +msgstr "" +"Confirme se %(email)s é um endereço de " +"e-mail do usuário %(user_display)s." + +#: {{dxh_py.project_slug}}/templates/account/email_confirm.html:20 +msgid "Confirm" +msgstr "Confirmar" + +#: {{dxh_py.project_slug}}/templates/account/email_confirm.html:27 +#, python-format +msgid "" +"This e-mail confirmation link expired or is invalid. Please issue a new e-mail confirmation request." +msgstr "Este link de confirmação de e-mail expirou ou é inválido. " +"Por favor, emita um novo pedido de confirmação por e-mail." + +#: {{dxh_py.project_slug}}/templates/account/login.html:7 +#: {{dxh_py.project_slug}}/templates/account/login.html:11 +#: {{dxh_py.project_slug}}/templates/account/login.html:56 +#: {{dxh_py.project_slug}}/templates/base.html:72 +msgid "Sign In" +msgstr "Entrar" + +#: {{dxh_py.project_slug}}/templates/account/login.html:17 +msgid "Please sign in with one of your existing third party accounts:" +msgstr "Faça login com uma de suas contas de terceiros existentes:" + +#: {{dxh_py.project_slug}}/templates/account/login.html:19 +#, python-format +msgid "" +"Or, sign up for a %(site_name)s account and " +"sign in below:" +msgstr "Ou, cadastre-se para uma conta em %(site_name)s e entre abaixo:" + +#: {{dxh_py.project_slug}}/templates/account/login.html:32 +msgid "or" +msgstr "ou" + +#: {{dxh_py.project_slug}}/templates/account/login.html:41 +#, python-format +msgid "" +"If you have not created an account yet, then please sign up first." +msgstr "Se você ainda não criou uma conta, registre-se primeiro." + +#: {{dxh_py.project_slug}}/templates/account/login.html:55 +msgid "Forgot Password?" +msgstr "Esqueceu sua senha?" + +#: {{dxh_py.project_slug}}/templates/account/logout.html:5 +#: {{dxh_py.project_slug}}/templates/account/logout.html:8 +#: {{dxh_py.project_slug}}/templates/account/logout.html:17 +#: {{dxh_py.project_slug}}/templates/base.html:61 +msgid "Sign Out" +msgstr "Sair" + +#: {{dxh_py.project_slug}}/templates/account/logout.html:10 +msgid "Are you sure you want to sign out?" +msgstr "Você tem certeza que deseja sair?" + +#: {{dxh_py.project_slug}}/templates/account/password_change.html:6 +#: {{dxh_py.project_slug}}/templates/account/password_change.html:9 +#: {{dxh_py.project_slug}}/templates/account/password_change.html:14 +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:5 +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:8 +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key_done.html:4 +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key_done.html:7 +msgid "Change Password" +msgstr "Alterar Senha" + +#: {{dxh_py.project_slug}}/templates/account/password_reset.html:7 +#: {{dxh_py.project_slug}}/templates/account/password_reset.html:11 +#: {{dxh_py.project_slug}}/templates/account/password_reset_done.html:6 +#: {{dxh_py.project_slug}}/templates/account/password_reset_done.html:9 +msgid "Password Reset" +msgstr "Redefinição de senha" + +#: {{dxh_py.project_slug}}/templates/account/password_reset.html:16 +msgid "" +"Forgotten your password? Enter your e-mail address below, and we'll send you " +"an e-mail allowing you to reset it." +msgstr "Esqueceu sua senha? Digite seu endereço de e-mail abaixo e enviaremos um e-mail permitindo que você o redefina." + +#: {{dxh_py.project_slug}}/templates/account/password_reset.html:21 +msgid "Reset My Password" +msgstr "Redefinir minha senha" + +#: {{dxh_py.project_slug}}/templates/account/password_reset.html:24 +msgid "Please contact us if you have any trouble resetting your password." +msgstr "Entre em contato conosco se tiver algum problema para redefinir sua senha." + +#: {{dxh_py.project_slug}}/templates/account/password_reset_done.html:15 +msgid "" +"We have sent you an e-mail. Please contact us if you do not receive it " +"within a few minutes." +msgstr "Enviamos um e-mail para você. Entre em contato conosco se você não recebê-lo dentro de alguns minutos." + +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:8 +msgid "Bad Token" +msgstr "Token Inválido" + +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:12 +#, python-format +msgid "" +"The password reset link was invalid, possibly because it has already been " +"used. Please request a new password reset." +msgstr "O link de redefinição de senha era inválido, possivelmente porque já foi usado. " +"Solicite uma nova redefinição de senha." + +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:18 +msgid "change password" +msgstr "alterar senha" + +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key.html:21 +#: {{dxh_py.project_slug}}/templates/account/password_reset_from_key_done.html:8 +msgid "Your password is now changed." +msgstr "Sua senha agora foi alterada." + +#: {{dxh_py.project_slug}}/templates/account/password_set.html:6 +#: {{dxh_py.project_slug}}/templates/account/password_set.html:9 +#: {{dxh_py.project_slug}}/templates/account/password_set.html:14 +msgid "Set Password" +msgstr "Definir Senha" + +#: {{dxh_py.project_slug}}/templates/account/signup.html:6 +msgid "Signup" +msgstr "Cadastro" + +#: {{dxh_py.project_slug}}/templates/account/signup.html:9 +#: {{dxh_py.project_slug}}/templates/account/signup.html:19 +#: {{dxh_py.project_slug}}/templates/base.html:67 +msgid "Sign Up" +msgstr "Cadastro" + +#: {{dxh_py.project_slug}}/templates/account/signup.html:11 +#, python-format +msgid "" +"Already have an account? Then please sign in." +msgstr "já tem uma conta? Então, por favor, faça login." + +#: {{dxh_py.project_slug}}/templates/account/signup_closed.html:5 +#: {{dxh_py.project_slug}}/templates/account/signup_closed.html:8 +msgid "Sign Up Closed" +msgstr "Inscrições encerradas" + +#: {{dxh_py.project_slug}}/templates/account/signup_closed.html:10 +msgid "We are sorry, but the sign up is currently closed." +msgstr "Lamentamos, mas as inscrições estão encerradas no momento." + +#: {{dxh_py.project_slug}}/templates/account/verification_sent.html:5 +#: {{dxh_py.project_slug}}/templates/account/verification_sent.html:8 +#: {{dxh_py.project_slug}}/templates/account/verified_email_required.html:5 +#: {{dxh_py.project_slug}}/templates/account/verified_email_required.html:8 +msgid "Verify Your E-mail Address" +msgstr "Verifique seu endereço de e-mail" + +#: {{dxh_py.project_slug}}/templates/account/verification_sent.html:10 +msgid "" +"We have sent an e-mail to you for verification. Follow the link provided to " +"finalize the signup process. Please contact us if you do not receive it " +"within a few minutes." +msgstr "Enviamos um e-mail para você para verificação. Siga o link fornecido para finalizar o processo de inscrição. Entre em contato conosco se você não recebê-lo dentro de alguns minutos." + +#: {{dxh_py.project_slug}}/templates/account/verified_email_required.html:12 +msgid "" +"This part of the site requires us to verify that\n" +"you are who you claim to be. For this purpose, we require that you\n" +"verify ownership of your e-mail address. " +msgstr "Esta parte do site exige que verifiquemos se você é quem afirma ser.\n" +"Para esse fim, exigimos que você verifique a propriedade\n" +"do seu endereço de e-mail." + +#: {{dxh_py.project_slug}}/templates/account/verified_email_required.html:16 +msgid "" +"We have sent an e-mail to you for\n" +"verification. Please click on the link inside this e-mail. Please\n" +"contact us if you do not receive it within a few minutes." +msgstr "Enviamos um e-mail para você para verificação.\n" +"Por favor, clique no link dentro deste e-mail.\n" +"Entre em contato conosco se você não recebê-lo dentro de alguns minutos." + +#: {{dxh_py.project_slug}}/templates/account/verified_email_required.html:20 +#, python-format +msgid "" +"Note: you can still change your e-" +"mail address." +msgstr "Nota: você ainda pode alterar seu endereço de e-mail." + +#: {{dxh_py.project_slug}}/templates/base.html:57 +msgid "My Profile" +msgstr "Meu perfil" + +#: {{dxh_py.project_slug}}/users/admin.py:17 +msgid "Personal info" +msgstr "Informação pessoal" + +#: {{dxh_py.project_slug}}/users/admin.py:19 +msgid "Permissions" +msgstr "Permissões" + +#: {{dxh_py.project_slug}}/users/admin.py:30 +msgid "Important dates" +msgstr "Datas importantes" + +#: {{dxh_py.project_slug}}/users/apps.py:7 +msgid "Users" +msgstr "Usuários" + +#: {{dxh_py.project_slug}}/users/forms.py:24 +#: {{dxh_py.project_slug}}/users/tests/test_forms.py:36 +msgid "This username has already been taken." +msgstr "Este nome de usuário já foi usado." + +#: {{dxh_py.project_slug}}/users/models.py:15 +msgid "Name of User" +msgstr "Nome do Usuário" + +#: {{dxh_py.project_slug}}/users/views.py:23 +msgid "Information successfully updated" +msgstr "Informação atualizada com sucesso" \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/manage.py b/{{dxh_py.project_slug}}/manage.py index 0f8b05a..6a2e295 100644 --- a/{{dxh_py.project_slug}}/manage.py +++ b/{{dxh_py.project_slug}}/manage.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# ruff: noqa import os import sys from pathlib import Path @@ -13,7 +14,7 @@ # issue is really that Django is missing to avoid masking other # exceptions on Python 2. try: - import django # noqa + import django except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " diff --git a/{{dxh_py.project_slug}}/merge_production_dotenvs_in_dotenv.py b/{{dxh_py.project_slug}}/merge_production_dotenvs_in_dotenv.py index 35139fb..c83ed71 100644 --- a/{{dxh_py.project_slug}}/merge_production_dotenvs_in_dotenv.py +++ b/{{dxh_py.project_slug}}/merge_production_dotenvs_in_dotenv.py @@ -1,3 +1,4 @@ +# ruff: noqa import os from collections.abc import Sequence from pathlib import Path diff --git a/{{dxh_py.project_slug}}/package.json b/{{dxh_py.project_slug}}/package.json index fa23126..42d32b0 100644 --- a/{{dxh_py.project_slug}}/package.json +++ b/{{dxh_py.project_slug}}/package.json @@ -8,15 +8,15 @@ "autoprefixer": "^10.4.0", "babel-loader": "^9.1.2", "bootstrap": "^5.2.3", - "browser-sync": "^2.27.7", - "css-loader": "^6.5.1", + "browser-sync": "^3.0.2", + "css-loader": "^7.1.2", "gulp-concat": "^2.6.1", "concurrently": "^8.0.1", - "cssnano": "^6.0.0", + "cssnano": "^7.0.0", "gulp": "^4.0.2", "gulp-imagemin": "^7.1.0", "gulp-plumber": "^1.2.1", - "gulp-postcss": "^9.0.1", + "gulp-postcss": "^10.0.0", "gulp-rename": "^2.0.0", "gulp-sass": "^5.0.0", "gulp-uglify-es": "^3.0.0", @@ -24,18 +24,18 @@ "node-sass-tilde-importer": "^1.0.2", "pixrem": "^5.0.0", "postcss": "^8.3.11", - "postcss-loader": "^7.0.2", - "postcss-preset-env": "^8.0.1", + "postcss-loader": "^8.0.0", + "postcss-preset-env": "^9.0.0", "sass": "^1.43.4", - "sass-loader": "^13.2.0", + "sass-loader": "^16.0.1", "webpack": "^5.65.0", - "webpack-bundle-tracker": "^1.4.0", + "webpack-bundle-tracker": "^3.0.1", "webpack-cli": "^5.0.1", - "webpack-dev-server": "^4.6.0", - "webpack-merge": "^5.8.0" + "webpack-dev-server": "^5.0.2", + "webpack-merge": "^6.0.1" }, "engines": { - "node": "18" + "node": "22" }, "browserslist": [ "last 2 versions" diff --git a/{{dxh_py.project_slug}}/production.yml b/{{dxh_py.project_slug}}/production.yml index 61323a7..90e9a89 100644 --- a/{{dxh_py.project_slug}}/production.yml +++ b/{{dxh_py.project_slug}}/production.yml @@ -1,5 +1,3 @@ -version: '3' - volumes: {%- if dxh_py.database_engine == 'postgresql' %} production_postgres_data: {} @@ -13,6 +11,10 @@ volumes: {%- if dxh_py.cloud_provider == 'None' %} production_django_media: {} {%- endif %} + {% if dxh_py.use_celery == 'y' %} + production_redis_data: {} + {% endif %} + services: django:{% if dxh_py.use_celery == 'y' %} &django{% endif %} @@ -89,7 +91,7 @@ services: {%- endif %} - traefik: + traefik: build: context: . dockerfile: ./compose/production/traefik/Dockerfile @@ -106,8 +108,12 @@ services: {%- endif %} redis: - image: redis:6 - + image: docker.io/redis:6 + {% if dxh_py.use_celery == 'y' %} + volumes: + - production_redis_data:/data + {% endif %} + {%- if dxh_py.use_celery == 'y' %} celeryworker: @@ -142,7 +148,7 @@ services: build: context: . dockerfile: ./compose/production/nginx/Dockerfile - image: {{ dxh_py.project_slug }}_local_nginx + image: {{ dxh_py.project_slug }}_production_nginx depends_on: - django volumes: diff --git a/{{dxh_py.project_slug}}/pyproject.toml b/{{dxh_py.project_slug}}/pyproject.toml index e124447..fa27ef6 100644 --- a/{{dxh_py.project_slug}}/pyproject.toml +++ b/{{dxh_py.project_slug}}/pyproject.toml @@ -1,7 +1,7 @@ # ==== pytest ==== [tool.pytest.ini_options] minversion = "6.0" -addopts = "--ds=config.settings.test --reuse-db" +addopts = "--ds=config.settings.test --reuse-db --import-mode=importlib" python_files = [ "tests.py", "test_*.py", @@ -16,28 +16,9 @@ include = ["{{dxh_py.project_slug}}/**"] omit = ["*/migrations/*", "*/tests/*"] plugins = ["django_coverage_plugin"] - -# ==== black ==== -[tool.black] -line-length = 119 -target-version = ['py311'] - - -# ==== isort ==== -[tool.isort] -profile = "black" -line_length = 119 -known_first_party = [ - "{{dxh_py.project_slug}}", - "config", -] -skip = ["venv/"] -skip_glob = ["**/migrations/*.py"] - - # ==== mypy ==== [tool.mypy] -python_version = "3.11" +python_version = "3.12" check_untyped_defs = true ignore_missing_imports = true warn_unused_ignores = true @@ -58,35 +39,104 @@ ignore_errors = true [tool.django-stubs] django_settings_module = "config.settings.test" +# ==== djLint ==== +[tool.djlint] +blank_line_after_tag = "load,extends" +close_void_tags = true +format_css = true +format_js = true +# TODO: remove T002 when fixed https://github.com/djlint/djLint/issues/687 +ignore = "H006,H030,H031,T002" +include = "H017,H035" +indent = 2 +max_line_length = 119 +profile = "django" -# ==== PyLint ==== -[tool.pylint.MASTER] -load-plugins = [ - "pylint_django", -{%- if dxh_py.use_celery == "y" %} - "pylint_celery", -{%- endif %} -] -django-settings-module = "config.settings.local" +[tool.djlint.css] +indent_size = 2 -[tool.pylint.FORMAT] -max-line-length = 119 +[tool.djlint.js] +indent_size = 2 -[tool.pylint."MESSAGES CONTROL"] -disable = [ - "missing-docstring", - "invalid-name", +[tool.ruff] +target-version = "py312" +# Exclude a variety of commonly ignored directories. +extend-exclude = [ + "*/migrations/*.py", + "staticfiles/*", ] -[tool.pylint.DESIGN] -max-parents = 13 - -[tool.pylint.TYPECHECK] -generated-members = [ - "REQUEST", - "acl_users", - "aq_parent", - "[a-zA-Z]+_set{1,2}", - "save", - "delete", +[tool.ruff.lint] +select = [ + "F", + "E", + "W", + "C90", + "I", + "N", + "UP", + "YTT", + # "ANN", # flake8-annotations: we should support this in the future but 100+ errors atm + "ASYNC", + "S", + "BLE", + "FBT", + "B", + "A", + "COM", + "C4", + "DTZ", + "T10", + "DJ", + "EM", + "EXE", + "FA", + 'ISC', + "ICN", + "G", + 'INP', + 'PIE', + "T20", + 'PYI', + 'PT', + "Q", + "RSE", + "RET", + "SLF", + "SLOT", + "SIM", + "TID", + "TCH", + "INT", + # "ARG", # Unused function argument + "PTH", + "ERA", + "PD", + "PGH", + "PL", + "TRY", + "FLY", + # "NPY", + # "AIR", + "PERF", + # "FURB", + # "LOG", + "RUF", ] +ignore = [ + "S101", # Use of assert detected https://docs.astral.sh/ruff/rules/assert/ + "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` + "SIM102", # sometimes it's better to nest + "UP038", # Checks for uses of isinstance/issubclass that take a tuple + # of types for comparison. + # Deactivated because it can make the code slow: + # https://github.com/astral-sh/ruff/issues/7871 +] +# The fixes in extend-unsafe-fixes will require +# provide the `--unsafe-fixes` flag when fixing. +extend-unsafe-fixes = [ + "UP038", +] + +[tool.ruff.lint.isort] +force-single-line = true \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/requirements/base.txt b/{{dxh_py.project_slug}}/requirements/base.txt index 2e2677f..3b75cd7 100644 --- a/{{dxh_py.project_slug}}/requirements/base.txt +++ b/{{dxh_py.project_slug}}/requirements/base.txt @@ -1,66 +1,68 @@ -pytz==2023.3 # https://github.com/stub42/pytz -python-slugify==8.0.1 # https://github.com/un33k/python-slugify -Pillow==9.5.0 # https://github.com/python-pillow/Pillow +pytz==2024.1 # https://github.com/stub42/pytz +python-slugify==8.0.4 # https://github.com/un33k/python-slugify +pillow==10.4.0 # https://github.com/python-pillow/Pillow {%- if dxh_py.frontend_pipeline == 'Django Compressor' %} {%- if dxh_py.windows == 'y' and dxh_py.use_docker == 'n' %} -rcssmin==1.1.0 --install-option="--without-c-extensions" # https://github.com/ndparker/rcssmin +rcssmin==1.1.2 --install-option="--without-c-extensions" # https://github.com/ndparker/rcssmin {%- else %} -rcssmin==1.1.1 # https://github.com/ndparker/rcssmin +rcssmin==1.1.2 # https://github.com/ndparker/rcssmin {%- endif %} {%- endif %} -argon2-cffi==21.3.0 # https://github.com/hynek/argon2_cffi +argon2-cffi==23.1.0 # https://github.com/hynek/argon2_cffi {%- if dxh_py.use_whitenoise == 'y' %} -whitenoise==6.4.0 # https://github.com/evansd/whitenoise +whitenoise==6.7.0 # https://github.com/evansd/whitenoise {%- endif %} -redis==4.5.4 # https://github.com/redis/redis-py +redis==5.0.8 # https://github.com/redis/redis-py {%- if dxh_py.use_docker == "y" or dxh_py.windows == "n" %} -hiredis==2.2.2 # https://github.com/redis/hiredis-py +hiredis==3.0.0 # https://github.com/redis/hiredis-py {%- endif %} {%- if dxh_py.use_celery == "y" %} -celery==5.2.7 # pyup: < 6.0 # https://github.com/celery/celery -django-celery-beat==2.5.0 # https://github.com/celery/django-celery-beat +celery==5.4.0 # pyup: < 6.0 # https://github.com/celery/celery +django-celery-beat==2.7.0 # https://github.com/celery/django-celery-beat {%- if dxh_py.use_docker == 'y' %} -flower==1.2.0 # https://github.com/mher/flower +flower==2.0.1 # https://github.com/mher/flower {%- endif %} {%- endif %} {%- if dxh_py.use_async == 'y' %} -uvicorn[standard]==0.21.1 # https://github.com/encode/uvicorn +uvicorn[standard]==0.30.6 # https://github.com/encode/uvicorn +uvicorn-worker==0.2.0 # https://github.com/Kludex/uvicorn-worker {%- endif %} # Django # ------------------------------------------------------------------------------ -django==3.2.15 # pyup: < 3.2.15 # https://www.djangoproject.com/ -django-environ==0.10.0 # https://github.com/joke2k/django-environ -django-model-utils==4.3.1 # https://github.com/jazzband/django-model-utils -django-allauth==0.54.0 # https://github.com/pennersr/django-allauth -django-crispy-forms==2.0 # https://github.com/django-crispy-forms/django-crispy-forms -crispy-bootstrap5==0.7 # https://github.com/django-crispy-forms/crispy-bootstrap5 +django==5.0.8 # pyup: < 5.1 # https://www.djangoproject.com/ +django-cors-headers==4.4.0 # https://github.com/adamchainz/django-cors-headers +PyJWT==2.9.0 +django-environ==0.11.2 # https://github.com/joke2k/django-environ +django-model-utils==4.5.1 # https://github.com/jazzband/django-model-utils +django-allauth[mfa]==64.1.0 # https://github.com/pennersr/django-allauth +django-crispy-forms==2.3 # https://github.com/django-crispy-forms/django-crispy-forms +crispy-bootstrap5==2024.2 # https://github.com/django-crispy-forms/crispy-bootstrap5 {%- if dxh_py.frontend_pipeline == 'Django Compressor' %} -django-compressor==4.3.1 # https://github.com/django-compressor/django-compressor +django-compressor==4.5.1 # https://github.com/django-compressor/django-compressor {%- endif %} -django-redis==5.2.0 # https://github.com/jazzband/django-redis +django-redis==5.4.0 # https://github.com/jazzband/django-redis {%- if dxh_py.use_drf == 'y' %} # Django REST Framework -djangorestframework==3.14.0 # https://github.com/encode/django-rest-framework +djangorestframework==3.15.2 # https://github.com/encode/django-rest-framework # DRF-spectacular for api documentation -drf-spectacular==0.26.2 # https://github.com/tfranzel/drf-spectacular +drf-spectacular==0.27.2 # https://github.com/tfranzel/drf-spectacular {%- endif %} {%- if dxh_py.frontend_pipeline == 'Webpack' %} -django-webpack-loader==1.8.1 # https://github.com/django-webpack/django-webpack-loader +django-webpack-loader==3.1.0 # https://github.com/django-webpack/django-webpack-loader {%- endif %} {%- if dxh_py.use_graphene == 'y' %} # Graphene -graphene-django==3.0.0 # https://github.com/graphql-python/graphene-django -django-graphql-jwt==0.3.4 # https://github.com/flavors/django-graphql-jwt +graphene-django==3.2.2 # https://github.com/graphql-python/graphene-django +django-graphql-jwt==0.4.0 # https://github.com/flavors/django-graphql-jwt graphene-file-upload==1.3.0 {%- endif %} -django-filter==22.1 # https://github.com/carltongibson/django-filter -django-cors-headers==3.14.0 # https://github.com/adamchainz/django-cors-headers {%- if dxh_py.use_drf == "y" %} -dj-rest-auth==3.0.0 -djangorestframework-simplejwt==5.2.2 +dj-rest-auth==6.0.0 +djangorestframework-simplejwt==5.3.1 {%- endif %} {%- if dxh_py.use_tenants == "y" %} -django-tenants==3.4.8 +django-tenants==3.6.1 {%- endif %} +django-filter==24.3 # https://github.com/carltongibson/django-filter diff --git a/{{dxh_py.project_slug}}/requirements/local.txt b/{{dxh_py.project_slug}}/requirements/local.txt index 9577f0b..6dab3c8 100644 --- a/{{dxh_py.project_slug}}/requirements/local.txt +++ b/{{dxh_py.project_slug}}/requirements/local.txt @@ -1,54 +1,49 @@ --r base.txt +-r production.txt -Werkzeug[watchdog]==2.3.1 # https://github.com/pallets/werkzeug +Werkzeug[watchdog]==3.0.4 # https://github.com/pallets/werkzeug ipdb==0.13.13 # https://github.com/gotcha/ipdb {%- if dxh_py.database_engine == "postgresql" %} {%- if dxh_py.use_docker == 'y' %} -psycopg2==2.9.6 # https://github.com/psycopg/psycopg2 +psycopg[c]==3.2.1 # https://github.com/psycopg/psycopg {%- else %} -psycopg2-binary==2.9.6 # https://github.com/psycopg/psycopg2 +psycopg[binary]==3.2.1 # https://github.com/psycopg/psycopg {%- endif %} {%- endif %} {%- if dxh_py.database_engine == "mysql" %} -mysqlclient==2.1.1 # https://github.com/PyMySQL/mysqlclient +mysqlclient==2.2.4 # https://github.com/PyMySQL/mysqlclient {%- endif %} {%- if dxh_py.use_async == 'y' or dxh_py.use_celery == 'y' %} -watchfiles==0.19.0 # https://github.com/samuelcolvin/watchfiles +watchfiles==0.24.0 # https://github.com/samuelcolvin/watchfiles {%- endif %} - # Testing # ------------------------------------------------------------------------------ -mypy==1.2.0 # https://github.com/python/mypy -django-stubs==4.2.0 # https://github.com/typeddjango/django-stubs -pytest==7.3.1 # https://github.com/pytest-dev/pytest -pytest-sugar==0.9.7 # https://github.com/Frozenball/pytest-sugar +mypy==1.11.2 # https://github.com/python/mypy +django-stubs[compatible-mypy]==5.0.4 # https://github.com/typeddjango/django-stubs +pytest==8.3.2 # https://github.com/pytest-dev/pytest +pytest-sugar==1.0.0 # https://github.com/Frozenball/pytest-sugar {%- if dxh_py.use_drf == "y" %} -djangorestframework-stubs==3.14.0 # https://github.com/typeddjango/djangorestframework-stubs +djangorestframework-stubs==3.15.0 # https://github.com/typeddjango/djangorestframework-stubs {%- endif %} # Documentation # ------------------------------------------------------------------------------ -sphinx==6.2.1 # https://github.com/sphinx-doc/sphinx -sphinx-autobuild==2021.3.14 # https://github.com/GaretJax/sphinx-autobuild +sphinx==7.4.7 # https://github.com/sphinx-doc/sphinx +sphinx-autobuild==2024.4.16 # https://github.com/GaretJax/sphinx-autobuild # Code quality # ------------------------------------------------------------------------------ -flake8==6.0.0 # https://github.com/PyCQA/flake8 -flake8-isort==6.0.0 # https://github.com/gforcada/flake8-isort -coverage==7.2.3 # https://github.com/nedbat/coveragepy -black==23.3.0 # https://github.com/psf/black -pylint-django==2.5.3 # https://github.com/PyCQA/pylint-django -{%- if dxh_py.use_celery == 'y' %} -pylint-celery==0.3 # https://github.com/PyCQA/pylint-celery -{%- endif %} -pre-commit==3.2.2 # https://github.com/pre-commit/pre-commit +ruff==0.6.2 # https://github.com/astral-sh/ruff +coverage==7.6.1 # https://github.com/nedbat/coveragepy +black==24.8.0 # https://github.com/psf/black +djlint==1.34.2 # https://github.com/Riverside-Healthcare/djLint +pre-commit==3.8.0 # https://github.com/pre-commit/pre-commit # Django # ------------------------------------------------------------------------------ -factory-boy==3.2.1 # https://github.com/FactoryBoy/factory_boy +factory-boy==3.3.1 # https://github.com/FactoryBoy/factory_boy -django-debug-toolbar==4.0.0 # https://github.com/jazzband/django-debug-toolbar -django-extensions==3.2.1 # https://github.com/django-extensions/django-extensions -django-coverage-plugin==3.0.0 # https://github.com/nedbat/django_coverage_plugin -pytest-django==4.5.2 # https://github.com/pytest-dev/pytest-django +django-debug-toolbar==4.4.6 # https://github.com/jazzband/django-debug-toolbar +django-extensions==3.2.3 # https://github.com/django-extensions/django-extensions +django-coverage-plugin==3.1.0 # https://github.com/nedbat/django_coverage_plugin +pytest-django==4.8.0 # https://github.com/pytest-dev/pytest-django diff --git a/{{dxh_py.project_slug}}/requirements/production.txt b/{{dxh_py.project_slug}}/requirements/production.txt index 891fd23..b112000 100644 --- a/{{dxh_py.project_slug}}/requirements/production.txt +++ b/{{dxh_py.project_slug}}/requirements/production.txt @@ -2,48 +2,48 @@ -r base.txt -gunicorn==20.1.0 # https://github.com/benoitc/gunicorn +gunicorn==23.0.0 # https://github.com/benoitc/gunicorn {%- if dxh_py.database_engine == "postgresql" %} -psycopg2==2.9.6 # https://github.com/psycopg/psycopg2 +psycopg[c]==3.2.1 # https://github.com/psycopg/psycopg {%- elif dxh_py.database_engine == "mysql" %} -mysqlclient==2.1.1 # https://github.com/PyMySQL/mysqlclient +mysqlclient==2.2.4 # https://github.com/PyMySQL/mysqlclient {%- endif %} {%- if dxh_py.use_whitenoise == 'n' %} -Collectfast==2.2.0 # https://github.com/antonagestam/collectfast +Collectfasta==3.2.0 # https://github.com/jasongi/collectfasta {%- endif %} {%- if dxh_py.use_sentry == "y" %} -sentry-sdk==1.21.0 # https://github.com/getsentry/sentry-python +sentry-sdk==2.13.0 # https://github.com/getsentry/sentry-python {%- endif %} {%- if dxh_py.use_docker == "n" and dxh_py.windows == "y" %} -hiredis==2.2.2 # https://github.com/redis/hiredis-py +hiredis==3.0.0 # https://github.com/redis/hiredis-py {%- endif %} # Django # ------------------------------------------------------------------------------ {%- if dxh_py.cloud_provider == 'AWS' %} -django-storages[boto3]==1.13.2 # https://github.com/jschneier/django-storages +django-storages[s3]==1.14.4 # https://github.com/jschneier/django-storages {%- elif dxh_py.cloud_provider == 'GCP' %} -django-storages[google]==1.13.2 # https://github.com/jschneier/django-storages +django-storages[google]==1.14.4 # https://github.com/jschneier/django-storages {%- elif dxh_py.cloud_provider == 'Azure' %} -django-storages[azure]==1.13.2 # https://github.com/jschneier/django-storages +django-storages[azure]==1.14.4 # https://github.com/jschneier/django-storages {%- endif %} {%- if dxh_py.mail_service == 'Mailgun' %} -django-anymail[mailgun]==9.1 # https://github.com/anymail/django-anymail +django-anymail[mailgun]==11.1 # https://github.com/anymail/django-anymail {%- elif dxh_py.mail_service == 'Amazon SES' %} -django-anymail[amazon_ses]==9.1 # https://github.com/anymail/django-anymail +django-anymail[amazon-ses]==11.1 # https://github.com/anymail/django-anymail {%- elif dxh_py.mail_service == 'Mailjet' %} -django-anymail[mailjet]==9.1 # https://github.com/anymail/django-anymail +django-anymail[mailjet]==11.1 # https://github.com/anymail/django-anymail {%- elif dxh_py.mail_service == 'Mandrill' %} -django-anymail[mandrill]==9.1 # https://github.com/anymail/django-anymail +django-anymail[mandrill]==11.1 # https://github.com/anymail/django-anymail {%- elif dxh_py.mail_service == 'Postmark' %} -django-anymail[postmark]==9.1 # https://github.com/anymail/django-anymail +django-anymail[postmark]==11.1 # https://github.com/anymail/django-anymail {%- elif dxh_py.mail_service == 'Sendgrid' %} -django-anymail[sendgrid]==9.1 # https://github.com/anymail/django-anymail -{%- elif dxh_py.mail_service == 'SendinBlue' %} -django-anymail[sendinblue]==9.1 # https://github.com/anymail/django-anymail +django-anymail[sendgrid]==11.1 # https://github.com/anymail/django-anymail +{%- elif dxh_py.mail_service == 'Brevo' %} +django-anymail[brevo]==11.1 # https://github.com/anymail/django-anymail {%- elif dxh_py.mail_service == 'SparkPost' %} -django-anymail[sparkpost]==9.1 # https://github.com/anymail/django-anymail +django-anymail[sparkpost]==11.1 # https://github.com/anymail/django-anymail {%- elif dxh_py.mail_service == 'Other SMTP' %} -django-anymail==9.1 # https://github.com/anymail/django-anymail +django-anymail==11.1 # https://github.com/anymail/django-anymail {%- endif %} diff --git a/{{dxh_py.project_slug}}/runtime.txt b/{{dxh_py.project_slug}}/runtime.txt index afe12ad..8a7cba5 100644 --- a/{{dxh_py.project_slug}}/runtime.txt +++ b/{{dxh_py.project_slug}}/runtime.txt @@ -1 +1 @@ -python-3.11.3 +python-3.12.5 diff --git a/{{dxh_py.project_slug}}/setup.cfg b/{{dxh_py.project_slug}}/setup.cfg deleted file mode 100644 index 8290642..0000000 --- a/{{dxh_py.project_slug}}/setup.cfg +++ /dev/null @@ -1,10 +0,0 @@ -# flake8 and pycodestyle don't support pyproject.toml -# https://github.com/PyCQA/flake8/issues/234 -# https://github.com/PyCQA/pycodestyle/issues/813 -[flake8] -max-line-length = 119 -exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules,venv,.venv - -[pycodestyle] -max-line-length = 119 -exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules,venv,.venv diff --git a/{{dxh_py.project_slug}}/tests/__init__.py b/{{dxh_py.project_slug}}/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/{{dxh_py.project_slug}}/utility/requirements-bionic.apt b/{{dxh_py.project_slug}}/utility/requirements-bionic.apt index 1ca82b2..0e1a657 100644 --- a/{{dxh_py.project_slug}}/utility/requirements-bionic.apt +++ b/{{dxh_py.project_slug}}/utility/requirements-bionic.apt @@ -9,7 +9,7 @@ python3-dev ##Pillow, pylibmc zlib1g-dev -##Postgresql and psycopg2 dependencies +##Postgresql and psycopg dependencies libpq-dev ##Pillow dependencies diff --git a/{{dxh_py.project_slug}}/utility/requirements-bookworm.apt b/{{dxh_py.project_slug}}/utility/requirements-bookworm.apt new file mode 100644 index 0000000..883101e --- /dev/null +++ b/{{dxh_py.project_slug}}/utility/requirements-bookworm.apt @@ -0,0 +1,23 @@ +##basic build dependencies of various Django apps for Debian Bookworm 12.x +#build-essential metapackage install: make, gcc, g++, +build-essential +#required to translate +gettext +python3-dev + +##shared dependencies of: +##Pillow, pylibmc +zlib1g-dev + +##Postgresql and psycopg dependencies +libpq-dev + +##Pillow dependencies +libtiff5-dev +libjpeg62-turbo-dev +libfreetype6-dev +liblcms2-dev +libwebp-dev + +##django-extensions +libgraphviz-dev \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/utility/requirements-bullseye.apt b/{{dxh_py.project_slug}}/utility/requirements-bullseye.apt index 60f6028..e8e36b6 100644 --- a/{{dxh_py.project_slug}}/utility/requirements-bullseye.apt +++ b/{{dxh_py.project_slug}}/utility/requirements-bullseye.apt @@ -9,7 +9,7 @@ python3-dev ##Pillow, pylibmc zlib1g-dev -##Postgresql and psycopg2 dependencies +##Postgresql and psycopg dependencies libpq-dev ##Pillow dependencies diff --git a/{{dxh_py.project_slug}}/utility/requirements-buster.apt b/{{dxh_py.project_slug}}/utility/requirements-buster.apt index 75957f4..f2c8196 100644 --- a/{{dxh_py.project_slug}}/utility/requirements-buster.apt +++ b/{{dxh_py.project_slug}}/utility/requirements-buster.apt @@ -9,7 +9,7 @@ python3-dev ##Pillow, pylibmc zlib1g-dev -##Postgresql and psycopg2 dependencies +##Postgresql and psycopg dependencies libpq-dev ##Pillow dependencies diff --git a/{{dxh_py.project_slug}}/utility/requirements-focal.apt b/{{dxh_py.project_slug}}/utility/requirements-focal.apt index fe6f21e..f400b41 100644 --- a/{{dxh_py.project_slug}}/utility/requirements-focal.apt +++ b/{{dxh_py.project_slug}}/utility/requirements-focal.apt @@ -9,7 +9,7 @@ python3-dev ##Pillow, pylibmc zlib1g-dev -##Postgresql and psycopg2 dependencies +##Postgresql and psycopg dependencies libpq-dev ##Pillow dependencies diff --git a/{{dxh_py.project_slug}}/utility/requirements-jammy.apt b/{{dxh_py.project_slug}}/utility/requirements-jammy.apt index 63d1587..ea52472 100644 --- a/{{dxh_py.project_slug}}/utility/requirements-jammy.apt +++ b/{{dxh_py.project_slug}}/utility/requirements-jammy.apt @@ -9,7 +9,7 @@ python3-dev ##Pillow, pylibmc zlib1g-dev -##Postgresql and psycopg2 dependencies +##Postgresql and psycopg dependencies libpq-dev ##Pillow dependencies diff --git a/{{dxh_py.project_slug}}/utility/requirements-jessie.apt b/{{dxh_py.project_slug}}/utility/requirements-jessie.apt index 5c49365..ebf0e58 100644 --- a/{{dxh_py.project_slug}}/utility/requirements-jessie.apt +++ b/{{dxh_py.project_slug}}/utility/requirements-jessie.apt @@ -9,7 +9,7 @@ python3-dev ##Pillow, pylibmc zlib1g-dev -##Postgresql and psycopg2 dependencies +##Postgresql and psycopg dependencies libpq-dev ##Pillow dependencies diff --git a/{{dxh_py.project_slug}}/utility/requirements-stretch.apt b/{{dxh_py.project_slug}}/utility/requirements-stretch.apt index a2b3a7e..979eca3 100644 --- a/{{dxh_py.project_slug}}/utility/requirements-stretch.apt +++ b/{{dxh_py.project_slug}}/utility/requirements-stretch.apt @@ -9,7 +9,7 @@ python3-dev ##Pillow, pylibmc zlib1g-dev -##Postgresql and psycopg2 dependencies +##Postgresql and psycopg dependencies libpq-dev ##Pillow dependencies diff --git a/{{dxh_py.project_slug}}/utility/requirements-trusty.apt b/{{dxh_py.project_slug}}/utility/requirements-trusty.apt index 455f1a8..954f783 100644 --- a/{{dxh_py.project_slug}}/utility/requirements-trusty.apt +++ b/{{dxh_py.project_slug}}/utility/requirements-trusty.apt @@ -9,7 +9,7 @@ python3-dev ##Pillow, pylibmc zlib1g-dev -##Postgresql and psycopg2 dependencies +##Postgresql and psycopg dependencies libpq-dev ##Pillow dependencies diff --git a/{{dxh_py.project_slug}}/utility/requirements-xenial.apt b/{{dxh_py.project_slug}}/utility/requirements-xenial.apt index ba84ef1..1784e40 100644 --- a/{{dxh_py.project_slug}}/utility/requirements-xenial.apt +++ b/{{dxh_py.project_slug}}/utility/requirements-xenial.apt @@ -9,7 +9,7 @@ python3-dev ##Pillow, pylibmc zlib1g-dev -##Postgresql and psycopg2 dependencies +##Postgresql and psycopg dependencies libpq-dev ##Pillow dependencies diff --git a/{{dxh_py.project_slug}}/webpack/common.config.js b/{{dxh_py.project_slug}}/webpack/common.config.js index 0e3267f..3a7fd6a 100644 --- a/{{dxh_py.project_slug}}/webpack/common.config.js +++ b/{{dxh_py.project_slug}}/webpack/common.config.js @@ -20,7 +20,8 @@ module.exports = { }, plugins: [ new BundleTracker({ - filename: path.resolve(__dirname, '../webpack-stats.json'), + path: path.resolve(path.join(__dirname, '../')), + filename: 'webpack-stats.json', }), new MiniCssExtractPlugin({ filename: 'css/[name].[contenthash].css' }), ], diff --git a/{{dxh_py.project_slug}}/webpack/dev.config.js b/{{dxh_py.project_slug}}/webpack/dev.config.js index 8aeba8f..d5d1d95 100644 --- a/{{dxh_py.project_slug}}/webpack/dev.config.js +++ b/{{dxh_py.project_slug}}/webpack/dev.config.js @@ -6,15 +6,25 @@ module.exports = merge(commonConfig, { devtool: 'inline-source-map', devServer: { port: 3000, - proxy: { - {%- if dxh_py.use_docker == 'n' %} - '/': 'http://0.0.0.0:8000', - {%- else %} - '/': 'http://django:8000', - {%- endif %} + proxy: [ + { + context: ['/'], + {%- if dxh_py.use_docker == 'n' %} + target: 'http://0.0.0.0:8000', + {%- else %} + target: 'http://django:8000', + {%- endif %} + }, + ], + client: { + overlay: { + errors: true, + warnings: false, + runtimeErrors: true, + }, }, // We need hot=false (Disable HMR) to set liveReload=true hot: false, liveReload: true, }, -}); +}); \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/__init__.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/__init__.py index 7cd0fc3..fc5c2e6 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/__init__.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/__init__.py @@ -1,2 +1,5 @@ __version__ = "{{ dxh_py.version }}" -__version_info__ = tuple(int(num) if num.isdigit() else num for num in __version__.replace("-", ".", 1).split(".")) +__version_info__ = tuple( + int(num) if num.isdigit() else num + for num in __version__.replace("-", ".", 1).split(".") +) \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/conftest.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/conftest.py index 941eb03..d450952 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/conftest.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/conftest.py @@ -5,7 +5,7 @@ @pytest.fixture(autouse=True) -def media_storage(settings, tmpdir): +def _media_storage(settings, tmpdir) -> None: settings.MEDIA_ROOT = tmpdir.strpath diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0001_initial.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0001_initial.py index 304cd6d..26c05ee 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0001_initial.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0001_initial.py @@ -1,6 +1,7 @@ import django.contrib.sites.models from django.contrib.sites.models import _simple_domain_name_validator -from django.db import migrations, models +from django.db import migrations +from django.db import models class Migration(migrations.Migration): @@ -38,5 +39,5 @@ class Migration(migrations.Migration): }, bases=(models.Model,), managers=[("objects", django.contrib.sites.models.SiteManager())], - ) - ] + ), + ] \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0002_alter_domain_unique.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0002_alter_domain_unique.py index 2c8d6da..4a44a6a 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0002_alter_domain_unique.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0002_alter_domain_unique.py @@ -1,5 +1,6 @@ import django.contrib.sites.models -from django.db import migrations, models +from django.db import migrations +from django.db import models class Migration(migrations.Migration): diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0003_set_site_domain_and_name.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0003_set_site_domain_and_name.py index c0b6fe9..5976fa9 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0003_set_site_domain_and_name.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/contrib/sites/migrations/0003_set_site_domain_and_name.py @@ -50,8 +50,8 @@ def update_site_forward(apps, schema_editor): _update_or_create_site_with_sequence( Site, schema_editor.connection, - "{{dxh_py.domain_name}}", - "{{dxh_py.project_name}}", + "{{ dxh_py.domain_name }}", + "{{ dxh_py.project_name[:50] }}", ) @@ -70,4 +70,4 @@ class Migration(migrations.Migration): dependencies = [("sites", "0002_alter_domain_unique")] - operations = [migrations.RunPython(update_site_forward, update_site_backward)] + operations = [migrations.RunPython(update_site_forward, update_site_backward)] \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/setting/models.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/setting/models.py index aad2bae..d527f2b 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/setting/models.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/setting/models.py @@ -6,6 +6,7 @@ class PasswordPolicies(BaseModel): + id = models.BigAutoField(primary_key=True) min_length = models.IntegerField(default=4, blank=True, null=True) min_uppercase = models.IntegerField(default=1, blank=True, null=True) min_lowercase = models.IntegerField(default=1, blank=True, null=True) @@ -18,12 +19,17 @@ def __str__(self): def clean(self): super().clean() - total_length = self.min_uppercase + self.min_lowercase + self.min_numerals + self.min_special_chars - if ( - total_length > self.min_length - ): + min_uppercase = self.min_uppercase or 0 + min_lowercase = self.min_lowercase or 0 + min_numerals = self.min_numerals or 0 + min_special_chars = self.min_special_chars or 0 + min_length = self.min_length or 0 + + total_length = min_uppercase + min_lowercase + min_numerals + min_special_chars + + if total_length > min_length: raise ValidationError( - "Minimum uppercase, lowercase, numerals, or special characters cannot exceed minimum length." + "The sum of minimum uppercase, lowercase, numerals, and special characters cannot exceed the minimum length." ) diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/static/js/vendors.js b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/static/js/vendors.js new file mode 100644 index 0000000..21a9b3c --- /dev/null +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/static/js/vendors.js @@ -0,0 +1,2 @@ +import '@popperjs/core'; +import 'bootstrap'; \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/adapters.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/adapters.py index 0d206fa..21984bd 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/adapters.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/adapters.py @@ -1,16 +1,44 @@ -from typing import Any +from __future__ import annotations + +import typing from allauth.account.adapter import DefaultAccountAdapter from allauth.socialaccount.adapter import DefaultSocialAccountAdapter from django.conf import settings -from django.http import HttpRequest + +if typing.TYPE_CHECKING: + from allauth.socialaccount.models import SocialLogin + from django.http import HttpRequest + + from {{dxh_py.project_slug}}.users.models import User class AccountAdapter(DefaultAccountAdapter): - def is_open_for_signup(self, request: HttpRequest): + def is_open_for_signup(self, request: HttpRequest) -> bool: return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True) class SocialAccountAdapter(DefaultSocialAccountAdapter): - def is_open_for_signup(self, request: HttpRequest, sociallogin: Any): + def is_open_for_signup(self, request: HttpRequest, sociallogin: SocialLogin,) -> bool: return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True) + + def populate_user( + self, + request: HttpRequest, + sociallogin: SocialLogin, + data: dict[str, typing.Any], + ) -> User: + """ + Populates user information from social provider info. + + See: https://docs.allauth.org/en/latest/socialaccount/advanced.html#creating-and-populating-user-instances + """ + user = super().populate_user(request, sociallogin, data) + if not user.name: + if name := data.get("name"): + user.name = name + elif first_name := data.get("first_name"): + user.name = first_name + if last_name := data.get("last_name"): + user.name += f" {last_name}" + return user \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/admin.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/admin.py index ce7f76f..f0e3e0a 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/admin.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/admin.py @@ -1,11 +1,17 @@ +from allauth.account.decorators import secure_admin_login +from django.conf import settings from django.contrib import admin from django.contrib.auth import admin as auth_admin -from django.contrib.auth import get_user_model from django.utils.translation import gettext_lazy as _ -from {{ dxh_py.project_slug }}.users.forms import UserAdminChangeForm, UserAdminCreationForm +from .forms import UserAdminChangeForm, UserAdminCreationForm +from .models import User -User = get_user_model() +if settings.DJANGO_ADMIN_FORCE_ALLAUTH: + # Force the `admin` sign in process to go through the `django-allauth` workflow: + # https://docs.allauth.org/en/latest/common/admin.html#admin + admin.autodiscover() + admin.site.login = secure_admin_login(admin.site.login) # type: ignore[method-assign] @admin.register(User) diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/api/serializers.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/api/serializers.py index fba1d08..df4b2df 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/api/serializers.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/api/serializers.py @@ -1,10 +1,9 @@ -from django.contrib.auth import get_user_model from rest_framework import serializers -User = get_user_model() +from {{ dxh_py.project_slug }}.users.models import User -class UserSerializer(serializers.ModelSerializer): +class UserSerializer(serializers.ModelSerializer[User]): class Meta: model = User {%- if dxh_py.username_type == "email" %} diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/api/views.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/api/views.py index 9633399..e0fe1de 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/api/views.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/api/views.py @@ -1,13 +1,14 @@ -from django.contrib.auth import get_user_model from rest_framework import status from rest_framework.decorators import action -from rest_framework.mixins import ListModelMixin, RetrieveModelMixin, UpdateModelMixin +from rest_framework.mixins import ListModelMixin +from rest_framework.mixins import RetrieveModelMixin +from rest_framework.mixins import UpdateModelMixin from rest_framework.response import Response from rest_framework.viewsets import GenericViewSet -from .serializers import UserSerializer +from {{ dxh_py.project_slug }}.users.models import User -User = get_user_model() +from .serializers import UserSerializer class UserViewSet(RetrieveModelMixin, ListModelMixin, UpdateModelMixin, GenericViewSet): diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/apps.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/apps.py index 1f95cd3..1d64eaf 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/apps.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/apps.py @@ -1,3 +1,5 @@ +import contextlib + from django.apps import AppConfig from django.utils.translation import gettext_lazy as _ @@ -7,7 +9,5 @@ class UsersConfig(AppConfig): verbose_name = _("Users") def ready(self): - try: - import {{ dxh_py.project_slug }}.users.signals # noqa: F401 - except ImportError: - pass + with contextlib.suppress(ImportError): + import {{ dxh_py.project_slug }}.users.signals # noqa: F401 \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/forms.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/forms.py index 5fae0fb..32d7f3d 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/forms.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/forms.py @@ -1,17 +1,16 @@ from allauth.account.forms import SignupForm from allauth.socialaccount.forms import SignupForm as SocialSignupForm from django.contrib.auth import forms as admin_forms -from django.contrib.auth import get_user_model {%- if dxh_py.username_type == "email" %} from django.forms import EmailField {%- endif %} from django.utils.translation import gettext_lazy as _ -User = get_user_model() +from .models import User class UserAdminChangeForm(admin_forms.UserChangeForm): - class Meta(admin_forms.UserChangeForm.Meta): + class Meta(admin_forms.UserChangeForm.Meta): # type: ignore[name-defined] model = User {%- if dxh_py.username_type == "email" %} field_classes = {"email": EmailField} @@ -24,7 +23,7 @@ class UserAdminCreationForm(admin_forms.UserCreationForm): To change user signup, see UserSignupForm and UserSocialSignupForm. """ - class Meta(admin_forms.UserCreationForm.Meta): + class Meta(admin_forms.UserCreationForm.Meta): # type: ignore[name-defined] model = User {%- if dxh_py.username_type == "email" %} fields = ("email",) diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/managers.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/managers.py index 017ab14..ac97682 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/managers.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/managers.py @@ -1,8 +1,13 @@ +from typing import TYPE_CHECKING + from django.contrib.auth.hashers import make_password from django.contrib.auth.models import UserManager as DjangoUserManager +if TYPE_CHECKING: + from .models import User # noqa: F401 + -class UserManager(DjangoUserManager): +class UserManager(DjangoUserManager["User"]): """Custom manager for the User model.""" def _create_user(self, email: str, password: str | None, **extra_fields): @@ -17,12 +22,12 @@ def _create_user(self, email: str, password: str | None, **extra_fields): user.save(using=self._db) return user - def create_user(self, email: str, password: str | None = None, **extra_fields): + def create_user(self, email: str, password: str | None = None, **extra_fields): # type: ignore[override] extra_fields.setdefault("is_staff", False) extra_fields.setdefault("is_superuser", False) return self._create_user(email, password, **extra_fields) - def create_superuser(self, email: str, password: str | None = None, **extra_fields): + def create_superuser(self, email: str, password: str | None = None, **extra_fields): # type: ignore[override] extra_fields.setdefault("is_staff", True) extra_fields.setdefault("is_superuser", True) @@ -31,4 +36,4 @@ def create_superuser(self, email: str, password: str | None = None, **extra_fiel if extra_fields.get("is_superuser") is not True: raise ValueError("Superuser must have is_superuser=True.") - return self._create_user(email, password, **extra_fields) + return self._create_user(email, password, **extra_fields) \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/migrations/0001_initial.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/migrations/0001_initial.py index 168e4f2..5543ad0 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/migrations/0001_initial.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/migrations/0001_initial.py @@ -1,7 +1,8 @@ import django.contrib.auth.models import django.contrib.auth.validators -from django.db import migrations, models import django.utils.timezone +from django.db import migrations +from django.db import models import {{dxh_py.project_slug}}.users.models @@ -31,7 +32,7 @@ class Migration(migrations.Migration): ( "last_login", models.DateTimeField( - blank=True, null=True, verbose_name="last login" + blank=True, null=True, verbose_name="last login", ), ), ( @@ -61,14 +62,14 @@ class Migration(migrations.Migration): ( "email", models.EmailField( - blank=True, max_length=254, verbose_name="email address" + blank=True, max_length=254, verbose_name="email address", ), ), {%- else %} ( "email", models.EmailField( - unique=True, max_length=254, verbose_name="email address" + unique=True, max_length=254, verbose_name="email address", ), ), {%- endif %} @@ -91,7 +92,7 @@ class Migration(migrations.Migration): ( "date_joined", models.DateTimeField( - default=django.utils.timezone.now, verbose_name="date joined" + default=django.utils.timezone.now, verbose_name="date joined", ), ), ( @@ -149,4 +150,4 @@ class Migration(migrations.Migration): {%- endif %} ], ), - ] + ] \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/migrations/0002_auto_20240609_1055.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/migrations/0002_auto_20240609_1055.py deleted file mode 100644 index 02c34ec..0000000 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/migrations/0002_auto_20240609_1055.py +++ /dev/null @@ -1,44 +0,0 @@ -# Generated by Django 3.2.15 on 2024-06-09 10:55 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion -import uuid - - -class Migration(migrations.Migration): - - dependencies = [ - ('users', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='user', - name='phone_number', - field=models.CharField(blank=True, max_length=255, null=True), - ), - migrations.AddField( - model_name='user', - name='phone_verified', - field=models.BooleanField(default=False), - ), - migrations.CreateModel( - name='PhoneVerification', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)), - ('created_at', models.DateTimeField(auto_now_add=True, null=True)), - ('updated_at', models.DateTimeField(auto_now=True, null=True)), - ('is_deleted', models.BooleanField(default=False)), - ('phone_number', models.CharField(blank=True, max_length=255, null=True)), - ('otp', models.CharField(blank=True, max_length=4, null=True)), - ('expires_at', models.DateTimeField(blank=True, null=True)), - ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='phoneverification_created', to=settings.AUTH_USER_MODEL)), - ('updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='phoneverification_updated', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'abstract': False, - }, - ), - ] diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/models.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/models.py index e1bd438..8b7b0dc 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/models.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/models.py @@ -1,11 +1,16 @@ +{%- if dxh_py.username_type == "email" %} +from typing import ClassVar +{% endif -%} from django.contrib.auth.models import AbstractUser -from django.db.models import CharField{% if dxh_py.username_type == "email" %}, EmailField{% endif %} +from django.db.models import CharField +{%- if dxh_py.username_type == "email" %} +from django.db.models import EmailField +{%- endif %} from django.urls import reverse -from django.db import models from django.utils.translation import gettext_lazy as _ {%- if dxh_py.username_type == "email" %} -from {{ dxh_py.project_slug }}.users.managers import UserManager +from .managers import UserManager {%- endif %} @@ -15,22 +20,28 @@ class User(AbstractUser): If adding fields that need to be filled at user signup, check forms.SignupForm and forms.SocialSignupForms accordingly. """ - - # First and last name do not cover name patterns around the globe - name = CharField(_("Name of User"), blank=True, max_length=255) + + # Overriding fields in AbstractUser first_name = None # type: ignore last_name = None # type: ignore - reset_password_token = models.CharField(max_length=255, blank=True, null=True) - reset_otp= models.CharField(max_length=6, blank=True, null=True) - verify_token = models.CharField(max_length=255, blank=True, null=True) + {%- if dxh_py.username_type == "email" %} - email = EmailField(_("email address"), unique=True) username = None # type: ignore + {%- endif %} + + # Custom fields + name = CharField(_("Name of User"), blank=True, max_length=255) + reset_password_token = CharField(max_length=255, blank=True, null=True) + reset_otp= CharField(max_length=6, blank=True, null=True) + verify_token = CharField(max_length=255, blank=True, null=True) + {%- if dxh_py.username_type == "email" %} + email = EmailField(_("email address"), unique=True) + # Update the USERNAME_FIELD and REQUIRED_FIELDS USERNAME_FIELD = "email" REQUIRED_FIELDS = [] - - objects = UserManager() + + objects: ClassVar[UserManager] = UserManager() {%- endif %} def get_absolute_url(self) -> str: @@ -44,4 +55,4 @@ def get_absolute_url(self) -> str: return reverse("users:detail", kwargs={"pk": self.id}) {%- else %} return reverse("users:detail", kwargs={"username": self.username}) - {%- endif %} + {%- endif %} \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tasks.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tasks.py index 6b3d224..986f0aa 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tasks.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tasks.py @@ -2,16 +2,14 @@ {%- if dxh_py.use_twillio == 'y' %} from twilio.rest import Client {%- endif %} -from django.contrib.auth import get_user_model from celery import shared_task from django.core.mail import send_mail from config import celery_app import environ from django.template.loader import render_to_string +from .models import User env = environ.Env() -User = get_user_model() - @celery_app.task() def get_users_count(): diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/factories.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/factories.py index c862913..97c42c7 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/factories.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/factories.py @@ -1,12 +1,14 @@ from collections.abc import Sequence from typing import Any -from django.contrib.auth import get_user_model -from factory import Faker, post_generation +from factory import Faker +from factory import post_generation from factory.django import DjangoModelFactory +from {{ dxh_py.project_slug }}.users.models import User -class UserFactory(DjangoModelFactory): + +class UserFactory(DjangoModelFactory[User]): {%- if dxh_py.username_type == "username" %} username = Faker("user_name") {%- endif %} @@ -14,7 +16,7 @@ class UserFactory(DjangoModelFactory): name = Faker("name") @post_generation - def password(self, create: bool, extracted: Sequence[Any], **kwargs): + def password(self, create: bool, extracted: Sequence[Any], **kwargs): # noqa: FBT001 password = ( extracted if extracted @@ -29,6 +31,13 @@ def password(self, create: bool, extracted: Sequence[Any], **kwargs): ) self.set_password(password) + @classmethod + def _after_postgeneration(cls, instance, create, results=None): + """Save again the instance if creating and at least one hook ran.""" + if create and results and not cls._meta.skip_postgeneration_save: + # Some post-generation hooks ran, and may have modified us. + instance.save() + class Meta: - model = get_user_model() - django_get_or_create = ["{{dxh_py.username_type}}"] + model = User + django_get_or_create = ["{{dxh_py.username_type}}"] \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_admin.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_admin.py index a45c82b..e154ee9 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_admin.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_admin.py @@ -1,4 +1,12 @@ +import contextlib +from http import HTTPStatus +from importlib import reload + +import pytest +from django.contrib import admin +from django.contrib.auth.models import AnonymousUser from django.urls import reverse +from pytest_django.asserts import assertRedirects from {{ dxh_py.project_slug }}.users.models import User @@ -7,17 +15,17 @@ class TestUserAdmin: def test_changelist(self, admin_client): url = reverse("admin:users_user_changelist") response = admin_client.get(url) - assert response.status_code == 200 + assert response.status_code == HTTPStatus.OK def test_search(self, admin_client): url = reverse("admin:users_user_changelist") response = admin_client.get(url, data={"q": "test"}) - assert response.status_code == 200 + assert response.status_code == HTTPStatus.OK def test_add(self, admin_client): url = reverse("admin:users_user_add") response = admin_client.get(url) - assert response.status_code == 200 + assert response.status_code == HTTPStatus.OK response = admin_client.post( url, @@ -31,7 +39,7 @@ def test_add(self, admin_client): "password2": "My_R@ndom-P@ssw0rd", }, ) - assert response.status_code == 302 + assert response.status_code == HTTPStatus.FOUND {%- if dxh_py.username_type == "email" %} assert User.objects.filter(email="new-admin@example.com").exists() {%- else %} @@ -46,4 +54,4 @@ def test_view_user(self, admin_client): {%- endif %} url = reverse("admin:users_user_change", kwargs={"object_id": user.pk}) response = admin_client.get(url) - assert response.status_code == 200 + assert response.status_code == HTTPStatus.OK diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_drf_urls.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_drf_urls.py index 3861788..cdf7a3b 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_drf_urls.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_drf_urls.py @@ -1,14 +1,20 @@ -from django.urls import resolve, reverse +from django.urls import resolve +from django.urls import reverse from {{ dxh_py.project_slug }}.users.models import User def test_user_detail(user: User): {%- if dxh_py.username_type == "email" %} - assert reverse("api:user-detail", kwargs={"pk": user.pk}) == f"/api/users/{user.pk}/" + assert ( + reverse("api:user-detail", kwargs={"pk": user.pk}) == f"/api/users/{user.pk}/" + ) assert resolve(f"/api/users/{user.pk}/").view_name == "api:user-detail" {%- else %} - assert reverse("api:user-detail", kwargs={"username": user.username}) == f"/api/users/{user.username}/" + assert ( + reverse("api:user-detail", kwargs={"username": user.username}) + == f"/api/users/{user.username}/" + ) assert resolve(f"/api/users/{user.username}/").view_name == "api:user-detail" {%- endif %} diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_drf_views.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_drf_views.py index 7504752..2a76ed8 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_drf_views.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_drf_views.py @@ -26,7 +26,7 @@ def test_me(self, user: User, api_rf: APIRequestFactory): view.request = request - response = view.me(request) # type: ignore + response = view.me(request) # type: ignore[call-arg, arg-type, misc] assert response.data == { {%- if dxh_py.username_type == "email" %} diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_forms.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_forms.py index f4ca3d2..a1f87fe 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_forms.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_forms.py @@ -1,6 +1,5 @@ -""" -Module for all Form Tests. -""" +"""Module for all Form Tests.""" + from django.utils.translation import gettext_lazy as _ from {{ dxh_py.project_slug }}.users.forms import UserAdminCreationForm @@ -31,7 +30,7 @@ def test_username_validation_error_msg(self, user: User): {%- endif %} "password1": user.password, "password2": user.password, - } + }, ) assert not form.is_valid() diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_managers.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_managers.py index 499d6d8..82f2bb1 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_managers.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_managers.py @@ -11,7 +11,7 @@ class TestUserManager: def test_create_user(self): user = User.objects.create_user( email="john@example.com", - password="something-r@nd0m!", + password="something-r@nd0m!", # noqa: S106 ) assert user.email == "john@example.com" assert not user.is_staff @@ -22,7 +22,7 @@ def test_create_user(self): def test_create_superuser(self): user = User.objects.create_superuser( email="admin@example.com", - password="something-r@nd0m!", + password="something-r@nd0m!", # noqa: S106 ) assert user.email == "admin@example.com" assert user.is_staff @@ -32,7 +32,7 @@ def test_create_superuser(self): def test_create_superuser_username_ignored(self): user = User.objects.create_superuser( email="test@example.com", - password="something-r@nd0m!", + password="something-r@nd0m!", # noqa: S106 ) assert user.username is None diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_swagger.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_swagger.py index f97658b..f800109 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_swagger.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_swagger.py @@ -1,3 +1,5 @@ +from http import HTTPStatus + import pytest from django.urls import reverse @@ -5,17 +7,17 @@ def test_swagger_accessible_by_admin(admin_client): url = reverse("api-docs") response = admin_client.get(url) - assert response.status_code == 200 + assert response.status_code == HTTPStatus.OK @pytest.mark.django_db def test_swagger_ui_not_accessible_by_normal_user(client): url = reverse("api-docs") response = client.get(url) - assert response.status_code == 403 + assert response.status_code == HTTPStatus.UNAUTHORIZED def test_api_schema_generated_successfully(admin_client): url = reverse("api-schema") response = admin_client.get(url) - assert response.status_code == 200 + assert response.status_code == HTTPStatus.OK \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_tasks.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_tasks.py index d719ecb..c912176 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_tasks.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_tasks.py @@ -9,8 +9,9 @@ def test_user_count(settings): """A basic test to execute the get_users_count Celery task.""" - UserFactory.create_batch(3) + batch_size = 3 + UserFactory.create_batch(batch_size) settings.CELERY_TASK_ALWAYS_EAGER = True task_result = get_users_count.delay() assert isinstance(task_result, EagerResult) - assert task_result.result == 3 + assert task_result.result == batch_size \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_urls.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_urls.py index 89d3400..f720bc0 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_urls.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_urls.py @@ -1,4 +1,5 @@ -from django.urls import resolve, reverse +from django.urls import resolve +from django.urls import reverse from {{ dxh_py.project_slug }}.users.models import User @@ -8,7 +9,10 @@ def test_detail(user: User): assert reverse("users:detail", kwargs={"pk": user.pk}) == f"/users/{user.pk}/" assert resolve(f"/users/{user.pk}/").view_name == "users:detail" {%- else %} - assert reverse("users:detail", kwargs={"username": user.username}) == f"/users/{user.username}/" + assert ( + reverse("users:detail", kwargs={"username": user.username}) + == f"/users/{user.username}/" + ) assert resolve(f"/users/{user.username}/").view_name == "users:detail" {%- endif %} @@ -20,4 +24,4 @@ def test_update(): def test_redirect(): assert reverse("users:redirect") == "/users/~redirect/" - assert resolve("/users/~redirect/").view_name == "users:redirect" + assert resolve("/users/~redirect/").view_name == "users:redirect" \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_views.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_views.py index 30c17a8..952d50c 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_views.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/tests/test_views.py @@ -1,21 +1,23 @@ +from http import HTTPStatus + import pytest from django.conf import settings from django.contrib import messages from django.contrib.auth.models import AnonymousUser from django.contrib.messages.middleware import MessageMiddleware from django.contrib.sessions.middleware import SessionMiddleware -from django.http import HttpRequest, HttpResponseRedirect +from django.http import HttpRequest +from django.http import HttpResponseRedirect from django.test import RequestFactory from django.urls import reverse +from django.utils.translation import gettext_lazy as _ from {{ dxh_py.project_slug }}.users.forms import UserAdminChangeForm from {{ dxh_py.project_slug }}.users.models import User from {{ dxh_py.project_slug }}.users.tests.factories import UserFactory -from {{ dxh_py.project_slug }}.users.views import ( - UserRedirectView, - UserUpdateView, - user_detail_view, -) +from {{ dxh_py.project_slug }}.users.views import UserRedirectView +from {{ dxh_py.project_slug }}.users.views import UserUpdateView +from {{ dxh_py.project_slug }}.users.views import user_detail_view pytestmark = pytest.mark.django_db @@ -72,7 +74,7 @@ def test_form_valid(self, user: User, rf: RequestFactory): view.form_valid(form) messages_sent = [m.message for m in messages.get_messages(request)] - assert messages_sent == ["Information successfully updated"] + assert messages_sent == [_("Information successfully updated")] class TestUserRedirectView: @@ -101,7 +103,7 @@ def test_authenticated(self, user: User, rf: RequestFactory): response = user_detail_view(request, username=user.username) {%- endif %} - assert response.status_code == 200 + assert response.status_code == HTTPStatus.OK def test_not_authenticated(self, user: User, rf: RequestFactory): request = rf.get("/fake-url/") @@ -115,5 +117,5 @@ def test_not_authenticated(self, user: User, rf: RequestFactory): login_url = reverse(settings.LOGIN_URL) assert isinstance(response, HttpResponseRedirect) - assert response.status_code == 302 - assert response.url == f"{login_url}?next=/fake-url/" + assert response.status_code == HTTPStatus.FOUND + assert response.url == f"{login_url}?next=/fake-url/" \ No newline at end of file diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/urls.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/urls.py index c97e3a2..9f564ee 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/urls.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/urls.py @@ -1,10 +1,8 @@ from django.urls import path -from {{ dxh_py.project_slug }}.users.views import ( - user_detail_view, - user_redirect_view, - user_update_view, -) +from .views import user_detail_view +from .views import user_redirect_view +from .views import user_update_view app_name = "users" urlpatterns = [ diff --git a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/views.py b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/views.py index 9a6c8e1..e97e284 100644 --- a/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/views.py +++ b/{{dxh_py.project_slug}}/{{dxh_py.project_slug}}/users/views.py @@ -1,7 +1,6 @@ -import environ -from django.contrib.auth import get_user_model from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.messages.views import SuccessMessageMixin +from django.db.models import QuerySet from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django.views.generic import DetailView, RedirectView, UpdateView @@ -11,10 +10,10 @@ from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter from allauth.socialaccount.providers.oauth2.client import OAuth2Client {%- endif %} +from {{ dxh_py.project_slug }}.users.models import User +import environ env = environ.Env() -User = get_user_model() - class UserDetailView(LoginRequiredMixin, DetailView): model = User @@ -35,11 +34,12 @@ class UserUpdateView(LoginRequiredMixin, SuccessMessageMixin, UpdateView): fields = ["name"] success_message = _("Information successfully updated") - def get_success_url(self): - assert self.request.user.is_authenticated # for mypy to know that the user is authenticated + def get_success_url(self) -> str: + assert self.request.user.is_authenticated # type guard return self.request.user.get_absolute_url() - def get_object(self): + def get_object(self, queryset: QuerySet | None=None) -> User: + assert self.request.user.is_authenticated # type guard return self.request.user @@ -49,7 +49,7 @@ def get_object(self): class UserRedirectView(LoginRequiredMixin, RedirectView): permanent = False - def get_redirect_url(self): + def get_redirect_url(self) -> str: {%- if dxh_py.username_type == "email" %} return reverse("users:detail", kwargs={"pk": self.request.user.pk}) {%- else %}