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.api_key_readonly = token_urlsafe(nbytes=24)
self.save() self.save()
def team(self):
return User.objects.filter(memberships__project=self).order_by("email")
def invite_suggestions(self): def invite_suggestions(self):
q = User.objects.filter(memberships__project__owner_id=self.owner_id) q = User.objects.filter(memberships__project__owner_id=self.owner_id)
q = q.exclude(memberships__project=self) 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) self.assertEqual(self.project.owner, self.bob)
# Alice, the previous owner, should now be a member # 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): def test_accept_requires_a_transfer_request(self):
self.client.login(username="[email protected]", password="password") 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.transfer_request_date = None
tr.save() tr.save()
q = project.member_set.select_related("user").order_by("user__email")
ctx["memberships"] = list(q)
return render(request, "accounts/project.html", ctx) 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 panel-{{ team_status|default:'default' }}">
<div class="panel-body settings-block"> <div class="panel-body settings-block">
<h2>Team Access</h2> <h2>Team Access</h2>
{% if project.team.exists or invite_suggestions %}
{% if memberships or invite_suggestions %}
<table id="team-table" class="table"> <table id="team-table" class="table">
<tr> <tr>
<th>Email</th> <th>Email</th>
@ -164,7 +164,7 @@
<td>Owner</td> <td>Owner</td>
<td></td> <td></td>
</tr> </tr>
{% for m in project.member_set.all %}
{% for m in memberships %}
<tr> <tr>
<td class="email">{{ m.user.email }}</td> <td class="email">{{ m.user.email }}</td>
<td>{{ m.get_role_display }}</td> <td>{{ m.get_role_display }}</td>
@ -514,7 +514,7 @@
</div> </div>
</div> </div>
{% if not transfer_request %}
{% if is_owner and not transfer_request %}
<div id="transfer-modal" class="modal"> <div id="transfer-modal" class="modal">
<div class="modal-dialog"> <div class="modal-dialog">
<form <form
@ -529,7 +529,7 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
{% if project.team %}
{% if memberships %}
<div class="form-group"> <div class="form-group">
<label for="update-name-input" class="col-sm-4 control-label"> <label for="update-name-input" class="col-sm-4 control-label">
Choose owner Choose owner
@ -540,8 +540,8 @@
name="email" name="email"
title="Select..." title="Select..."
class="form-control selectpicker"> class="form-control selectpicker">
{% for user in project.team %}
<option>{{ user.email }}</option>
{% for m in memberships %}
<option>{{ m.user.email }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>


Loading…
Cancel
Save