diff --git a/hc/accounts/tests/test_add_project.py b/hc/accounts/tests/test_add_project.py index 3e5709c1..6835edaa 100644 --- a/hc/accounts/tests/test_add_project.py +++ b/hc/accounts/tests/test_add_project.py @@ -2,12 +2,7 @@ from hc.accounts.models import Project from hc.test import BaseTestCase -class RemoveProjectTestCase(BaseTestCase): - def setUp(self): - super(RemoveProjectTestCase, self).setUp() - - self.url = "/projects/%s/remove/" % self.project.code - +class AddProjectTestCase(BaseTestCase): def test_it_works(self): self.client.login(username="alice@example.org", password="password") r = self.client.post("/projects/add/", {"name": "My Second Project"}) @@ -16,10 +11,6 @@ class RemoveProjectTestCase(BaseTestCase): self.assertRedirects(r, "/projects/%s/checks/" % p.code) self.assertEqual(str(p.code), p.badge_key) - # Alice's current project should be the just created one - self.profile.refresh_from_db() - self.assertEqual(self.profile.current_project, p) - def test_it_rejects_get(self): self.client.login(username="alice@example.org", password="password") r = self.client.get("/projects/add/") diff --git a/hc/front/tests/test_my_checks.py b/hc/front/tests/test_my_checks.py index 5814c44b..c16908f3 100644 --- a/hc/front/tests/test_my_checks.py +++ b/hc/front/tests/test_my_checks.py @@ -34,16 +34,12 @@ class MyChecksTestCase(BaseTestCase): delta = timezone.now() - self.profile.last_active_date self.assertTrue(delta.total_seconds() < 1) - def test_it_updates_current_project(self): - self.profile.current_project = None - self.profile.save() - + def test_it_updates_session(self): self.client.login(username="alice@example.org", password="password") r = self.client.get(self.url) self.assertEqual(r.status_code, 200) - self.profile.refresh_from_db() - self.assertEqual(self.profile.current_project, self.project) + self.assertEqual(self.client.session["last_project_id"], self.project.id) def test_it_checks_access(self): self.client.login(username="charlie@example.org", password="password") diff --git a/hc/front/tests/test_transfer.py b/hc/front/tests/test_transfer.py index 952cce54..f874f49e 100644 --- a/hc/front/tests/test_transfer.py +++ b/hc/front/tests/test_transfer.py @@ -2,9 +2,9 @@ from hc.api.models import Channel, Check from hc.test import BaseTestCase -class TrabsferTestCase(BaseTestCase): +class TransferTestCase(BaseTestCase): def setUp(self): - super(TrabsferTestCase, self).setUp() + super(TransferTestCase, self).setUp() self.check = Check.objects.create(project=self.bobs_project) self.url = "/checks/%s/transfer/" % self.check.code @@ -15,9 +15,6 @@ class TrabsferTestCase(BaseTestCase): self.assertContains(r, "Transfer to Another Project") def test_it_works(self): - self.bobs_profile.current_project = self.bobs_project - self.bobs_profile.save() - self.client.login(username="bob@example.org", password="password") payload = {"project": self.project.code} r = self.client.post(self.url, payload, follow=True) @@ -27,10 +24,6 @@ class TrabsferTestCase(BaseTestCase): check = Check.objects.get() self.assertEqual(check.project, self.project) - # Bob's current project should have been updated - self.bobs_profile.refresh_from_db() - self.assertEqual(self.bobs_profile.current_project, self.project) - def test_it_obeys_check_limit(self): # Alice's projects cannot accept checks due to limits: self.profile.check_limit = 0 diff --git a/hc/front/views.py b/hc/front/views.py index 2e84b765..636210aa 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -154,9 +154,8 @@ def my_checks(request, code): request.profile.sort = request.GET["sort"] request.profile.save() - if request.profile.current_project_id != project.id: - request.profile.current_project = project - request.profile.save() + if request.session.get("last_project_id") != project.id: + request.session["last_project_id"] = project.id q = Check.objects.filter(project=project) checks = list(q.prefetch_related("channel_set")) @@ -257,7 +256,12 @@ def index(request): if request.user.is_authenticated: projects = list(request.profile.projects()) - ctx = {"page": "projects", "projects": projects} + ctx = { + "page": "projects", + "projects": projects, + "last_project_id": request.session.get("last_project_id"), + } + return render(request, "front/projects.html", ctx) check = Check() @@ -555,14 +559,9 @@ def transfer(request, code): check.project = target_project check.save() - check.assign_all_channels() - request.profile.current_project = target_project - request.profile.save() - messages.success(request, "Check transferred successfully!") - return redirect("hc-details", code) ctx = {"check": check} diff --git a/templates/front/projects.html b/templates/front/projects.html index e6ca2e26..a734b89d 100644 --- a/templates/front/projects.html +++ b/templates/front/projects.html @@ -15,7 +15,7 @@ {% for project in projects %}
-
+

{{ project }}