Compare commits

..

2 commits

Author SHA1 Message Date
Yohan Boniface
e3c6dcf3fa chore: add test for template_list view 2025-04-22 15:48:42 +02:00
Yohan Boniface
6de878551b wip: mark template maps in maps list 2025-04-22 15:42:41 +02:00
4 changed files with 63 additions and 4 deletions

View file

@ -165,7 +165,6 @@ h2.tabs a:hover {
min-height: var(--map-fragment-height);
}
.tag-list {
margin-top: var(--text-margin);
margin-bottom: var(--text-margin);
display: flex;
flex-wrap: wrap;
@ -205,6 +204,7 @@ h2.tabs a:hover {
margin-bottom: 0;
flex-grow: 1;
gap: var(--gutter);
margin-top: var(--text-margin);
}
.card h3 {
margin-bottom: 0;

View file

@ -12,14 +12,14 @@
{% endfor %}
</ul>
{% endif %}
<h3>{{ map_inst.name }}</h3>
<h3>{% if map_inst.is_template %}<mark class="template-map">[{% trans "template" %}]</mark>{% endif %} {{ map_inst.name }}</h3>
{% with author=map_inst.get_author %}
{% if author %}
<p>{% trans "by" %} <a href="{{ author.get_url }}">{{ author }}</a></p>
{% endif %}
{% endwith %}
</div>
<a class="main" href="{{ map_inst.get_absolute_url }}">{% translate "See the map" %}</a>
<a class="main" href="{{ map_inst.get_absolute_url }}">{% if map_inst.is_template %}{% translate "See the template" %}{% else %}{% translate "See the map" %}{% endif %}</a>
</hgroup>
</div>
{% endfor %}

View file

@ -528,3 +528,62 @@ def test_can_find_small_usernames(client):
data = json.loads(response.content)["data"]
assert len(data) == 1
assert data[0]["label"] == "JoeJoe"
@pytest.mark.django_db
def test_templates_list(client, user, user2):
public = MapFactory(
owner=user,
name="A public template",
share_status=Map.PUBLIC,
is_template=True,
)
link_only = MapFactory(
owner=user,
name="A link-only template",
share_status=Map.OPEN,
is_template=True,
)
private = MapFactory(
owner=user,
name="A link-only template",
share_status=Map.PRIVATE,
is_template=True,
)
someone_else = MapFactory(
owner=user2,
name="A public template from someone else",
share_status=Map.PUBLIC,
is_template=True,
)
staff = UserFactory(username="Staff", is_staff=True)
Star.objects.create(by=staff, map=someone_else)
client.login(username=user.username, password="123123")
url = reverse("template_list")
# Ask for mine
response = client.get(f"{url}?source=mine")
templates = json.loads(response.content)["templates"]
ids = [t["id"] for t in templates]
assert public.pk in ids
assert link_only.pk in ids
assert private.pk in ids
assert someone_else.pk not in ids
# Ask for staff ones
response = client.get(f"{url}?source=staff")
templates = json.loads(response.content)["templates"]
ids = [t["id"] for t in templates]
assert public.pk not in ids
assert link_only.pk not in ids
assert private.pk not in ids
assert someone_else.pk in ids
# Ask for community ones
response = client.get(f"{url}?source=community")
templates = json.loads(response.content)["templates"]
ids = [t["id"] for t in templates]
assert public.pk in ids
assert link_only.pk not in ids
assert private.pk not in ids
assert someone_else.pk in ids

View file

@ -1471,6 +1471,6 @@ class TemplateList(ListView):
"description": m.description,
"url": m.get_absolute_url(),
}
for m in qs
for m in qs.order_by("-modified_at")
]
return simple_json_response(templates=templates)