Browse Source

Optimize queries and fix team member sorting

pull/551/head
Pēteris Caune 3 years ago
parent
commit
bbd2786e0f
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
4 changed files with 10 additions and 10 deletions
  1. +0
    -3
      hc/accounts/models.py
  2. +2
    -1
      hc/accounts/tests/test_transfer_project.py
  3. +2
    -0
      hc/accounts/views.py
  4. +6
    -6
      templates/accounts/project.html

+ 0
- 3
hc/accounts/models.py View File

@ -338,9 +338,6 @@ class Project(models.Model):
self.api_key_readonly = token_urlsafe(nbytes=24)
self.save()
def team(self):
return User.objects.filter(memberships__project=self).order_by("email")
def invite_suggestions(self):
q = User.objects.filter(memberships__project__owner_id=self.owner_id)
q = q.exclude(memberships__project=self)


+ 2
- 1
hc/accounts/tests/test_transfer_project.py View File

@ -97,7 +97,8 @@ class TransferProjectTestCase(BaseTestCase):
self.assertEqual(self.project.owner, self.bob)
# Alice, the previous owner, should now be a member
self.assertTrue(self.project.team().filter(email="[email protected]").exists())
m = Member.objects.get(project=self.project, user=self.alice)
self.assertEqual(m.role, Member.Role.REGULAR)
def test_accept_requires_a_transfer_request(self):
self.client.login(username="[email protected]", password="password")


+ 2
- 0
hc/accounts/views.py View File

@ -457,6 +457,8 @@ def project(request, code):
tr.transfer_request_date = None
tr.save()
q = project.member_set.select_related("user").order_by("user__email")
ctx["memberships"] = list(q)
return render(request, "accounts/project.html", ctx)


+ 6
- 6
templates/accounts/project.html View File

@ -152,7 +152,7 @@
<div class="panel panel-{{ team_status|default:'default' }}">
<div class="panel-body settings-block">
<h2>Team Access</h2>
{% if project.team.exists or invite_suggestions %}
{% if memberships or invite_suggestions %}
<table id="team-table" class="table">
<tr>
<th>Email</th>
@ -164,7 +164,7 @@
<td>Owner</td>
<td></td>
</tr>
{% for m in project.member_set.all %}
{% for m in memberships %}
<tr>
<td class="email">{{ m.user.email }}</td>
<td>{{ m.get_role_display }}</td>
@ -514,7 +514,7 @@
</div>
</div>
{% if not transfer_request %}
{% if is_owner and not transfer_request %}
<div id="transfer-modal" class="modal">
<div class="modal-dialog">
<form
@ -529,7 +529,7 @@
</div>
<div class="modal-body">
{% if project.team %}
{% if memberships %}
<div class="form-group">
<label for="update-name-input" class="col-sm-4 control-label">
Choose owner
@ -540,8 +540,8 @@
name="email"
title="Select..."
class="form-control selectpicker">
{% for user in project.team %}
<option>{{ user.email }}</option>
{% for m in memberships %}
<option>{{ m.user.email }}</option>
{% endfor %}
</select>
</div>


Loading…
Cancel
Save