[dict(zip(r.keys(), r)) for r in users]
@contextmanager
def mongo_connection():
server = SSHTunnelForwarder(
'192.168.20.10',
ssh_username='username',
ssh_password='password',
remote_bind_address=('127.0.0.1', 27017))
server.start()
yield server
server.stop()
with mongo_connection() as server:
client = MongoClient('127.0.0.1', server.local_bind_port)
...
{% extends "mainApp/wrapper.html" %}
{% block content %}
<h1>Поиск</h1>
{% for article in article_lists %}
<article>
<a href="{{ article.get_absolute_url }}">
<h2>{{ article.article_title }}</h2>
</a>
{{ article.post|safe }}
<p><a class="btn btn-default btn-sm" href="{{ article.get_absolute_url }}">Читать далее</a></p>
</article>
{% empty %}
<p>Не найдено публикаций по вашему запросу<br>Попробуйте повторить запрос с другой формулировкой</p>
{% endfor %}
{% endblock %}
products = Product.objects.filter(is_main=True)
groups = [item.group_id for item in products]
children = Product.objects.filter(group_id__in=groups).order_by('group_id')
children = {
grouper: elements for grouper, elements in
groupby(children, key=lambda x: x.group_id)
}
for product in products:
product.children = children.get(product.group_id, [])
{% for p in products %}
<ul>
{% for c in p.children %}
<li>{{ c.name }}</li>
{% endfor %}
</ul>
{% endfor %}
@register.simple_tag(takes_context=True)
def dinamic(context, **kwargs):
request = context['request']
qparams = request.GET.dict()
qparams.update(**kwargs)
return '{}?{}'.format(request.path_info,
urlencode(qparams))