- Fixes bugs
- Removes useless scripts
This commit is contained in:
Martin Pépin 2016-12-25 12:27:42 +01:00
parent 3c7558c853
commit 01ce955784
4 changed files with 14 additions and 41 deletions

View file

@ -54,13 +54,14 @@ def autocomplete(request):
['(cn=*{:s}*)'.format(bit) for bit in bits]
))
with Connection(settings.LDAP_SERVER_URL) as conn:
queries['clippers'] = conn.search(
'dc=spi,dc=ens,dc=fr', query,
conn.search(
'dc=spi,dc=ens,dc=fr', ldap_query,
attributes=['uid', 'cn']
)
queries['clippers'] = conn.entries
# Clearing redundancies
queries['clippers'] = [
{'clipper': clipper.uid, 'fullname': clipper.cn}
Clipper(clipper.uid, clipper.cn)
for clipper in queries['clippers']
if clipper.uid not in usernames
]

View file

@ -11,6 +11,13 @@ from gestioncof.models import User
from kfet.decorators import teamkfet_required
from kfet.models import Account
class Clipper(object):
def __init__(self, clipper, fullname):
self.clipper = clipper
self.fullname = fullname
@teamkfet_required
def account_create(request):
if "q" not in request.GET:
@ -72,13 +79,14 @@ def account_create(request):
['(cn=*{:s}*)'.format(bit) for bit in bits]
))
with Connection(settings.LDAP_SERVER_URL) as conn:
queries['clippers'] = conn.search(
conn.search(
'dc=spi,dc=ens,dc=fr', ldap_query,
attributes=['uid', 'cn']
)
queries['clippers'] = conn.entries
# Clearing redundancies
queries['clippers'] = [
{'clipper': clipper.uid, 'fullname': clipper.cn}
Clipper(clipper.uid, clipper.cn)
for clipper in queries['clippers']
if clipper.uid not in usernames
]

View file

@ -1,34 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cof.settings")
from gestioncof.models import Clipper
current = {}
print("[ FETCHING ]")
for clipper in Clipper.objects.all():
current[clipper.username] = clipper
print("[ SYNCING ]")
for line in sys.stdin:
bits = line.split(":")
username = bits[0]
fullname = bits[4]
if username in current:
clipper = current[username]
if clipper.fullname != fullname:
clipper.fullname = fullname
clipper.save()
print("Updated", username)
else:
clipper = Clipper(username=username, fullname=fullname)
clipper.save()
print("Created", username)
print("[ DONE ]")

View file

@ -1,2 +0,0 @@
#!/bin/sh
ssh cof@sas.eleves.ens.fr ypcat passwd | python sync_clipper.py