Skip to content

Commit

Permalink
Merge branch 'main' into add-django-debug-toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
CamLamb committed Dec 4, 2024
2 parents 1fb5cda + 3905827 commit dbfeb74
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 45 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ APP_ENV=local

# Django
DJANGO_DEBUG=true
ENABLE_DEBUGPY=false
DJANGO_SECRET_KEY=this_is_an_example_use_a_proper_key_in_production

# Wagtail
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,30 @@ A [Wagtail](https://www.wagtail.io)-based intranet for the Department for Busine

Project documentation is available [here](https://uktrade.github.io/digital-workspace-v2/).

# Setup DebugPy

Add environment variable in your .env file

ENABLE_DEBUGPY=True

Create launch.json file inside .vscode directory

{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach (DebugPy)",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app/"
}
],
"justMyCode": true
},
]
}
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ services:
volumes:
- ./:/app/
ports:
- "0.0.0.0:8000:8000"
- "8000:8000"
- "5678:5678"
depends_on:
- db
- redis
Expand Down
37 changes: 36 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ wagtail-factories = "^4.0.0"
# Util
bpython = "^0.24"
django-extensions = "^3.2.1"
django-silk = "^5.0.4"
django-debug-toolbar = "^4.4.6"
werkzeug = "^3.0.6"
blessings = "^1.7"
pytest-mock = "^3.11.1"
pytest-freezer = "^0.4.8"
playwright = "^1.36"
django-silk = "^5.0.4"
snakeviz = "^2.2.0"
django-debug-toolbar = "^4.4.6"
debugpy = "*"

[tool.poetry.group.docs.dependencies]
mkdocs-awesome-pages-plugin = "^2.8.0"
Expand Down
2 changes: 2 additions & 0 deletions src/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

DEBUG = env.bool("DJANGO_DEBUG", False)

ENABLE_DEBUGPY = env.bool("ENABLE_DEBUGPY", False)

SECRET_KEY = env("DJANGO_SECRET_KEY")

AUTH_USER_MODEL = "user.User"
Expand Down
35 changes: 33 additions & 2 deletions src/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,40 @@
import sys


if __name__ == "__main__":
def initialize_debugpy():
try:
import debugpy
except ImportError:
sys.stdout.write(
"debugpy is not installed, please install it with: pip install debugpy\n"
)
return

if not os.getenv("RUN_MAIN"):
debugpy.listen(("0.0.0.0", 5678))
sys.stdout.write("debugpy listening on port 5678...\n")


def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.prod")
from django.conf import settings

from django.core.management import execute_from_command_line
if settings.DEBUG and settings.ENABLE_DEBUGPY:
initialize_debugpy()

try:
from django.core.management import execute_from_command_line
except ImportError:
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
78 changes: 39 additions & 39 deletions src/peoplefinder/templates/peoplefinder/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

{% block primary_content %}
<div class="content-stack large">
<div class="dwds-content-item-card">
<div class="dwds-content-item-card no-shadow">
<div class="dwds-content-list content-item">
<div class="content-main">
<div class="content-body content-body-space-padding content-stack">
Expand Down Expand Up @@ -80,40 +80,6 @@ <h1 class="text-large" data-testid="full-name">{{ profile.full_name }}</h1>
</div>
</div>

{% if show_confirm_my_details or show_activate_profile %}
<div class="dwds-button-group">
{% if show_confirm_my_details %}
<button class="dwds-button dwds-button--transactional"
hx-post="{% url 'profile-confirm-details' profile.slug %}"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
Confirm my details are still correct
</button>
{% endif %}

{% if show_activate_profile %}
<button class="dwds-button dwds-button--transactional"
hx-post="{% url 'profile-activate' profile.slug %}"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-confirm="Are you sure you want to activate this profile?">
Activate profile
</button>
{% endif %}
</div>
{% endif %}

{% if profile.is_active and perms.peoplefinder.delete_person and request.user != profile.user %}
<form action="{% url 'profile-delete' profile.slug %}"
style="display: contents"
method="post"
onsubmit="javascript:return confirm('Are you sure? This cannot be undone.')">
{% csrf_token %}
<input class="dwds-button dwds-button--warning"
type="submit"
id="delete-profile"
value="Delete profile" />
</form>
{% endif %}

<div class="content-stack">
{% if profile.is_active %}
{% if request.user == profile.user %}
Expand All @@ -129,10 +95,44 @@ <h1 class="text-large" data-testid="full-name">{{ profile.full_name }}</h1>
<p>This profile is inactive since {{ profile.became_inactive|naturaltime }}.</p>
{% endif %}
</div>
{% if profile.is_active %}
<a class="dwds-button dwds-button--inline dwds-button--secondary"
href="{% url 'profile-edit' profile.slug %}">Edit profile</a>
{% endif %}


<div class="dwds-button-group">
{% if profile.is_active %}
<a class="dwds-button dwds-button--inline dwds-button--secondary"
href="{% url 'profile-edit' profile.slug %}">Edit profile</a>
{% endif %}

{% if show_confirm_my_details %}
<button class="dwds-button dwds-button--inline dwds-button--transactional"
hx-post="{% url 'profile-confirm-details' profile.slug %}"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
Confirm my details are still correct
</button>
{% endif %}

{% if show_activate_profile %}
<button class="dwds-button dwds-button--inline dwds-button--transactional"
hx-post="{% url 'profile-activate' profile.slug %}"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-confirm="Are you sure you want to activate this profile?">
Activate profile
</button>
{% endif %}

{% if profile.is_active and perms.peoplefinder.delete_person and request.user != profile.user %}
<form action="{% url 'profile-delete' profile.slug %}"
style="display: contents"
method="post"
onsubmit="javascript:return confirm('Are you sure? This cannot be undone.')">
{% csrf_token %}
<input class="dwds-button dwds-button--inline dwds-button--warning"
type="submit"
id="delete-profile"
value="Delete profile" />
</form>
{% endif %}
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit dbfeb74

Please sign in to comment.