Merge branch 'k-fet' of git.eleves.ens.fr:cof-geek/gestioCOF into Aufinal/visibilite_stock

This commit is contained in:
Ludovic Stephan 2017-02-05 19:56:34 -02:00
commit 95e96d8ce5
8 changed files with 229 additions and 113 deletions

View file

@ -1,9 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from django.shortcuts import render
from django.http import Http404
from django.db.models import Q
@ -11,6 +7,7 @@ from gestioncof.models import User, Clipper
from kfet.decorators import teamkfet_required
from kfet.models import Account
@teamkfet_required
def account_create(request):
if "q" not in request.GET:
@ -32,31 +29,31 @@ def account_create(request):
for word in search_words:
queries['kfet'] = queries['kfet'].filter(
Q(cofprofile__user__username__icontains = word)
| Q(cofprofile__user__first_name__icontains = word)
| Q(cofprofile__user__last_name__icontains = word)
Q(cofprofile__user__username__icontains=word) |
Q(cofprofile__user__first_name__icontains=word) |
Q(cofprofile__user__last_name__icontains=word)
)
queries['users_cof'] = queries['users_cof'].filter(
Q(username__icontains = word)
| Q(first_name__icontains = word)
| Q(last_name__icontains = word)
Q(username__icontains=word) |
Q(first_name__icontains=word) |
Q(last_name__icontains=word)
)
queries['users_notcof'] = queries['users_notcof'].filter(
Q(username__icontains = word)
| Q(first_name__icontains = word)
| Q(last_name__icontains = word)
Q(username__icontains=word) |
Q(first_name__icontains=word) |
Q(last_name__icontains=word)
)
queries['clippers'] = queries['clippers'].filter(
Q(username__icontains = word)
| Q(fullname__icontains = word)
Q(username__icontains=word) |
Q(fullname__icontains=word)
)
queries['kfet'] = queries['kfet'].distinct()
usernames = list( \
usernames = list(
queries['kfet'].values_list('cofprofile__user__username', flat=True))
queries['kfet'] = [ (account, account.cofprofile.user) \
queries['kfet'] = [(account, account.cofprofile.user)
for account in queries['kfet']]
queries['users_cof'] = \
@ -64,9 +61,9 @@ def account_create(request):
queries['users_notcof'] = \
queries['users_notcof'].exclude(username__in=usernames).distinct()
usernames += list( \
usernames += list(
queries['users_cof'].values_list('username', flat=True))
usernames += list( \
usernames += list(
queries['users_notcof'].values_list('username', flat=True))
queries['clippers'] = \
@ -80,3 +77,25 @@ def account_create(request):
data['options'] = options
return render(request, "kfet/account_create_autocomplete.html", data)
def account_search(request):
if "q" not in request.GET:
raise Http404
q = request.GET.get("q")
words = q.split()
data = {'q': q}
for word in words:
query = Account.objects.filter(
Q(cofprofile__user__username__icontains=word) |
Q(cofprofile__user__first_name__icontains=word) |
Q(cofprofile__user__last_name__icontains=word)
).distinct()
query = [(account.trigramme, account.cofprofile.user.get_full_name())
for account in query]
data['accounts'] = query
return render(request, 'kfet/account_search_autocomplete.html', data)

View file

@ -1,21 +1,17 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from decimal import Decimal
from django import forms
from django.core.exceptions import ValidationError
from django.core.validators import MinLengthValidator
from django.contrib.auth.models import User, Group, Permission
from django.contrib.contenttypes.models import ContentType
from django.forms import modelformset_factory, inlineformset_factory
from django.forms.models import BaseInlineFormSet
from django.forms import modelformset_factory
from django.utils import timezone
from kfet.models import (Account, Checkout, Article, OperationGroup, Operation,
from kfet.models import (
Account, Checkout, Article, OperationGroup, Operation,
CheckoutStatement, ArticleCategory, Settings, AccountNegative, Transfer,
TransferGroup, Supplier, Inventory, InventoryArticle)
TransferGroup, Supplier)
from gestioncof.models import CofProfile
# -----
@ -131,7 +127,16 @@ class UserRestrictTeamForm(UserForm):
class UserGroupForm(forms.ModelForm):
groups = forms.ModelMultipleChoiceField(
Group.objects.filter(name__icontains='K-Fêt'))
Group.objects.filter(name__icontains='K-Fêt'),
required=False)
def clean_groups(self):
groups = self.cleaned_data.get('groups')
# Si aucun groupe, on le dénomme
if not groups:
groups = self.instance.groups.exclude(name__icontains='K-Fêt')
return groups
class Meta:
model = User
fields = ['groups']

View file

@ -83,3 +83,24 @@
padding-right: 50px;
padding-left: 50px;
}
/* Account autocomplete window */
#account_results ul {
list-style-type:none;
background:rgba(255,255,255,0.9);
padding:0;
}
#account_results li {
display:block;
padding:5px 20px;
height:100%;
width:100%;
}
#account_results .hilight {
background:rgba(200,16,46,0.9);
color:#fff;
text-decoration:none;
}

View file

@ -7,7 +7,7 @@
</a>
</li>
{% if kfet %}
<li class="user_category"><span class="text">Comptes existant</span></li>
<li class="user_category"><span class="text">Comptes existants</span></li>
{% for account, user in kfet %}
<li><span class="text">{{ account }} [{{ user|highlight_user:q }}]</span></li>
{% endfor %}

View file

@ -0,0 +1,14 @@
{% load kfet_tags %}
<ul>
{% if accounts %}
{% for trigramme, user in accounts %}
<li class='choice'>{{ user|highlight_text:q }} (<span class="trigramme">{{ trigramme }}</span>)</li>
{% endfor %}
{% elif not q %}
<li class="user_category"><span class="text">Pas de recherche, pas de résultats !</span></li>
{% else %}
<li class="user_category"><span class="text">Aucune correspondance trouvée :-(</span></li>
{% endif %}
</ul>

View file

@ -4,6 +4,7 @@
{% block extra_head %}
<link rel="stylesheet" style="text/css" href="{% static 'kfet/css/jquery-ui.min.css' %}">
<link rel="stylesheet" style="text/css" href="{% static 'kfet/css/kpsul_grid.css' %}">
<script src="{% static "autocomplete_light/autocomplete.js" %}" type="text/javascript"></script>
<script type="text/javascript" src="{% static 'kfet/js/js.cookie.js' %}"></script>
<script type="text/javascript" src="{% static 'kfet/js/reconnecting-websocket.js' %}"></script>
<script type="text/javascript" src="{% static 'kfet/js/jquery-ui.min.js' %}"></script>
@ -261,12 +262,56 @@ $(document).ready(function() {
buttons += '<a href="'+url_base+'?trigramme='+trigramme+'" class="btn btn-primary" target="_blank" title="Créer"><span class="glyphicon glyphicon-plus"></span></a>';
} else {
var url_base = '{% url 'kfet.account' %}'
buttons += '<a href="'+url_base+'" class="btn btn-primary" target="_blank" title="Rechercher"><span class="glyphicon glyphicon-search"></span></a>';
buttons += '<button class="btn btn-primary search" title="Rechercher"><span class="glyphicon glyphicon-search"></span></button>';
}
}
account_container.find('.buttons').html(buttons);
}
// Search for an account
function searchAccount() {
var content = '<input type="text" name="q" id="search_autocomplete" spellcheck="false" autofocus><div id="account_results"></div>' ;
$.dialog({
title: 'Recherche de compte',
content: content,
backgroundDismiss: true,
animation: 'top',
closeAnimation: 'bottom',
keyboardEnabled: true,
onOpen: function() {
var that=this ;
$('input#search_autocomplete').yourlabsAutocomplete({
url: '{% url "kfet.account.search.autocomplete" %}',
minimumCharacters: 2,
id: 'search_autocomplete',
choiceSelector: '.choice',
placeholder: "Chercher un utilisateur K-Fêt",
box: $("#account_results"),
});
$('input#search_autocomplete').bind(
'selectChoice',
function(e, choice, autocomplete) {
autocomplete.hide() ;
triInput.val(choice.find('.trigramme').text()) ;
triInput.trigger('input') ;
that.close() ;
});
}
});
}
account_container.on('click', '.search', function () {
searchAccount() ;
}) ;
account_container.on('keydown', function(e) {
if (e.which == 70 && e.ctrlKey) {
// Ctrl + F : universal search shortcut
searchAccount() ;
e.preventDefault() ;
}
});
// Clear data
function resetAccountData() {
account_data = account_data_default;
@ -992,7 +1037,7 @@ $(document).ready(function() {
var title = is_checkout ? 'Montant de la charge' : "Montant de l'édition";
$.confirm({
title: title,
content: '<input type="number" step="0.01" min="0.01" on autofocus placeholder="€">',
content: '<input type="number" lang="en" step="0.01" min="0.01" on autofocus placeholder="€">',
backgroundDismiss: true,
animation:'top',
closeAnimation:'bottom',
@ -1019,7 +1064,7 @@ $(document).ready(function() {
function askWithdraw() {
$.confirm({
title: 'Montant du retrait',
content: '<input type="number" step="0.01" min="0.01" on autofocus placeholder="€">',
content: '<input type="number" lang="en" step="0.01" min="0.01" on autofocus placeholder="€">',
backgroundDismiss: true,
animation:'top',
closeAnimation:'bottom',
@ -1203,7 +1248,7 @@ $(document).ready(function() {
function askAddcost(errors = '') {
$.confirm({
title: 'Majoration',
content: errors + '<input type="text" placeholder="Trigramme" autocomplete="off" name="trigramme" spellcheck="false" style="text-transform:uppercase" autofocus><input type="number" step="0.01" min="0.01" placeholder="€" name="amount">',
content: errors + '<input type="text" placeholder="Trigramme" autocomplete="off" name="trigramme" spellcheck="false" style="text-transform:uppercase" autofocus><input type="number" lang="en" step="0.01" min="0.01" placeholder="€" name="amount">',
backgroundDismiss: true,
animation:'top',
closeAnimation:'bottom',
@ -1290,7 +1335,7 @@ $(document).ready(function() {
}
for (var i=0; i<data['articles'].length; i++) {
article = data['articles'][i];
articles_container.find('[data-article='+article['id']+'] .stock')
articles_container.find('#data-article-'+article['id']+' .stock')
.text(article['stock']);
}
if (data['addcost']) {

View file

@ -1,23 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from django import template
from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.core.cache import cache
from kfet.models import Settings
from math import floor
import re
register = template.Library()
@register.filter()
def highlight_text(text, q):
q2 = "|".join(q.split())
pattern = re.compile(r"(?P<filter>%s)" % q2, re.IGNORECASE)
return mark_safe(re.sub(pattern, r"<span class='highlight_autocomplete'>\g<filter></span>", text))
return mark_safe(
re.sub(pattern,
r"<span class='highlight_autocomplete'>\g<filter></span>",
escape(text)))
@register.filter(is_safe=True)
def highlight_user(user, q):
@ -25,7 +26,8 @@ def highlight_user(user, q):
text = "%s %s (%s)" % (user.first_name, user.last_name, user.username)
else:
text = user.username
return highlight_text(escape(text), q)
return highlight_text(text, q)
@register.filter(is_safe=True)
def highlight_clipper(clipper, q):
@ -33,9 +35,11 @@ def highlight_clipper(clipper, q):
text = "%s (%s)" % (clipper.fullname, clipper.username)
else:
text = clipper.username
return highlight_text(escape(text), q)
return highlight_text(text, q)
@register.filter()
def ukf(balance, is_cof):
grant = is_cof and (1 + Settings.SUBVENTION_COF() / 100) or 1
return floor(balance * 10 * grant)
# float nécessaire car sinon problème avec le round de future.builtins
return floor(float(balance) * 10 * grant)

View file

@ -1,9 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from django.conf.urls import url
from django.contrib.auth.decorators import permission_required
from kfet import views
@ -35,13 +31,18 @@ urlpatterns = [
name='kfet.account.create_special'),
url(r'^accounts/new/user/(?P<username>.+)$', views.account_create_ajax,
name='kfet.account.create.fromuser'),
url(r'^accounts/new/clipper/(?P<login_clipper>.+)$', views.account_create_ajax,
url(r'^accounts/new/clipper/(?P<login_clipper>.+)$',
views.account_create_ajax,
name='kfet.account.create.fromclipper'),
url(r'^accounts/new/empty$', views.account_create_ajax,
name='kfet.account.create.empty'),
url(r'^autocomplete/account_new$', autocomplete.account_create,
name='kfet.account.create.autocomplete'),
# Account - Search
url(r'^autocomplete/account_search$', autocomplete.account_search,
name='kfet.account.search.autocomplete'),
# Account - Read
url(r'^accounts/(?P<trigramme>.{3})$', views.account_read,
name='kfet.account.read'),
@ -54,14 +55,17 @@ urlpatterns = [
url(r'^accounts/groups$', views.account_group,
name='kfet.account.group'),
url(r'^accounts/groups/new$',
permission_required('kfet.manage_perms')(views.AccountGroupCreate.as_view()),
permission_required('kfet.manage_perms')
(views.AccountGroupCreate.as_view()),
name='kfet.account.group.create'),
url(r'^accounts/groups/(?P<pk>\d+)/edit$',
permission_required('kfet.manage_perms')(views.AccountGroupUpdate.as_view()),
permission_required('kfet.manage_perms')
(views.AccountGroupUpdate.as_view()),
name='kfet.account.group.update'),
url(r'^accounts/negatives$',
permission_required('kfet.view_negs')(views.AccountNegativeList.as_view()),
permission_required('kfet.view_negs')
(views.AccountNegativeList.as_view()),
name='kfet.account.negative'),
# -----
@ -85,7 +89,9 @@ urlpatterns = [
teamkfet_required(views.CheckoutUpdate.as_view()),
name='kfet.checkout.update'),
### Checkout Statements urls
# -----
# Checkout Statement urls
# -----
# Checkout Statement - General
url('^checkouts/statements/$',
@ -154,10 +160,12 @@ urlpatterns = [
# -----
url(r'^settings/$',
permission_required('kfet.change_settings')(views.SettingsList.as_view()),
permission_required('kfet.change_settings')
(views.SettingsList.as_view()),
name='kfet.settings'),
url(r'^settings/(?P<pk>\d+)/edit$',
permission_required('kfet.change_settings')(views.SettingsUpdate.as_view()),
permission_required('kfet.change_settings')
(views.SettingsUpdate.as_view()),
name='kfet.settings.update'),
# -----