Skip to content

Commit dd4d99b

Browse files
evildmpdwilding
andauthored
More frontend fixes (#62)
* Fixed a permissions issue * Bumped version * Add more reload delays, fix another permissions bug * Fixed status algorithm (again) * Added date picker for last review date * Added URL field, improved basic view * Added back tests for logged-in user * Updated CSS for candidate/na statuses * Reformatted with Black * Added basic permission testing * Removed unnecessary formset from template * Bumped version * install playright before running tests * add CI for running tests * fix testing deps * Improved frontend tests Now loads initial_data.yaml that includes built-in superuser and driver users. * Update dashboard/projects/templates/projects/partial_project_basics.html Co-authored-by: Dave Wilding <tech@dpw.me> * Updated initial_data.yaml * Removed project objective inlines from project admin * Added log in/out and other URLs to project page * Bumped version * add delays in more places (temporary workaround) * try very long delays (for debugging * compromise on 5-second delays * match settings.py update in rock version * match login form layout with project form * send users back to the project page on logout --------- Co-authored-by: David Wilding <david.wilding@canonical.com> Co-authored-by: Dave Wilding <tech@dpw.me>
1 parent f3abd70 commit dd4d99b

File tree

11 files changed

+76
-46
lines changed

11 files changed

+76
-46
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ The application will run in a Kubernetes cluster, so we need a container image f
8686
Creating the container image might take several minutes, so this is a good point to take a break. When you return, you should see the following output:
8787

8888
> ```
89-
> Packed dashboard_0.24_amd64.rock
89+
> Packed dashboard_0.25_amd64.rock
9090
> ```
9191
9292
### Create a charm
@@ -109,10 +109,10 @@ Creating the charm might take several minutes, so this is another good point to
109109
``` { name=deploy-dashboard }
110110
cd ~/dashboard
111111
rockcraft.skopeo --insecure-policy copy --dest-tls-verify=false \
112-
oci-archive:dashboard_0.24_amd64.rock \
113-
docker://localhost:32000/dashboard:0.24
112+
oci-archive:dashboard_0.25_amd64.rock \
113+
docker://localhost:32000/dashboard:0.25
114114
juju deploy ./charm/dashboard_ubuntu-22.04-amd64.charm \
115-
--resource django-app-image=localhost:32000/dashboard:0.24
115+
--resource django-app-image=localhost:32000/dashboard:0.25
116116
```
117117
118118
The `rockcraft.skopeo` command makes the container image available to Juju.

dashboard/dashboard/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,6 @@
131131
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
132132

133133
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
134+
135+
LOGIN_REDIRECT_URL = "projects:project_list"
136+
LOGOUT_REDIRECT_URL = "projects:project_list"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
<h2>Log in</h2>
6+
<form method="post">
7+
{% csrf_token %}
8+
9+
<table>
10+
11+
{% for field in form %}
12+
<tr><td>{{ field.label_tag }}</td><td>{{ field }}</td></tr>
13+
{% endfor %}
14+
15+
</table>
16+
17+
<p>
18+
<button type="submit">Log In</button>
19+
</p>
20+
21+
</form>
22+
23+
{% endblock %}

dashboard/dashboard/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
urlpatterns = [
55
path("admin/doc/", include("django.contrib.admindocs.urls")),
66
path("admin/", admin.site.urls),
7+
path("accounts/", include("django.contrib.auth.urls")),
78
path("__reload__/", include("django_browser_reload.urls")),
89
path("", include("projects.urls")),
910
]

dashboard/initial_data.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@
478478
pk: 1
479479
fields:
480480
name: Nuclear
481-
url: ''
481+
url: https://nuclear.org
482482
group: 1
483483
owner: A. Scientist
484484
driver: A. Technician
@@ -489,7 +489,7 @@
489489
pk: 2
490490
fields:
491491
name: Chemistry
492-
url: https://nuclear.nut
492+
url: https://chemistry.org
493493
group: 1
494494
owner: A. Chemist
495495
driver: null

dashboard/projects/admin.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,6 @@ def has_delete_permission(self, request, obj):
5050
return False
5151

5252

53-
class ProjectObjectiveInline(admin.TabularInline):
54-
model = ProjectObjective
55-
max_num = 0
56-
can_delete = False
57-
fields = ("name", "unstarted_reason")
58-
readonly_fields = ["name"]
59-
exclude = ["objective", "description", "status"]
60-
61-
def has_add_permission(self, request, obj):
62-
return False
63-
64-
def has_delete_permission(self, request, obj):
65-
return False
66-
67-
6853
@admin.register(ProjectObjective)
6954
class ProjectObjectiveAdmin(admin.ModelAdmin):
7055
readonly_fields = ["project", "objective", "status"]
@@ -95,9 +80,7 @@ def change_view(self, request, object_id, form_url="", extra_context=None):
9580

9681
@admin.register(Project)
9782
class ProjectAdmin(admin.ModelAdmin):
98-
inlines = [
99-
ProjectObjectiveInline,
100-
]
83+
10184
list_display = [
10285
"name",
10386
"owner",

dashboard/projects/templates/projects/partial_project_basics.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<div id="basic_information">
2-
3-
{% if not user.is_authenticated %}
4-
<div class="auth"><a href="{% url 'admin:index' %}">Log in to edit</a></div>
5-
{% endif %}
6-
72
<div id="basic_form" class="submit-row">
83
<form
94
hx-post="{% url 'projects:project_basic_form_save' project.id %}"

dashboard/projects/templates/projects/project.html

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,47 @@
1414

1515
{% block content %}
1616

17-
<h1>{{ project }}</h1>
17+
<div id="container">
1818

19-
<div id="container">
20-
<div class="main" id="main">
21-
<main id="content-start" class="content">
22-
<div id="content" class="colM">
23-
<div id="content-main">
19+
<nav class="navigation">
20+
<ul>
21+
<li><a href="/">Dashboard</a></li>
22+
{% if user.is_authenticated %}
23+
<li><a href="{% url 'admin:index' %}">Admin</a></li>
24+
<li>Logged in as {{ user.username }}</li>
25+
<li>
26+
<form action="{% url 'logout' %}?next={{ request.path }}" method="post">
27+
{% csrf_token %}
28+
<button type="submit">Log out</button>
29+
</form>
30+
</li>
31+
{% else %}
32+
<li><a href="{% url 'login' %}?next={{ request.path }}">Log in</a></li>
33+
{% endif %}
34+
</ul>
35+
</nav>
2436

25-
<div>{% include "projects/partial_project_basics.html" %}</div>
37+
<h1>{{ project }}</h1>
2638

27-
<hr>
39+
<div class="main" id="main">
40+
<main id="content-start" class="content">
41+
<div id="content" class="colM">
42+
<div id="content-main">
2843

29-
<div>{% include "projects/partial_project_commitments.html" %}</div>
44+
<div>{% include "projects/partial_project_basics.html" %}</div>
3045

31-
<hr>
46+
<hr>
3247

33-
{% include "projects/partial_projectobjectives.html" %}
48+
<div>{% include "projects/partial_project_commitments.html" %}</div>
3449

50+
<hr>
51+
52+
{% include "projects/partial_projectobjectives.html" %}
53+
54+
</div>
3555
</div>
36-
</div>
37-
</main>
56+
</main>
57+
</div>
3858
</div>
39-
</div>
59+
4060
{% endblock content %}

dashboard/tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_toggling_conditions(live_server, page):
5858
# after toggling, the new conditions should be saved in the database
5959
page.get_by_test_id("toggle_condition_94").uncheck()
6060
page.get_by_test_id("toggle_condition_102").check()
61-
time.sleep(0.5) # Temporary workaround. Find a better solution.
61+
time.sleep(5) # Temporary workaround. Find a better solution.
6262

6363
assert ProjectObjectiveCondition.objects.get(id=94).done == False
6464
assert ProjectObjectiveCondition.objects.get(id=102).done == True
@@ -70,7 +70,7 @@ def test_toggling_conditions(live_server, page):
7070

7171
page.get_by_test_id("toggle_commitment_705").check()
7272
page.get_by_test_id("toggle_commitment_474").uncheck()
73-
time.sleep(0.5) # Temporary workaround. Find a better solution.
73+
time.sleep(5) # Temporary workaround. Find a better solution.
7474

7575
assert Commitment.objects.get(id=705).committed == True
7676
assert Commitment.objects.get(id=474).committed == False
@@ -88,13 +88,15 @@ def test_toggling_conditions(live_server, page):
8888

8989
# check the remaining box to get to Started
9090
page.get_by_test_id("toggle_condition_10").check()
91+
time.sleep(5) # Temporary workaround. Find a better solution.
9192
assert ProjectObjectiveCondition.objects.get(
9293
id=10
9394
).projectobjective().status() == Level.objects.get(id=1)
9495
expect(page.get_by_test_id("projectobjective_status_1")).to_contain_text("Started")
9596

9697
# check one more to get to First results
9798
page.get_by_test_id("toggle_condition_14").check()
99+
time.sleep(5) # Temporary workaround. Find a better solution.
98100
assert ProjectObjectiveCondition.objects.get(
99101
id=14
100102
).projectobjective().status() == Level.objects.get(id=1)

dashboard_rock_patch/dashboard/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,6 @@
151151
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
152152

153153
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
154+
155+
LOGIN_REDIRECT_URL = "projects:project_list"
156+
LOGOUT_REDIRECT_URL = "projects:project_list"

0 commit comments

Comments
 (0)