blob: bba6fd47a8b9ff2cced90c5817ec60b0259b10fa (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
"""
Return a list of all publicly discoverable forms to unauthenticated users.
"""
from starlette.requests import Request
from starlette.responses import JSONResponse
from backend.models import Form
from backend.route import Route
class DiscoverableFormsList(Route):
"""
List all discoverable forms that should be shown on the homepage.
"""
name = "discoverable_forms_list"
path = "/discoverable"
async def get(self, request: Request) -> JSONResponse:
forms = []
cursor = request.state.db.forms.find({"features": "DISCOVERABLE"})
# Parse it to Form and then back to dictionary
# to replace _id with id
for form in await cursor.to_list(None):
forms.append(Form(**form))
forms = [form.dict(admin=False) for form in forms]
return JSONResponse(
forms
)
|