-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_page.py
36 lines (32 loc) · 1.28 KB
/
index_page.py
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
33
34
35
36
from typing import List
from django.urls import reverse
from reactpy import component, html
from reactpy_router import link
from ..models import Question
from .common import use_query, LoadingException, RecordNotFound
from .page_404 import Page_404
@component
def index():
@component
def QuestionCard(question):
return html.div({'class_name': 'card-mb-3'},
html.div({'class_name': 'card-body'},
html.p({'class_name': 'lead'}, question.question_text),
html.div({'class_name':'btn-group'},
link("Vote Now", to=reverse("polls:detail", kwargs={'pk': question.pk}), class_name='btn btn-primary btn-sm mx-1'),
link("Results", to=reverse("polls:results", kwargs={'pk': question.pk}), class_name='btn btn-secondary btn-sm'),
)
)
)
try:
questions: List[Question] = use_query(Question.get_ordered_questions)
return html.div(
html.h1({'class_name':"text-center mb-3"},"Poll Questions"),
*[QuestionCard(question) for question in questions]
)
except LoadingException as ex:
return html.h2(str(ex))
except RecordNotFound:
return html.h2("No polls available.")
except Exception:
return Page_404()