aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ctrack/register/migrations/0004_auto_20201017_1958.py33
-rw-r--r--ctrack/templates/base.html2
-rw-r--r--ctrack/templates/users/user_detail.html75
-rw-r--r--ctrack/users/tests/test_views.py47
-rw-r--r--ctrack/users/views.py12
5 files changed, 131 insertions, 38 deletions
diff --git a/ctrack/register/migrations/0004_auto_20201017_1958.py b/ctrack/register/migrations/0004_auto_20201017_1958.py
new file mode 100644
index 0000000..d13903d
--- /dev/null
+++ b/ctrack/register/migrations/0004_auto_20201017_1958.py
@@ -0,0 +1,33 @@
+# Generated by Django 3.1.2 on 2020-10-17 19:58
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('register', '0003_auto_20201015_1955'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='singledatetimeevent',
+ name='private',
+ field=models.BooleanField(default=False, help_text='Private events can only be seen by you. Official records should not be private, but you can use private events to track your own work.'),
+ ),
+ migrations.AddField(
+ model_name='singledatetimeevent',
+ name='url',
+ field=models.URLField(blank=True, help_text='If recording an email, please link to it here. Do not paste the text in the comments box.', max_length=400, null=True, verbose_name='URL'),
+ ),
+ migrations.AlterField(
+ model_name='singledatetimeevent',
+ name='location',
+ field=models.CharField(blank=True, help_text='If event involved a physical location, indicate here.', max_length=100),
+ ),
+ migrations.AlterField(
+ model_name='singledatetimeevent',
+ name='type_descriptor',
+ field=models.CharField(choices=[('MEETING', 'Meeting'), ('PHONE_CALL', 'Phone Call'), ('VIDEO_CALL', 'Video Call'), ('EMAIL', 'Email'), ('NOTE', 'Note')], max_length=50),
+ ),
+ ]
diff --git a/ctrack/templates/base.html b/ctrack/templates/base.html
index be4340a..0b1e04e 100644
--- a/ctrack/templates/base.html
+++ b/ctrack/templates/base.html
@@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
- <title>{% block title %}ctrack - Department for Transport{% endblock title %}</title>
+ <title>{% block title %}ctrack - NIS Tracker{% endblock title %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
diff --git a/ctrack/templates/users/user_detail.html b/ctrack/templates/users/user_detail.html
index f1913c3..5b9386f 100644
--- a/ctrack/templates/users/user_detail.html
+++ b/ctrack/templates/users/user_detail.html
@@ -4,35 +4,56 @@
{% block title %}User: {{ object.username }}{% endblock %}
{% block content %}
-<div class="container">
-
- <div class="row">
- <div class="col-sm-12">
-
- <h2>User: {{ object.username }}</h2>
- {% if object.name %}
- <p>{{ object.name }}</p>
- {% else %}
- <p>Email: {{ object.email }}</p>
- {% endif %}
+ <div class="container">
+
+ <div class="row">
+ <div class="col-sm-12">
+
+ <h1 class="display-4">{{ object.name }}</h1>
+ {% if object.name %}
+ <p>{{ object.name }}</p>
+ {% else %}
+ <p>Email: {{ object.email }}</p>
+ {% endif %}
+ </div>
</div>
- </div>
-{% if object == request.user %}
-<!-- Action buttons -->
-<div class="row">
-
- <div class="col-sm-12">
- <a class="btn btn-primary" href="{% url 'users:update' %}" role="button">My Info</a>
- <a class="btn btn-primary" href="{% url 'account_email' %}" role="button">E-Mail</a>
- <!-- Your Stuff: Custom user template urls -->
+ {#{% if object == request.user %}#}
+ {#<!-- Action buttons -->#}
+ {#<div class="row">#}
+ {##}
+ {# <div class="col-sm-12 mb-3">#}
+ {# <a class="btn btn-primary" href="{% url 'users:update' %}" role="button">My Info</a>#}
+ {# <a class="btn btn-primary" href="{% url 'account_email' %}" role="button">E-Mail</a>#}
+ {# <!-- Your Stuff: Custom user template urls -->#}
+ {# </div>#}
+ {#</div>#}
+ {#<!-- End Action buttons -->#}
+ {#{% endif %}#}
+ </div>
+ <hr>
+ <div class="container">
+ <div class="row justify-content-center">
+ <div class="col-md-12 m-2">
+ <h3 class="h3">Recent Events</h3>
+ <table class="table table-bordered">
+ <thead>
+ <tr>
+ <th>Event</th>
+ <th>Comments</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for event in single_date_events %}
+ <tr>
+ <td>{{ event.short_description }}</td>
+ <td>{{ event.comments }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ </div>
</div>
-
-</div>
-<!-- End Action buttons -->
-{% endif %}
-
-
-</div>
{% endblock content %}
diff --git a/ctrack/users/tests/test_views.py b/ctrack/users/tests/test_views.py
index 7b5343f..5d158fe 100644
--- a/ctrack/users/tests/test_views.py
+++ b/ctrack/users/tests/test_views.py
@@ -1,13 +1,48 @@
import pytest
from django.contrib.auth.models import Permission
-from django.test import RequestFactory
+from django.test import RequestFactory, TestCase
+from django.urls import reverse
from ctrack.core.views import home_page
+from ctrack.register.models import SingleDateTimeEvent
from ctrack.users.models import User
from ctrack.users.views import UserDetailView, UserRedirectView, UserUpdateView
pytestmark = pytest.mark.django_db
+test_case = TestCase("run")
+
+
+class TestUserProfilePage:
+
+ def test_their_full_name_in_h3(self, user: User, client):
+ full_name = user.name
+ client.force_login(user)
+ response = client.get(reverse("users:detail", args=[user.username]))
+ assert response.status_code == 200
+ html = response.content.decode("utf-8")
+ test_string = f"<h3>{full_name}</h3>"
+ assert test_string in html
+
+ def test_view_has_all_events_related_to_user(self, user, client):
+ SingleDateTimeEvent.objects.create(
+ type_descriptor="PHONE_CALL",
+ short_description="Important event",
+ url="http://fake.url.com",
+ requested_response_date="2021-01-24",
+ response_received_date=None,
+ datetime="2020-10-10T15:00",
+ comments="Comments on important event",
+ # location is optional
+ user=user,
+ )
+ client.force_login(user)
+ response = client.get(reverse("users:detail", args=[user.username]))
+ assert response.status_code == 200
+ html = response.content.decode("utf-8")
+ test_case.assertInHTML("Comments on important event", html)
+
+
class TestUserUpdateView:
"""
@@ -87,25 +122,23 @@ def test_home_page_h1_tag_with_client(client, django_user_model):
client.login(username="toss", password="knob")
response = client.get("/")
assert response.status_code == 200
- assert b"<title>ctrack - Department for Transport</title>" in response.content
- # assert b"<h1>Welcome to ctrack - Department for Transport</h1>" in response.content
+ assert b"<title>ctrack - NIS Tracker</title>" in response.content
assert b"</html>" in response.content
-@pytest.mark.skip("Need to examine the HTML for this to work. Minor test.")
def test_regular_user_redirected_to_their_template_on_login(
django_user_model, request_factory: RequestFactory
):
"""
- When a user logs in without a stakeholder mapping, they get sent to the regular user
- template.
+ When a user logs in without a stakeholder mapping, they get sent to the site home
+ page.
"""
user = django_user_model.objects.create_user(username="toss", password="knob")
request = request_factory.get("/")
request.user = user
response = home_page(request)
assert response.status_code == 200
- assert b"<p>THIS IS A TEMPLATE FOR A REGULAR USER</p>" in response.content
+ assert b'<h1 class="display-3">ctrack</h1>' in response.content
def test_stakeholder_redirected_to_their_template_on_login(
diff --git a/ctrack/users/views.py b/ctrack/users/views.py
index 883cfb5..3ca574a 100644
--- a/ctrack/users/views.py
+++ b/ctrack/users/views.py
@@ -5,11 +5,12 @@ from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.views.generic import DetailView, RedirectView, UpdateView
+from ctrack.register.models import SingleDateTimeEvent
+
User = get_user_model()
class UserDetailView(DetailView):
-
model = User
# This names the field in the model that contains the slug. Want it to be thise so that is a good
@@ -20,12 +21,18 @@ class UserDetailView(DetailView):
# we have to pass 'username' as the argument when testing UserDetailView because of this.
slug_url_kwarg = "username"
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data()
+ user = self.request.user
+ single_date_events = SingleDateTimeEvent.objects.filter(user=user).all()
+ context["single_date_events"] = single_date_events
+ return context
+
user_detail_view = UserDetailView.as_view()
class UserUpdateView(UpdateView):
-
model = User
fields = ["name", "first_name", "last_name"]
@@ -46,7 +53,6 @@ user_update_view = UserUpdateView.as_view()
class UserRedirectView(RedirectView):
-
permanent = False
def get_redirect_url(self):