Как использовать jinja, чтобы сделать макрос для динамического c модального? - PullRequest
0 голосов
/ 10 апреля 2020

Я пытаюсь сделать всплывающее окно, когда пользователь нажимает кнопку c, указанную в запросе. После нажатия этой кнопки в макрос нужно отправить два значения данных: запрос (это переменная в моей базе данных) и кортеж (переменная, которая уже была создана для отображения).

Так выглядит страница, генерирующая запросы.

<div class="card mb-5 w-100">
    <img src="" id="requests-image" class="card-img-top">
    <div class="card-body">
      <h3 class="card-title">Requests Near: </h3>
      <p class="card-text">{{current_user.street}}, {{current_user.city}}</p>
      <ul class="list-group">
        {% if all_users_requests %}
          {% for tuple in all_users_requests %}
            {% for request in tuple[0] %}
              <a class="list-group-item">
                <div class="justify-content-between">
                  {{ request.item_name }}
                  <span style="float: right;" class="badge badge-secondary badge-pill">{{ request.quantity }}</span>
                </div>
                <small class="text-muted">{{ tuple[1] }} </small>
                {{ render_modal("request", "tuple") }}
                <button type="button" style = "float: right;" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#requestView">
                  View this Request
                </button>
              </a>
            {% endfor %}
          {% endfor %}
        {% else %}
            <img src="https://scontent-iad3-1.xx.fbcdn.net/v/t1.15752-0/p480x480/92476693_2688296751448986_2334854164678443008_n.jpg?_nc_cat=102&_nc_sid=b96e70&_nc_ohc=j0xkWJ4nstAAX_yxLPf&_nc_ht=scontent-iad3-1.xx&_nc_tp=6&oh=a5ae7f1d95f4fb1d793cd5d04d61bf4a&oe=5EB4894D" class="rounded float-right" style="width: 80%;">
            <p>There are currently no requests near you. Keep refreshing the page to find new ones!</p>
        {% endif %}
      </ul>
    </div>
  </div>

Для каждого запроса есть кнопка, и я хочу, чтобы кнопка передавала информацию, указанную c, в этот запрос всплывающее окно. Это выглядит так:

{% macro render_modal(request, tuple) -%}
<div class="modal fade" id="requestView" tabindex="-1" role="dialog" aria-labelledby="ModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="ModalLongTitle">Request View</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <h6> Item Name: </h6>
        <p>{{ request.item_name }}</p>
        <h6> Quantity: </h6>
        <p>{{ request.quantity }}</p>
        <h6> Special Instructions: </h6>
        <p>{{ request.instruct }}</p>
        <h6> Distance: </h6>
        <p>{{ tuple[1] }} </p>
        <h6> Estimated Time: </h6>
        <p>{{ tuple[0] }} </p>
      </div>
    </div>
  </div>
</div>
{%- endmacro %}

Проблема в том, что данные «запрос» и «кортеж» не передаются, и всплывающее окно не отображает их. Из того, что я могу сказать, похоже, что запрос и кортеж обрабатываются как строки, а не как переменные, но я понятия не имею, как это исправить.

...