Commit f1105d70 authored by Skia's avatar Skia

Add basic search bar

parent 0689f864
Pipeline #122 failed with stage
in 3 minutes and 2 seconds
......@@ -26,7 +26,11 @@ header a {
header a:hover {
color: #2D3;
}
header form {
display: inline-block;
padding: 1em;
width: 150px;
}
#popupheader {
width: 88%;
margin: 0px auto;
......@@ -185,6 +189,24 @@ tbody>tr:hover {
#user_profile .promo_pict {
height: 45px;
}
.mini_profile_link {
display: block;
text-decoration: none;
}
.mini_profile_link span {
display: inline-block;
width: 50px;
vertical-align: middle;
}
.mini_profile_link em {
vertical-align: middle;
}
.mini_profile_link img {
max-width: 40px;
max-height: 60px;
margin: 2px auto;
display: block;
}
/*---------------------------------PAGE--------------------------------*/
.page_content {
display: block;
......
......@@ -24,6 +24,10 @@
<a href="{{ url('core:user_profile', user_id=user.id) }}">{{ user.get_display_name() }}</a> |
<a href="{{ url('core:user_tools') }}">{% trans %}Tools{% endtrans %}</a> |
<a href="{{ url('core:logout') }}">{% trans %}Logout{% endtrans %}</a>
<form action="{{ url('core:search') }}" method="GET">
<input type="text" placeholder="{% trans %}Search{% endtrans %}" name="query" />
<input type="submit" value="{% trans %}Search{% endtrans %}" style="display: none;" />
</form>
{% endif %}
</header>
{% else %}
......
{% extends "core/base.jinja" %}
{% block title %}{{ title }}{% endblock %}
{% block title %}
{% trans %}Welcome!{% endtrans %}
{% endblock %}
{% block content %}
{% trans %}Hello, world. You're at the core index using Jinja2.{% endtrans %}
{% endblock %}
{% macro user_profile_link(user) -%}
<a href="{{ url("core:user_profile", user_id=user.id) }}">{{ user.get_display_name() }}</a>
{%- endmacro %}
{% macro user_link_with_pict(user) -%}
<a href="{{ url("core:user_profile", user_id=user.id) }}" class="mini_profile_link" >
<span>
{% if user.profile_pict %}
<img src="{{ user.profile_pict.get_download_url() }}" alt="{% trans %}Profile{% endtrans %}" />
{% else %}
<img src="{{ static('core/img/na.gif') }}" alt="{% trans %}Profile{% endtrans %}" />
{% endif %}
</span>
<em>{{ user.get_display_name() }}</em>
</a>
{%- endmacro %}
{% extends "core/base.jinja" %}
{% from "core/macros.jinja" import user_link_with_pict %}
{% block title %}
{% trans %}Search result{% endtrans %}
{% endblock %}
{% block content %}
<h4>{% trans %}Users{% endtrans %}</h4>
<ul>
{% for i in result.users %}
<li>
{{ user_link_with_pict(i) }}
</li>
{% endfor %}
</ul>
<h4>{% trans %}Clubs{% endtrans %}</h4>
<ul>
{% for i in result.clubs %}
<li>
<a href="{{ url("club:club_view", club_id=i.id) }}">{{ i }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
......@@ -8,9 +8,10 @@
{% if profile.permanencies %}
<div>
<h3>Permanencies</h3>
<p>
{{ total_time }}
</p>
<p>Total: {{ total_perm_time }}</p>
<p>Foyer: {{ total_foyer_time }}</p>
<p>MDE: {{ total_mde_time }}</p>
<p>La Gommette: {{ total_gommette_time }}</p>
</div>
{% endif %}
{% endblock %}
......
......@@ -4,6 +4,8 @@ from core.views import *
urlpatterns = [
url(r'^$', index, name='index'),
url(r'^search/$', search_view, name='search'),
url(r'^search_json/$', search_json, name='search_json'),
# Login and co
url(r'^login/$', login, name='login'),
......@@ -50,5 +52,4 @@ urlpatterns = [
url(r'^page/(?P<page_name>[a-z0-9/-_]*)/hist$', PageHistView.as_view(), name='page_hist'),
url(r'^page/(?P<page_name>[a-z0-9/-_]*)/rev/(?P<rev>[0-9]+)/', PageRevView.as_view(), name='page_rev'),
url(r'^page/(?P<page_name>[a-z0-9/-_]*)/$', PageView.as_view(), name='page'),
]
from django.shortcuts import render, redirect, get_object_or_404
from django.db import models
from django.http import JsonResponse
from django.core import serializers
from django.db.models import Q
from django.contrib.auth.decorators import login_required
import os
import json
from itertools import chain
from core.models import User
from club.models import Club
def index(request, context=None):
if context == None:
return render(request, "core/index.jinja", {'title': 'Bienvenue!'})
else:
return render(request, "core/index.jinja", context)
return render(request, "core/index.jinja")
def search(query, as_json=False):
result = {'users': None, 'clubs': None}
if query:
nicks = User.objects.filter(nick_name__icontains=query).all()
users = User.objects.filter(Q(first_name__icontains=query) | Q(last_name__icontains=query)).all()
clubs = Club.objects.filter(name__icontains=query).all()
nicks = nicks[:5]
users = users[:5]
clubs = clubs[:5]
if as_json: # Re-loads json to avoid double encoding by JsonResponse, but still benefit from serializers
nicks = json.loads(serializers.serialize('json', nicks, fields=('nick_name', 'last_name', 'first_name', 'profile_pict')))
users = json.loads(serializers.serialize('json', users, fields=('nick_name', 'last_name', 'first_name', 'profile_pict')))
clubs = json.loads(serializers.serialize('json', clubs, fields=('name')))
else:
nicks = list(nicks.all())
users = list(users.all())
clubs = list(clubs.all())
result['users'] = nicks + users
result['clubs'] = clubs
return result
@login_required
def search_view(request):
return render(request, "core/search.jinja", context={'result': search(request.GET.get('query', ''))})
@login_required
def search_json(request):
return JsonResponse(search(request.GET.get('query', ''), True))
......@@ -134,7 +134,14 @@ class UserStatsView(CanViewMixin, DetailView):
def get_context_data(self, **kwargs):
kwargs = super(UserStatsView, self).get_context_data(**kwargs)
kwargs['total_time'] = sum([p.end-p.start for p in self.object.permanencies.all()], timedelta())
from counter.models import Counter
foyer = Counter.objects.filter(name="Foyer").first()
mde = Counter.objects.filter(name="MDE").first()
gommette = Counter.objects.filter(name="La Gommette").first()
kwargs['total_perm_time'] = sum([p.end-p.start for p in self.object.permanencies.all()], timedelta())
kwargs['total_foyer_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=foyer)], timedelta())
kwargs['total_mde_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=mde)], timedelta())
kwargs['total_gommette_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=gommette)], timedelta())
return kwargs
class UserMiniView(CanViewMixin, DetailView):
......
This diff is collapsed.
......@@ -513,13 +513,17 @@ def migrate_sellings():
""")
Selling.objects.filter(payment_method="SITH_ACCOUNT").delete()
print("Sith account selling deleted")
ae = Club.objects.filter(unix_name="ae").first()
mde = Counter.objects.filter(id=1).first()
root = User.objects.filter(id=0).first()
beer = Product.objects.filter(id=1).first()
for r in cur:
try:
product = Product.objects.filter(id=r['id_produit']).first()
club = Club.objects.filter(id=r['id_assocpt']).first()
counter = Counter.objects.filter(id=r['id_comptoir']).first()
op = User.objects.filter(id=r['id_utilisateur']).first()
customer = Customer.objects.filter(user__id=r['id_utilisateur_client']).first()
product = Product.objects.filter(id=r['id_produit']).first() or beer
club = Club.objects.filter(id=r['id_assocpt']).first() or ae
counter = Counter.objects.filter(id=r['id_comptoir']).first() or mde
op = User.objects.filter(id=r['id_utilisateur']).first() or root
customer = Customer.objects.filter(user__id=r['id_utilisateur_client']).first() or root.customer
new = Selling(
label=product.name,
counter=counter,
......@@ -570,6 +574,7 @@ def main():
# migrate_subscriptions()
# update_customer_account()
# migrate_counters()
# migrate_permanencies()
# migrate_typeproducts()
# migrate_products()
# migrate_products_to_counter()
......@@ -577,7 +582,6 @@ def main():
# migrate_invoices()
# migrate_refillings()
# migrate_sellings()
# migrate_permanencies()
reset_index('core', 'counter')
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment