Merge branch 'master' into 'Aufinal/merge_k-fet'

# Conflicts:
#   kfet/static/kfet/css/index.css
This commit is contained in:
Aurélien Delobelle 2017-03-24 20:23:32 +01:00
commit cb13280458
11 changed files with 83 additions and 53 deletions

View file

@ -56,22 +56,24 @@ def autocomplete(request):
# Fetching data from the SPI # Fetching data from the SPI
if hasattr(settings, 'LDAP_SERVER_URL'): if hasattr(settings, 'LDAP_SERVER_URL'):
# Fetching # Fetching
ldap_query = '(|{:s})'.format(''.join( ldap_query = '(&{:s})'.format(''.join(
['(cn=*{bit:s}*)(uid=*{bit:s}*)'.format(**{"bit": bit}) '(|(cn=*{bit:s}*)(uid=*{bit:s}*))'.format(bit=bit)
for bit in bits] for bit in bits if bit.isalnum()
)) ))
with Connection(settings.LDAP_SERVER_URL) as conn: if ldap_query != "(&)":
conn.search( # If none of the bits were legal, we do not perform the query
'dc=spi,dc=ens,dc=fr', ldap_query, with Connection(settings.LDAP_SERVER_URL) as conn:
attributes=['uid', 'cn'] conn.search(
) 'dc=spi,dc=ens,dc=fr', ldap_query,
queries['clippers'] = conn.entries attributes=['uid', 'cn']
# Clearing redundancies )
queries['clippers'] = [ queries['clippers'] = conn.entries
Clipper(clipper.uid, clipper.cn) # Clearing redundancies
for clipper in queries['clippers'] queries['clippers'] = [
if str(clipper.uid) not in usernames Clipper(clipper.uid, clipper.cn)
] for clipper in queries['clippers']
if str(clipper.uid) not in usernames
]
# Resulting data # Resulting data
data.update(queries) data.update(queries)

View file

@ -1,10 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import division from django.contrib.auth.decorators import user_passes_test
from __future__ import print_function
from __future__ import unicode_literals
from django_cas_ng.decorators import user_passes_test
def is_cof(user): def is_cof(user):
@ -14,9 +10,7 @@ def is_cof(user):
except: except:
return False return False
cof_required = user_passes_test(lambda u: is_cof(u)) cof_required = user_passes_test(is_cof)
cof_required_customdenied = user_passes_test(lambda u: is_cof(u),
login_url="cof-denied")
def is_buro(user): def is_buro(user):
@ -26,4 +20,4 @@ def is_buro(user):
except: except:
return False return False
buro_required = user_passes_test(lambda u: is_buro(u)) buro_required = user_passes_test(is_buro)

View file

@ -800,7 +800,7 @@ input#search_autocomplete {
height: 40px; height: 40px;
padding: 10px 8px; padding: 10px 8px;
margin: 0 auto; margin: 0 auto;
margin-top: 20px; margin-top: 0px;
display: block; display: block;
color: #aaa; color: #aaa;
} }
@ -1119,3 +1119,10 @@ div.messages div.alert-success div.container {
div.messages div.alert div.container a { div.messages div.alert div.container a {
color: inherit; color: inherit;
} }
/* Help text */
p.help-block {
margin: 5px auto;
width: 90%;
}

View file

@ -9,7 +9,9 @@
{% block realcontent %} {% block realcontent %}
<h2>Inscription d'un nouveau membre</h2> <h2>Inscription d'un nouveau membre</h2>
<input type="text" name="q" id="search_autocomplete" spellcheck="false" /> <p class="help-block">Les mots contenant des caractères non alphanumériques seront ignorés</p>
<input type="text" name="q" id="search_autocomplete" spellcheck="false"
placeholder="Chercher un utilisateur par nom, prénom ou identifiant clipper" />
<div id="form-placeholder"></div> <div id="form-placeholder"></div>
<div class="yourlabs-autocomplete"></div> <div class="yourlabs-autocomplete"></div>
<script type="text/javascript"> <script type="text/javascript">
@ -20,7 +22,6 @@
minimumCharacters: 3, minimumCharacters: 3,
id: 'search_autocomplete', id: 'search_autocomplete',
choiceSelector: 'li:has(a)', choiceSelector: 'li:has(a)',
placeholder: "Chercher un utilisateur par nom, prénom ou identifiant clipper",
box: $(".yourlabs-autocomplete"), box: $(".yourlabs-autocomplete"),
}); });
$('input#search_autocomplete').bind( $('input#search_autocomplete').bind(

View file

@ -23,7 +23,7 @@ def key(d, key_name):
def highlight_text(text, q): def highlight_text(text, q):
q2 = "|".join(q.split()) q2 = "|".join(re.escape(word) for word in 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, return mark_safe(re.sub(pattern,
r"<span class='highlight'>\g<filter></span>", r"<span class='highlight'>\g<filter></span>",

View file

@ -74,22 +74,24 @@ def account_create(request):
# Fetching data from the SPI # Fetching data from the SPI
if hasattr(settings, 'LDAP_SERVER_URL'): if hasattr(settings, 'LDAP_SERVER_URL'):
# Fetching # Fetching
ldap_query = '(|{:s})'.format(''.join( ldap_query = '(&{:s})'.format(''.join(
['(cn=*{bit:s}*)(uid=*{bit:s}*)'.format(bit=word) '(|(cn=*{bit:s}*)(uid=*{bit:s}*))'.format(bit=word)
for word in search_words] for word in search_words if word.isalnum()
)) ))
with Connection(settings.LDAP_SERVER_URL) as conn: if ldap_query != "(&)":
conn.search( # If none of the bits were legal, we do not perform the query
'dc=spi,dc=ens,dc=fr', ldap_query, with Connection(settings.LDAP_SERVER_URL) as conn:
attributes=['uid', 'cn'] conn.search(
) 'dc=spi,dc=ens,dc=fr', ldap_query,
queries['clippers'] = conn.entries attributes=['uid', 'cn']
# Clearing redundancies )
queries['clippers'] = [ queries['clippers'] = conn.entries
Clipper(clipper.uid, clipper.cn) # Clearing redundancies
for clipper in queries['clippers'] queries['clippers'] = [
if str(clipper.uid) not in usernames Clipper(clipper.uid, clipper.cn)
] for clipper in queries['clippers']
if str(clipper.uid) not in usernames
]
# Resulting data # Resulting data
data.update(queries) data.update(queries)

View file

@ -1,12 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, from django.contrib.auth.decorators import user_passes_test
print_function, unicode_literals)
from builtins import *
from django_cas_ng.decorators import user_passes_test
def kfet_is_team(user): def kfet_is_team(user):
return user.has_perm('kfet.is_team') return user.has_perm('kfet.is_team')
teamkfet_required = user_passes_test(lambda u: kfet_is_team(u)) teamkfet_required = user_passes_test(kfet_is_team)

View file

@ -12,7 +12,8 @@ from django.contrib.auth.models import User, Group, Permission, ContentType
from gestioncof.management.base import MyBaseCommand from gestioncof.management.base import MyBaseCommand
from gestioncof.models import CofProfile from gestioncof.models import CofProfile
from kfet.models import Account, Article, OperationGroup, Operation, Checkout from kfet.models import (Account, Article, OperationGroup, Operation,
Checkout, CheckoutStatement)
# Où sont stockés les fichiers json # Où sont stockés les fichiers json
DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)),
@ -87,22 +88,44 @@ class Command(MyBaseCommand):
# Compte liquide # Compte liquide
self.stdout.write("Création du compte liquide")
liq_user, _ = User.objects.get_or_create(username='liquide') liq_user, _ = User.objects.get_or_create(username='liquide')
liq_profile, _ = CofProfile.objects.get_or_create(user=liq_user) liq_profile, _ = CofProfile.objects.get_or_create(user=liq_user)
liq_account, _ = Account.objects.get_or_create(cofprofile=liq_profile, liq_account, _ = Account.objects.get_or_create(cofprofile=liq_profile,
trigramme='LIQ') trigramme='LIQ')
# Root account if existing
root_profile = CofProfile.objects.filter(user__username='root')
if root_profile.exists():
self.stdout.write("Création du compte K-Fêt root")
root_profile = root_profile.get()
Account.objects.get_or_create(cofprofile=root_profile,
trigramme='AAA')
# --- # ---
# Caisse # Caisse
# --- # ---
checkout, _ = Checkout.objects.get_or_create( checkout, created = Checkout.objects.get_or_create(
created_by=Account.objects.get(trigramme='000'), created_by=Account.objects.get(trigramme='000'),
name='Chaudron', name='Chaudron',
valid_from=timezone.now(), defaults={
valid_to=timezone.now() + timedelta(days=365) 'valid_from': timezone.now(),
'valid_to': timezone.now() + timedelta(days=730)
},
) )
if created:
CheckoutStatement.objects.create(
by=Account.objects.get(trigramme='000'),
checkout=checkout,
balance_old=0,
balance_new=0,
amount_taken=0,
amount_error=0
)
# --- # ---
# Opérations # Opérations
# --- # ---

View file

@ -544,4 +544,7 @@ thead .tooltip {
-moz-column-count: 5; /* Firefox */ -moz-column-count: 5; /* Firefox */
column-count: 5; column-count: 5;
} }
.help-block {
padding-top: 15px;
} }

View file

@ -23,6 +23,7 @@
{{ trigramme_form.trigramme }} {{ trigramme_form.trigramme }}
</div> </div>
<div id="trigramme_valid"></div> <div id="trigramme_valid"></div>
<p class="help-block">Les mots contenant des caractères non alphanumériques seront ignorés</p>
<input type="text" name="q" id="search_autocomplete" spellcheck="false" placeholder="Chercher un utilisateur par nom, prénom ou identifiant clipper" class="form-control"> <input type="text" name="q" id="search_autocomplete" spellcheck="false" placeholder="Chercher un utilisateur par nom, prénom ou identifiant clipper" class="form-control">
<div style="position:relative;"> <div style="position:relative;">
<div id="search_results"></div> <div id="search_results"></div>

View file

@ -12,7 +12,7 @@ register = template.Library()
@register.filter() @register.filter()
def highlight_text(text, q): def highlight_text(text, q):
q2 = "|".join(q.split()) q2 = "|".join(re.escape(word) for word in q.split())
pattern = re.compile(r"(?P<filter>%s)" % q2, re.IGNORECASE) pattern = re.compile(r"(?P<filter>%s)" % q2, re.IGNORECASE)
regex = r"<span class='highlight_autocomplete'>\g<filter></span>" regex = r"<span class='highlight_autocomplete'>\g<filter></span>"
return mark_safe(re.sub(pattern, regex, escape(text))) return mark_safe(re.sub(pattern, regex, escape(text)))