Add basic search bar

This commit is contained in:
Skia 2016-08-19 02:53:44 +02:00
parent 0689f864d2
commit f1105d704e
13 changed files with 199 additions and 73 deletions

BIN
core/static/core/img/na.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -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;

View File

@ -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 %}

View File

@ -1,7 +1,8 @@
{% 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 %}

View File

@ -1,3 +1,16 @@
{% 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 %}

View File

@ -0,0 +1,26 @@
{% 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 %}

View File

@ -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 %}

View File

@ -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'),
]

View File

@ -1,11 +1,46 @@
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))

View File

@ -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):

Binary file not shown.

View File

@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-08-18 17:40+0200\n"
"POT-Creation-Date: 2016-08-19 01:43+0200\n"
"PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Skia <skia@libskia.so>\n"
"Language-Team: AE info <ae.info@utbm.fr>\n"
@ -40,12 +40,12 @@ msgstr "numero de compte"
msgid "%(club_account)s on %(bank_account)s"
msgstr "%(club_account)s sur %(bank_account)s"
#: accounting/models.py:109 club/models.py:147 counter/models.py:271
#: accounting/models.py:109 club/models.py:147 counter/models.py:291
#: launderette/models.py:122
msgid "start date"
msgstr "date de début"
#: accounting/models.py:110 club/models.py:148 counter/models.py:272
#: accounting/models.py:110 club/models.py:148 counter/models.py:292
msgid "end date"
msgstr "date de fin"
@ -67,12 +67,12 @@ msgid "number"
msgstr "numéro"
#: accounting/models.py:154 core/models.py:404 core/models.py:680
#: counter/models.py:209 counter/models.py:245 eboutic/models.py:14
#: counter/models.py:209 counter/models.py:255 eboutic/models.py:14
#: eboutic/models.py:47
msgid "date"
msgstr "date"
#: accounting/models.py:155 accounting/models.py:241 counter/models.py:237
#: accounting/models.py:155 accounting/models.py:241 counter/models.py:247
msgid "label"
msgstr "intitulé"
@ -80,8 +80,8 @@ msgstr "intitulé"
msgid "remark"
msgstr "remarque"
#: accounting/models.py:157 counter/models.py:210 counter/models.py:247
#: eboutic/models.py:49 subscription/models.py:34
#: accounting/models.py:157 counter/models.py:210 counter/models.py:256
#: subscription/models.py:34
msgid "payment method"
msgstr "méthode de paiement"
@ -89,7 +89,7 @@ msgstr "méthode de paiement"
msgid "cheque number"
msgstr "numéro de chèque"
#: accounting/models.py:159 eboutic/models.py:119
#: accounting/models.py:159 eboutic/models.py:115
msgid "invoice"
msgstr "facture"
@ -114,7 +114,7 @@ msgstr "Utilisateur"
msgid "Club"
msgstr "Club"
#: accounting/models.py:163 core/templates/core/user_base.jinja:17
#: accounting/models.py:163 core/templates/core/user_base.jinja:18
msgid "Account"
msgstr "Compte"
@ -207,7 +207,7 @@ msgstr "Nouveau compte club"
#: accounting/templates/accounting/club_account_details.jinja:44
#: accounting/templates/accounting/journal_details.jinja:62
#: club/templates/club/club_detail.jinja:7 core/templates/core/file.jinja:38
#: core/templates/core/page.jinja:31 core/templates/core/user_base.jinja:9
#: core/templates/core/page.jinja:31 core/templates/core/user_base.jinja:10
#: core/templates/core/user_tools.jinja:33
#: counter/templates/counter/counter_list.jinja:15
#: counter/templates/counter/counter_list.jinja:18
@ -269,7 +269,7 @@ msgstr "Fin"
#: accounting/templates/accounting/club_account_details.jinja:20
#: accounting/templates/accounting/journal_details.jinja:23
#: core/templates/core/user_account.jinja:19
#: core/templates/core/user_account.jinja:72
#: core/templates/core/user_account.jinja:78
msgid "Amount"
msgstr "Montant"
@ -324,13 +324,13 @@ msgstr "No"
#: accounting/templates/accounting/journal_details.jinja:21
#: core/templates/core/user_account.jinja:16
#: core/templates/core/user_account.jinja:41
#: core/templates/core/user_account.jinja:70
#: core/templates/core/user_account.jinja:44
#: core/templates/core/user_account.jinja:76
msgid "Date"
msgstr "Date"
#: accounting/templates/accounting/journal_details.jinja:22
#: core/templates/core/user_account.jinja:44
#: core/templates/core/user_account.jinja:47
msgid "Label"
msgstr "Intitulé"
@ -908,7 +908,7 @@ msgstr "Outils"
msgid "Logout"
msgstr "Déconnexion"
#: core/templates/core/base.jinja:36
#: core/templates/core/base.jinja:36 core/templates/core/search.jinja:10
msgid "Users"
msgstr "Utilisateurs"
@ -920,7 +920,7 @@ msgstr "Wiki"
msgid "Pages"
msgstr "Pages"
#: core/templates/core/base.jinja:39
#: core/templates/core/base.jinja:39 core/templates/core/search.jinja:18
msgid "Clubs"
msgstr "Clubs"
@ -938,23 +938,25 @@ msgid "Create %(name)s"
msgstr "Créer %(name)s"
#: core/templates/core/delete_confirm.jinja:4
#: core/templates/core/delete_confirm.jinja:8
#: core/templates/core/file_delete_confirm.jinja:4
#: core/templates/core/file_delete_confirm.jinja:8
msgid "Delete confirmation"
msgstr "Confirmation de suppression"
#: core/templates/core/delete_confirm.jinja:6
#: core/templates/core/file_delete_confirm.jinja:6
#: core/templates/core/delete_confirm.jinja:10
#: core/templates/core/file_delete_confirm.jinja:10
#, python-format
msgid "Are you sure you want to delete \"%(obj)s\"?"
msgstr "Êtes-vous sûr de vouloir supprimer \"%(obj)s\" ?"
#: core/templates/core/delete_confirm.jinja:7
#: core/templates/core/file_delete_confirm.jinja:7
#: core/templates/core/delete_confirm.jinja:11
#: core/templates/core/file_delete_confirm.jinja:11
msgid "Confirm"
msgstr "Confirmation"
#: core/templates/core/delete_confirm.jinja:8
#: core/templates/core/file_delete_confirm.jinja:8
#: core/templates/core/delete_confirm.jinja:14
#: core/templates/core/file_delete_confirm.jinja:14
#: counter/templates/counter/counter_click.jinja:71
msgid "Cancel"
msgstr "Annuler"
@ -1067,6 +1069,13 @@ msgstr "login"
msgid "Lost password?"
msgstr "Mot de passe perdu ?"
#: core/templates/core/macros.jinja:9 core/templates/core/macros.jinja:11
#: core/templates/core/user_detail.jinja:12
#: core/templates/core/user_edit.jinja:15
#: core/templates/core/user_mini.jinja:4
msgid "Profile"
msgstr "Profil"
#: core/templates/core/page.jinja:7 core/templates/core/page_list.jinja:4
#: core/templates/core/page_list.jinja:9
msgid "Page list"
@ -1219,6 +1228,10 @@ msgstr ""
msgid "Your username is %(username)s."
msgstr "Votre nom d'utilisateur est %(username)s."
#: core/templates/core/search.jinja:6
msgid "Search result"
msgstr "Résultat de la recherche"
#: core/templates/core/user_account.jinja:4
#, python-format
msgid "%(user_name)s's account"
@ -1233,47 +1246,50 @@ msgid "Refillings"
msgstr "Rechargements"
#: core/templates/core/user_account.jinja:17
#: core/templates/core/user_account.jinja:42
#: core/templates/core/user_account.jinja:45
#: counter/templates/counter/counter_click.jinja:24
msgid "Counter"
msgstr "Comptoir"
#: core/templates/core/user_account.jinja:18
#: core/templates/core/user_account.jinja:43
#: core/templates/core/user_account.jinja:46
msgid "Barman"
msgstr "Barman"
#: core/templates/core/user_account.jinja:20
#: core/templates/core/user_account.jinja:47
#: core/templates/core/user_account.jinja:73
#: core/templates/core/user_account.jinja:50
msgid "Payment method"
msgstr "Méthode de paiement"
#: core/templates/core/user_account.jinja:37
#: core/templates/core/user_account.jinja:40
msgid "Account buyings"
msgstr "Achat sur compte utilisateur"
#: core/templates/core/user_account.jinja:45
#: core/templates/core/user_account.jinja:48
msgid "Quantity"
msgstr "Quantité"
#: core/templates/core/user_account.jinja:46
#: core/templates/core/user_account.jinja:49
msgid "Total"
msgstr "Total"
#: core/templates/core/user_account.jinja:66
#: core/templates/core/user_account.jinja:72
msgid "Eboutic invoices"
msgstr "Facture eboutic"
#: core/templates/core/user_account.jinja:71
#: core/templates/core/user_account.jinja:77
msgid "Items"
msgstr "Articles"
#: core/templates/core/user_account.jinja:95
#: core/templates/core/user_account.jinja:99
msgid "User has no account"
msgstr "L'utilisateur n'a pas de compte"
#: core/templates/core/user_base.jinja:12
#: core/templates/core/user_base.jinja:8
msgid "Stats"
msgstr "Stats"
#: core/templates/core/user_base.jinja:13
#: core/templates/core/user_tools.jinja:14
msgid "Groups"
msgstr "Groupes"
@ -1283,12 +1299,6 @@ msgstr "Groupes"
msgid "%(user_name)s's profile"
msgstr "Profil de %(user_name)s"
#: core/templates/core/user_detail.jinja:12
#: core/templates/core/user_edit.jinja:15
#: core/templates/core/user_mini.jinja:4
msgid "Profile"
msgstr "Profil"
#: core/templates/core/user_detail.jinja:21
#: core/templates/core/user_mini.jinja:12
msgid "Born: "
@ -1371,6 +1381,10 @@ msgstr "Éditer les groupes pour %(user_name)s"
msgid "User list"
msgstr "Liste d'utilisateurs"
#: core/templates/core/user_stats.jinja:4
msgid "%(user_name)s's stats"
msgstr "Stats de %(user_name)s"
#: core/templates/core/user_tools.jinja:4
#, python-format
msgid "%(user_name)s's tools"
@ -1522,7 +1536,7 @@ msgstr "comptoir"
msgid "bank"
msgstr "banque"
#: counter/models.py:214 counter/models.py:246
#: counter/models.py:214 counter/models.py:258
msgid "is validated"
msgstr "est validé"
@ -1530,29 +1544,29 @@ msgstr "est validé"
msgid "refilling"
msgstr "rechargement"
#: counter/models.py:241 eboutic/models.py:106
#: counter/models.py:251 eboutic/models.py:102
msgid "unit price"
msgstr "prix unitaire"
#: counter/models.py:242 eboutic/models.py:107
#: counter/models.py:252 eboutic/models.py:103
msgid "quantity"
msgstr "quantité"
#: counter/models.py:248 eboutic/models.py:48
#: counter/models.py:257
msgid "Sith account"
msgstr "Compte utilisateur"
#: counter/models.py:248 eboutic/models.py:48 sith/settings.py:272
#: sith/settings.py:277 sith/settings.py:298 sith/settings_sample.py:258
#: counter/models.py:257 sith/settings.py:272 sith/settings.py:277
#: sith/settings.py:298 sith/settings_sample.py:258
#: sith/settings_sample.py:263 sith/settings_sample.py:284
msgid "Credit card"
msgstr "Carte banquaire"
#: counter/models.py:251
#: counter/models.py:261
msgid "selling"
msgstr "vente"
#: counter/models.py:275
#: counter/models.py:295
msgid "permanency"
msgstr "permanence"
@ -1597,7 +1611,6 @@ msgid "Finish"
msgstr "Terminer"
#: counter/templates/counter/counter_click.jinja:73
#: eboutic/templates/eboutic/eboutic_main.jinja:41
msgid "Products: "
msgstr "Produits : "
@ -1694,27 +1707,27 @@ msgstr "ANN"
msgid "You have not enough money to buy all the basket"
msgstr "Vous n'avez pas assez d'argent pour acheter le panier"
#: eboutic/models.py:50
#: eboutic/models.py:48
msgid "validated"
msgstr "validé"
#: eboutic/models.py:60
#: eboutic/models.py:61
msgid "Invoice already validated"
msgstr "Facture déjà validée"
#: eboutic/models.py:103
#: eboutic/models.py:99
msgid "product id"
msgstr "ID du produit"
#: eboutic/models.py:104
#: eboutic/models.py:100
msgid "product name"
msgstr "nom du produit"
#: eboutic/models.py:105
#: eboutic/models.py:101
msgid "product type id"
msgstr "id du type du produit"
#: eboutic/models.py:116
#: eboutic/models.py:112
msgid "basket"
msgstr "panier"
@ -2047,4 +2060,3 @@ msgstr "Un utilisateur avec cette adresse email existe déjà"
msgid "You must either choose an existing user or create a new one properly"
msgstr ""
"Vous devez soit choisir un utilisateur existant, ou en créer un proprement."

View File

@ -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__":