Merge branch 'qwann/k-fet/stats' into qwann/k-fet/home

This commit is contained in:
Qwann 2017-01-27 12:15:47 +01:00
commit 5cedabf5a8
9 changed files with 232 additions and 142 deletions

View file

@ -1,9 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from django.shortcuts import render from django.shortcuts import render
from django.http import Http404 from django.http import Http404
from django.db.models import Q from django.db.models import Q
@ -11,6 +7,7 @@ from gestioncof.models import User, Clipper
from kfet.decorators import teamkfet_required from kfet.decorators import teamkfet_required
from kfet.models import Account from kfet.models import Account
@teamkfet_required @teamkfet_required
def account_create(request): def account_create(request):
if "q" not in request.GET: if "q" not in request.GET:
@ -25,48 +22,48 @@ def account_create(request):
queries = {} queries = {}
search_words = q.split() search_words = q.split()
queries['kfet'] = Account.objects queries['kfet'] = Account.objects
queries['users_cof'] = User.objects.filter(Q(profile__is_cof = True)) queries['users_cof'] = User.objects.filter(Q(profile__is_cof=True))
queries['users_notcof'] = User.objects.filter(Q(profile__is_cof = False)) queries['users_notcof'] = User.objects.filter(Q(profile__is_cof=False))
queries['clippers'] = Clipper.objects queries['clippers'] = Clipper.objects
for word in search_words: for word in search_words:
queries['kfet'] = queries['kfet'].filter( queries['kfet'] = queries['kfet'].filter(
Q(cofprofile__user__username__icontains = word) Q(cofprofile__user__username__icontains=word) |
| Q(cofprofile__user__first_name__icontains = word) Q(cofprofile__user__first_name__icontains=word) |
| Q(cofprofile__user__last_name__icontains = word) Q(cofprofile__user__last_name__icontains=word)
) )
queries['users_cof'] = queries['users_cof'].filter( queries['users_cof'] = queries['users_cof'].filter(
Q(username__icontains = word) Q(username__icontains=word) |
| Q(first_name__icontains = word) Q(first_name__icontains=word) |
| Q(last_name__icontains = word) Q(last_name__icontains=word)
) )
queries['users_notcof'] = queries['users_notcof'].filter( queries['users_notcof'] = queries['users_notcof'].filter(
Q(username__icontains = word) Q(username__icontains=word) |
| Q(first_name__icontains = word) Q(first_name__icontains=word) |
| Q(last_name__icontains = word) Q(last_name__icontains=word)
) )
queries['clippers'] = queries['clippers'].filter( queries['clippers'] = queries['clippers'].filter(
Q(username__icontains = word) Q(username__icontains=word) |
| Q(fullname__icontains = word) Q(fullname__icontains=word)
) )
queries['kfet'] = queries['kfet'].distinct() queries['kfet'] = queries['kfet'].distinct()
usernames = list( \ usernames = list(
queries['kfet'].values_list('cofprofile__user__username', flat=True)) 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'] ] for account in queries['kfet']]
queries['users_cof'] = \ queries['users_cof'] = \
queries['users_cof'].exclude(username__in=usernames).distinct() queries['users_cof'].exclude(username__in=usernames).distinct()
queries['users_notcof'] = \ queries['users_notcof'] = \
queries['users_notcof'].exclude(username__in=usernames).distinct() queries['users_notcof'].exclude(username__in=usernames).distinct()
usernames += list( \ usernames += list(
queries['users_cof'].values_list('username', flat=True)) queries['users_cof'].values_list('username', flat=True))
usernames += list( \ usernames += list(
queries['users_notcof'].values_list('username', flat=True)) queries['users_notcof'].values_list('username', flat=True))
queries['clippers'] = \ queries['clippers'] = \
@ -80,3 +77,25 @@ def account_create(request):
data['options'] = options data['options'] = options
return render(request, "kfet/account_create_autocomplete.html", data) 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

@ -83,3 +83,24 @@
padding-right: 50px; padding-right: 50px;
padding-left: 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> </a>
</li> </li>
{% if kfet %} {% 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 %} {% for account, user in kfet %}
<li><span class="text">{{ account }} [{{ user|highlight_user:q }}]</span></li> <li><span class="text">{{ account }} [{{ user|highlight_user:q }}]</span></li>
{% endfor %} {% 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 %} {% 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/jquery-ui.min.css' %}">
<link rel="stylesheet" style="text/css" href="{% static 'kfet/css/kpsul_grid.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/js.cookie.js' %}"></script>
<script type="text/javascript" src="{% static 'kfet/js/reconnecting-websocket.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> <script type="text/javascript" src="{% static 'kfet/js/jquery-ui.min.js' %}"></script>
@ -260,12 +261,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>'; buttons += '<a href="'+url_base+'?trigramme='+trigramme+'" class="btn btn-primary" target="_blank" title="Créer"><span class="glyphicon glyphicon-plus"></span></a>';
} else { } else {
var url_base = '{% url 'kfet.account' %}' 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); 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 // Clear data
function resetAccountData() { function resetAccountData() {
account_data = account_data_default; account_data = account_data_default;

View file

@ -1,23 +1,24 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from django import template from django import template
from django.utils.html import escape from django.utils.html import escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.core.cache import cache
from kfet.models import Settings from kfet.models import Settings
from math import floor from math import floor
import re import re
register = template.Library() register = template.Library()
@register.filter()
def highlight_text(text, q): def highlight_text(text, q):
q2 = "|".join(q.split()) q2 = "|".join(q.split())
pattern = re.compile(r"(?P<filter>%s)" % q2, re.IGNORECASE) 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) @register.filter(is_safe=True)
def highlight_user(user, q): 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) text = "%s %s (%s)" % (user.first_name, user.last_name, user.username)
else: else:
text = user.username text = user.username
return highlight_text(escape(text), q) return highlight_text(text, q)
@register.filter(is_safe=True) @register.filter(is_safe=True)
def highlight_clipper(clipper, q): def highlight_clipper(clipper, q):
@ -33,7 +35,8 @@ def highlight_clipper(clipper, q):
text = "%s (%s)" % (clipper.fullname, clipper.username) text = "%s (%s)" % (clipper.fullname, clipper.username)
else: else:
text = clipper.username text = clipper.username
return highlight_text(escape(text), q) return highlight_text(text, q)
@register.filter() @register.filter()
def ukf(balance, is_cof): def ukf(balance, is_cof):

View file

@ -1,8 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from django.test import TestCase from django.test import TestCase
from kfet.models import Account from kfet.models import Account

View file

@ -1,9 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from django.conf.urls import url from django.conf.urls import url
from django.contrib.auth.decorators import permission_required from django.contrib.auth.decorators import permission_required
from kfet import views from kfet import views
@ -14,9 +10,9 @@ urlpatterns = [
url(r'^$', views.Home.as_view(), url(r'^$', views.Home.as_view(),
name = 'kfet.home'), name = 'kfet.home'),
url(r'^login/genericteam$', views.login_genericteam, url(r'^login/genericteam$', views.login_genericteam,
name = 'kfet.login.genericteam'), name='kfet.login.genericteam'),
url(r'^history$', views.history, url(r'^history$', views.history,
name = 'kfet.history'), name='kfet.history'),
# ----- # -----
# Account urls # Account urls
@ -24,45 +20,53 @@ urlpatterns = [
# Account - General # Account - General
url(r'^accounts/$', views.account, url(r'^accounts/$', views.account,
name = 'kfet.account'), name='kfet.account'),
url(r'^accounts/is_validandfree$', views.account_is_validandfree_ajax, url(r'^accounts/is_validandfree$', views.account_is_validandfree_ajax,
name = 'kfet.account.is_validandfree.ajax'), name='kfet.account.is_validandfree.ajax'),
# Account - Create # Account - Create
url(r'^accounts/new$', views.account_create, url(r'^accounts/new$', views.account_create,
name = 'kfet.account.create'), name='kfet.account.create'),
url(r'^accounts/new_special$', views.account_create_special, url(r'^accounts/new_special$', views.account_create_special,
name = 'kfet.account.create_special'), name='kfet.account.create_special'),
url(r'^accounts/new/user/(?P<username>.+)$', views.account_create_ajax, url(r'^accounts/new/user/(?P<username>.+)$', views.account_create_ajax,
name = 'kfet.account.create.fromuser'), 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>.+)$',
name = 'kfet.account.create.fromclipper'), views.account_create_ajax,
name='kfet.account.create.fromclipper'),
url(r'^accounts/new/empty$', views.account_create_ajax, url(r'^accounts/new/empty$', views.account_create_ajax,
name = 'kfet.account.create.empty'), name='kfet.account.create.empty'),
url(r'^autocomplete/account_new$', autocomplete.account_create, url(r'^autocomplete/account_new$', autocomplete.account_create,
name = 'kfet.account.create.autocomplete'), name='kfet.account.create.autocomplete'),
# Account - Search
url(r'^autocomplete/account_search$', autocomplete.account_search,
name='kfet.account.search.autocomplete'),
# Account - Read # Account - Read
url(r'^accounts/(?P<trigramme>.{3})$', views.account_read, url(r'^accounts/(?P<trigramme>.{3})$', views.account_read,
name = 'kfet.account.read'), name='kfet.account.read'),
# Account - Update # Account - Update
url(r'^accounts/(?P<trigramme>.{3})/edit$', views.account_update, url(r'^accounts/(?P<trigramme>.{3})/edit$', views.account_update,
name = 'kfet.account.update'), name='kfet.account.update'),
# Account - Groups # Account - Groups
url(r'^accounts/groups$', views.account_group, url(r'^accounts/groups$', views.account_group,
name = 'kfet.account.group'), name='kfet.account.group'),
url(r'^accounts/groups/new$', url(r'^accounts/groups/new$',
permission_required('kfet.manage_perms')(views.AccountGroupCreate.as_view()), permission_required('kfet.manage_perms')
name = 'kfet.account.group.create'), (views.AccountGroupCreate.as_view()),
name='kfet.account.group.create'),
url(r'^accounts/groups/(?P<pk>\d+)/edit$', url(r'^accounts/groups/(?P<pk>\d+)/edit$',
permission_required('kfet.manage_perms')(views.AccountGroupUpdate.as_view()), permission_required('kfet.manage_perms')
name = 'kfet.account.group.update'), (views.AccountGroupUpdate.as_view()),
name='kfet.account.group.update'),
url(r'^accounts/negatives$', url(r'^accounts/negatives$',
permission_required('kfet.view_negs')(views.AccountNegativeList.as_view()), permission_required('kfet.view_negs')
name = 'kfet.account.negative'), (views.AccountNegativeList.as_view()),
name='kfet.account.negative'),
# Account - Statistics # Account - Statistics
url('^accounts/(?P<trigramme>.{3})/stat/last/$', url('^accounts/(?P<trigramme>.{3})/stat/last/$',
@ -95,34 +99,36 @@ urlpatterns = [
# Checkout - General # Checkout - General
url('^checkouts/$', url('^checkouts/$',
teamkfet_required(views.CheckoutList.as_view()), teamkfet_required(views.CheckoutList.as_view()),
name = 'kfet.checkout'), name='kfet.checkout'),
# Checkout - Create # Checkout - Create
url('^checkouts/new$', url('^checkouts/new$',
teamkfet_required(views.CheckoutCreate.as_view()), teamkfet_required(views.CheckoutCreate.as_view()),
name = 'kfet.checkout.create'), name='kfet.checkout.create'),
# Checkout - Read # Checkout - Read
url('^checkouts/(?P<pk>\d+)$', url('^checkouts/(?P<pk>\d+)$',
teamkfet_required(views.CheckoutRead.as_view()), teamkfet_required(views.CheckoutRead.as_view()),
name = 'kfet.checkout.read'), name='kfet.checkout.read'),
# Checkout - Update # Checkout - Update
url('^checkouts/(?P<pk>\d+)/edit$', url('^checkouts/(?P<pk>\d+)/edit$',
teamkfet_required(views.CheckoutUpdate.as_view()), teamkfet_required(views.CheckoutUpdate.as_view()),
name = 'kfet.checkout.update'), name='kfet.checkout.update'),
### Checkout Statements urls # -----
# Checkout Statement urls
# -----
# Checkout Statement - General # Checkout Statement - General
url('^checkouts/statements/$', url('^checkouts/statements/$',
teamkfet_required(views.CheckoutStatementList.as_view()), teamkfet_required(views.CheckoutStatementList.as_view()),
name = 'kfet.checkoutstatement'), name='kfet.checkoutstatement'),
# Checkout Statement - Create # Checkout Statement - Create
url('^checkouts/(?P<pk_checkout>\d+)/statements/add', url('^checkouts/(?P<pk_checkout>\d+)/statements/add',
teamkfet_required(views.CheckoutStatementCreate.as_view()), teamkfet_required(views.CheckoutStatementCreate.as_view()),
name = 'kfet.checkoutstatement.create'), name='kfet.checkoutstatement.create'),
# Checkout Statement - Update # Checkout Statement - Update
url('^checkouts/(?P<pk_checkout>\d+)/statements/(?P<pk>\d+)/edit', url('^checkouts/(?P<pk_checkout>\d+)/statements/(?P<pk>\d+)/edit',
teamkfet_required(views.CheckoutStatementUpdate.as_view()), teamkfet_required(views.CheckoutStatementUpdate.as_view()),
name = 'kfet.checkoutstatement.update'), name='kfet.checkoutstatement.update'),
# ----- # -----
# Article urls # Article urls
@ -131,15 +137,15 @@ urlpatterns = [
# Article - General # Article - General
url('^articles/$', url('^articles/$',
teamkfet_required(views.ArticleList.as_view()), teamkfet_required(views.ArticleList.as_view()),
name = 'kfet.article'), name='kfet.article'),
# Article - Create # Article - Create
url('^articles/new$', url('^articles/new$',
teamkfet_required(views.ArticleCreate.as_view()), teamkfet_required(views.ArticleCreate.as_view()),
name = 'kfet.article.create'), name='kfet.article.create'),
# Article - Read # Article - Read
url('^articles/(?P<pk>\d+)$', url('^articles/(?P<pk>\d+)$',
teamkfet_required(views.ArticleRead.as_view()), teamkfet_required(views.ArticleRead.as_view()),
name = 'kfet.article.read'), name='kfet.article.read'),
# Article - Update # Article - Update
url('^articles/(?P<pk>\d+)/edit$', url('^articles/(?P<pk>\d+)/edit$',
teamkfet_required(views.ArticleUpdate.as_view()), teamkfet_required(views.ArticleUpdate.as_view()),
@ -162,28 +168,28 @@ urlpatterns = [
# K-Psul urls # K-Psul urls
# ----- # -----
url('^k-psul/$', views.kpsul, name = 'kfet.kpsul'), url('^k-psul/$', views.kpsul, name='kfet.kpsul'),
url('^k-psul/checkout_data$', views.kpsul_checkout_data, url('^k-psul/checkout_data$', views.kpsul_checkout_data,
name = 'kfet.kpsul.checkout_data'), name='kfet.kpsul.checkout_data'),
url('^k-psul/perform_operations$', views.kpsul_perform_operations, url('^k-psul/perform_operations$', views.kpsul_perform_operations,
name = 'kfet.kpsul.perform_operations'), name='kfet.kpsul.perform_operations'),
url('^k-psul/cancel_operations$', views.kpsul_cancel_operations, url('^k-psul/cancel_operations$', views.kpsul_cancel_operations,
name = 'kfet.kpsul.cancel_operations'), name='kfet.kpsul.cancel_operations'),
url('^k-psul/articles_data', views.kpsul_articles_data, url('^k-psul/articles_data', views.kpsul_articles_data,
name = 'kfet.kpsul.articles_data'), name='kfet.kpsul.articles_data'),
url('^k-psul/update_addcost$', views.kpsul_update_addcost, url('^k-psul/update_addcost$', views.kpsul_update_addcost,
name = 'kfet.kpsul.update_addcost'), name='kfet.kpsul.update_addcost'),
url('^k-psul/get_settings$', views.kpsul_get_settings, url('^k-psul/get_settings$', views.kpsul_get_settings,
name = 'kfet.kpsul.get_settings'), name='kfet.kpsul.get_settings'),
# ----- # -----
# JSON urls # JSON urls
# ----- # -----
url(r'^history.json$', views.history_json, url(r'^history.json$', views.history_json,
name = 'kfet.history.json'), name='kfet.history.json'),
url(r'^accounts/read.json$', views.account_read_json, url(r'^accounts/read.json$', views.account_read_json,
name = 'kfet.account.read.json'), name='kfet.account.read.json'),
# ----- # -----
@ -191,24 +197,26 @@ urlpatterns = [
# ----- # -----
url(r'^settings/$', url(r'^settings/$',
permission_required('kfet.change_settings')(views.SettingsList.as_view()), permission_required('kfet.change_settings')
name = 'kfet.settings'), (views.SettingsList.as_view()),
name='kfet.settings'),
url(r'^settings/(?P<pk>\d+)/edit$', url(r'^settings/(?P<pk>\d+)/edit$',
permission_required('kfet.change_settings')(views.SettingsUpdate.as_view()), permission_required('kfet.change_settings')
name = 'kfet.settings.update'), (views.SettingsUpdate.as_view()),
name='kfet.settings.update'),
# ----- # -----
# Transfers urls # Transfers urls
# ----- # -----
url(r'^transfers/$', views.transfers, url(r'^transfers/$', views.transfers,
name = 'kfet.transfers'), name='kfet.transfers'),
url(r'^transfers/new$', views.transfers_create, url(r'^transfers/new$', views.transfers_create,
name = 'kfet.transfers.create'), name='kfet.transfers.create'),
url(r'^transfers/perform$', views.perform_transfers, url(r'^transfers/perform$', views.perform_transfers,
name = 'kfet.transfers.perform'), name='kfet.transfers.perform'),
url(r'^transfers/cancel$', views.cancel_transfers, url(r'^transfers/cancel$', views.cancel_transfers,
name = 'kfet.transfers.cancel'), name='kfet.transfers.cancel'),
# ----- # -----
# Inventories urls # Inventories urls
@ -216,12 +224,12 @@ urlpatterns = [
url(r'^inventaires/$', url(r'^inventaires/$',
teamkfet_required(views.InventoryList.as_view()), teamkfet_required(views.InventoryList.as_view()),
name = 'kfet.inventory'), name='kfet.inventory'),
url(r'^inventaires/new$', views.inventory_create, url(r'^inventaires/new$', views.inventory_create,
name = 'kfet.inventory.create'), name='kfet.inventory.create'),
url(r'^inventaires/(?P<pk>\d+)$', url(r'^inventaires/(?P<pk>\d+)$',
teamkfet_required(views.InventoryRead.as_view()), teamkfet_required(views.InventoryRead.as_view()),
name = 'kfet.inventory.read'), name='kfet.inventory.read'),
# ----- # -----
# Order urls # Order urls
@ -229,15 +237,15 @@ urlpatterns = [
url(r'^orders/$', url(r'^orders/$',
teamkfet_required(views.OrderList.as_view()), teamkfet_required(views.OrderList.as_view()),
name = 'kfet.order'), name='kfet.order'),
url(r'^orders/(?P<pk>\d+)$', url(r'^orders/(?P<pk>\d+)$',
teamkfet_required(views.OrderRead.as_view()), teamkfet_required(views.OrderRead.as_view()),
name = 'kfet.order.read'), name='kfet.order.read'),
url(r'^orders/suppliers/(?P<pk>\d+)/edit$', url(r'^orders/suppliers/(?P<pk>\d+)/edit$',
teamkfet_required(views.SupplierUpdate.as_view()), teamkfet_required(views.SupplierUpdate.as_view()),
name = 'kfet.order.supplier.update'), name='kfet.order.supplier.update'),
url(r'^orders/suppliers/(?P<pk>\d+)/new-order$', views.order_create, url(r'^orders/suppliers/(?P<pk>\d+)/new-order$', views.order_create,
name = 'kfet.order.new'), name='kfet.order.new'),
url(r'^orders/(?P<pk>\d+)/to_inventory$', views.order_to_inventory, url(r'^orders/(?P<pk>\d+)/to_inventory$', views.order_to_inventory,
name = 'kfet.order.to_inventory'), name='kfet.order.to_inventory'),
] ]

View file

@ -1,9 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from django.shortcuts import render, get_object_or_404, redirect from django.shortcuts import render, get_object_or_404, redirect
from django.core.exceptions import PermissionDenied, ValidationError from django.core.exceptions import PermissionDenied, ValidationError
from django.core.cache import cache from django.core.cache import cache
@ -983,7 +979,7 @@ def kpsul_perform_operations(request):
if operationgroup.on_acc.is_cof: if operationgroup.on_acc.is_cof:
if is_addcost: if is_addcost:
operation.addcost_amount = operation.addcost_amount / cof_grant_divisor operation.addcost_amount = operation.addcost_amount / cof_grant_divisor
operation.amount = Decimal(float(operation.amount) / cof_grant_divisor) operation.amount = operation.amount / cof_grant_divisor
to_articles_stocks[operation.article] -= operation.article_nb to_articles_stocks[operation.article] -= operation.article_nb
else: else:
if operationgroup.on_acc.is_cash: if operationgroup.on_acc.is_cash:
@ -2001,8 +1997,8 @@ class HybridDetailView(JSONResponseMixin,
SingleObjectTemplateResponseMixin, SingleObjectTemplateResponseMixin,
BaseDetailView): BaseDetailView):
""" """
Returns a DetailView as an html page except if a JSON is requested Returns a DetailView as an html page except if a JSON file is requested
file by the GET method in which case it returns a JSON response. by the GET method in which case it returns a JSON response.
""" """
def render_to_response(self, context): def render_to_response(self, context):
# Look for a 'format=json' GET argument # Look for a 'format=json' GET argument
@ -2012,14 +2008,12 @@ class HybridDetailView(JSONResponseMixin,
return super(HybridDetailView, self).render_to_response(context) return super(HybridDetailView, self).render_to_response(context)
# Rend un ListView en html sauf si on lui précise dans
# l'appel à get que l'on veut un json auquel cas il en rend un
class HybridListView(JSONResponseMixin, class HybridListView(JSONResponseMixin,
MultipleObjectTemplateResponseMixin, MultipleObjectTemplateResponseMixin,
BaseListView): BaseListView):
""" """
Returns a ListView as an html page except if a JSON is requested Returns a ListView as an html page except if a JSON file is requested
file by the GET method in which case it returns a JSON response. by the GET method in which case it returns a JSON response.
""" """
def render_to_response(self, context): def render_to_response(self, context):
# Look for a 'format=json' GET argument # Look for a 'format=json' GET argument
@ -2035,7 +2029,7 @@ class ObjectResumeStat(DetailView):
DOES NOT RETURN A JSON RESPONSE DOES NOT RETURN A JSON RESPONSE
""" """
template_name = 'kfet/object_stat_resume.html' template_name = 'kfet/object_stat_resume.html'
context_object_name = 'lul' context_object_name = ''
id_prefix = 'id_a_definir' id_prefix = 'id_a_definir'
# nombre de vues à résumer # nombre de vues à résumer
nb_stat = 2 nb_stat = 2
@ -2054,24 +2048,24 @@ class ObjectResumeStat(DetailView):
return [{}] * self.nb_stat return [{}] * self.nb_stat
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
# On hérite pas # On n'hérite pas
object_id = self.object.id object_id = self.object.id
url_kwargs = self.url_kwargs() url_kwargs = self.url_kwargs()
context = {} context = {}
stats = {} stats = {}
for i in range(self.nb_stat): for i in range(self.nb_stat):
stats[i] = { stats[i] = {
'label': self.stat_labels[i], 'label': self.stat_labels[i],
'btn': "btn_%s_%d_%d" % (self.id_prefix, 'btn': "btn_%s_%d_%d" % (self.id_prefix,
object_id, object_id,
i), i),
'url': reverse_lazy(self.stat_urls[i], 'url': reverse_lazy(self.stat_urls[i],
kwargs=dict( kwargs=dict(
self.get_object_url_kwargs(), self.get_object_url_kwargs(),
**url_kwargs[i] **url_kwargs[i]
),
), ),
} ),
}
prefix = "%s_%d" % (self.id_prefix, object_id) prefix = "%s_%d" % (self.id_prefix, object_id)
context['id_prefix'] = prefix context['id_prefix'] = prefix
context['content_id'] = "content_%s" % prefix context['content_id'] = "content_%s" % prefix
@ -2085,11 +2079,6 @@ class ObjectResumeStat(DetailView):
# Evolution Balance perso # Evolution Balance perso
# ----------------------- # -----------------------
ID_PREFIX_ACC_BALANCE = "balance_acc" ID_PREFIX_ACC_BALANCE = "balance_acc"
# ID_PREFIX_ACC_BALANCE_MONTH = "balance_month_acc"
# ID_PREFIX_ACC_BALANCE_THREE_MONTHS = "balance_three_months_acc"
# ID_PREFIX_ACC_BALANCE_SIX_MONTHS = "balance_six_months_acc"
# ID_PREFIX_ACC_BALANCE_YEAR = "balance_year_acc"
# ID_PREFIX_ACC_BALANCE_ANYTIME = "balance_anytime_acc"
# Un résumé de toutes les vues ArticleStatBalance # Un résumé de toutes les vues ArticleStatBalance
@ -2129,17 +2118,17 @@ class AccountStatBalanceAll(ObjectResumeStat):
class AccountStatBalance(HybridDetailView): class AccountStatBalance(HybridDetailView):
""" """
Returns a graph (or a JSON Response) of the evolution a the personnal Returns a graph (or a JSON Response) of the evolution a the personnal
balance of a trigramm between timezone.now() and `nb_days` balance of a trigramme between timezone.now() and `nb_days`
ago (specified to the view as an argument) ago (specified to the view as an argument)
takes intto account the Operations and the Transfers takes into account the Operations and the Transfers
does not takes intto account the balance offset does not takes into account the balance offset
""" """
model = Account model = Account
trigramme_url_kwarg = 'trigramme' trigramme_url_kwarg = 'trigramme'
nb_date_url_kwargs = 'nb_date' nb_date_url_kwargs = 'nb_date'
template_name = 'kfet/account_stat_balance.html' template_name = 'kfet/account_stat_balance.html'
context_object_name = 'account' context_object_name = 'account'
id_prefix = "lol" id_prefix = ""
def get_object(self, **kwargs): def get_object(self, **kwargs):
trigramme = self.kwargs.get(self.trigramme_url_kwarg) trigramme = self.kwargs.get(self.trigramme_url_kwarg)
@ -2296,14 +2285,14 @@ class AccountStatLastAll(ObjectResumeStat):
class AccountStatLast(HybridDetailView): class AccountStatLast(HybridDetailView):
""" """
Returns a graph (or a JSON Response) of the evolution a the personnal Returns a graph (or a JSON Response) of the evolution a the personnal
consommation of a trigramm at the diffent dates specified consommation of a trigramme at the diffent dates specified
""" """
model = Account model = Account
trigramme_url_kwarg = 'trigramme' trigramme_url_kwarg = 'trigramme'
template_name = 'kfet/account_stat_last.html' template_name = 'kfet/account_stat_last.html'
context_object_name = 'account' context_object_name = 'account'
end_date = timezone.now() end_date = timezone.now()
id_prefix = "lol" id_prefix = ""
# doit rendre un dictionnaire des dates # doit rendre un dictionnaire des dates
# la première date correspond au début # la première date correspond au début
@ -2344,9 +2333,6 @@ class AccountStatLast(HybridDetailView):
return operations return operations
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
# On hérite
# en fait non, pas besoin et c'est chiant à dumper
# context = super(AccountStat, self).get_context_data(**kwargs)
context = {} context = {}
nb_ventes = {} nb_ventes = {}
# On récupère les labels des dates # On récupère les labels des dates
@ -2444,7 +2430,7 @@ class ArticleStatLast(HybridDetailView):
template_name = 'kfet/article_stat_last.html' template_name = 'kfet/article_stat_last.html'
context_object_name = 'article' context_object_name = 'article'
end_date = timezone.now() end_date = timezone.now()
id_prefix = "lol" id_prefix = ""
def render_to_response(self, context): def render_to_response(self, context):
# Look for a 'format=json' GET argument # Look for a 'format=json' GET argument
@ -2465,9 +2451,6 @@ class ArticleStatLast(HybridDetailView):
pass pass
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
# On hérite
# en fait non, pas besoin et c'est chiant à dumper
# context = super(ArticleStat, self).get_context_data(**kwargs)
context = {} context = {}
# On récupère les labels des dates # On récupère les labels des dates
context['labels'] = self.get_labels().copy() context['labels'] = self.get_labels().copy()