mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Add basic search bar
This commit is contained in:
BIN
core/static/core/img/na.gif
Normal file
BIN
core/static/core/img/na.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
@ -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 %}
|
||||
|
@ -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 %}
|
||||
|
@ -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 %}
|
||||
|
26
core/templates/core/search.jinja
Normal file
26
core/templates/core/search.jinja
Normal 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 %}
|
@ -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'),
|
||||
|
||||
]
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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):
|
||||
|
Reference in New Issue
Block a user