views.py 185 KB
Newer Older
1
2
# epl_version ="v2.00 (Chimnechilde)"
# date_version ="July 9, 2021"
Georges Gressot's avatar
Georges Gressot committed
3
# Mise au niveau de :
4
epl_version ="v2.01.6-beta (~Bathilde)"
5
date_version ="October 7, 2021"
Georges Gressot's avatar
Georges Gressot committed
6
#branche = multi
7

Georges Gressot's avatar
Georges Gressot committed
8
9
10
11
12
13
14
15
16
17
from django.shortcuts import render

from .models import *

from .forms import *

from django.core.mail import send_mail

from django.db.models.functions import Now

18
19
from django.contrib.auth.decorators import login_required

Georges Gressot's avatar
Georges Gressot committed
20
21
from django.utils.translation import ugettext as _

Georges Gressot's avatar
Georges Gressot committed
22
23
from django.contrib.auth.models import User

24
25
from django.contrib.auth import logout

Georges Gressot's avatar
...    
Georges Gressot committed
26
from django.http import HttpResponseRedirect, HttpResponse
Georges Gressot's avatar
Georges Gressot committed
27
import os
Georges Gressot's avatar
Georges Gressot committed
28

Georges Gressot's avatar
Georges Gressot committed
29
30
from django.contrib import messages

31
lastrked =None
Georges Gressot's avatar
Georges Gressot committed
32
webmaster =""
Georges Gressot's avatar
Georges Gressot committed
33
try:
Georges Gressot's avatar
Georges Gressot committed
34
    webmaster = ReplyMail.objects.all().order_by('pk')[1].sendermail
Georges Gressot's avatar
Georges Gressot committed
35
36
37
38
39
40
41
42
    zz =1
except:
    pass

try:
    replymail =ReplyMail.objects.all().order_by('pk')[0].sendermail
except:
    replymail =BddAdmin.objects.all().order_by('pk')[0].contact
43

Georges Gressot's avatar
Georges Gressot committed
44
45
46
47
48
49
50
51
52
def serial_title(e):
    """sorting by title"""
    return e.title
def serial_id(e):
    """sorting by sid"""
    return e.sid
def coll_cn(e):
    """sorting by cn, title"""
    return (e.cn, e.title)
53
54


Georges Gressot's avatar
Georges Gressot committed
55
def selectbdd(request):
Georges Gressot's avatar
Georges Gressot committed
56

Georges Gressot's avatar
Georges Gressot committed
57
    k =logstatus(request)
Georges Gressot's avatar
Georges Gressot committed
58
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
59

Georges Gressot's avatar
Georges Gressot committed
60
    BDD_CHOICES =('',_('Sélectionnez votre projet')),
Georges Gressot's avatar
Georges Gressot committed
61

Georges Gressot's avatar
Georges Gressot committed
62
    for i in [n for n in range(100)]:
Georges Gressot's avatar
Georges Gressot committed
63
64
        if os.path.isfile('{:02d}.db'.format(i)):
            p = Project.objects.using('{:02d}'.format(i)).all().order_by('pk')[0].name
65
            BDD_CHOICES += ('{:02d}'.format(i), '{:02d}'.format(i) + " - " + p),
Georges Gressot's avatar
Georges Gressot committed
66

Georges Gressot's avatar
Georges Gressot committed
67
    if len(BDD_CHOICES) ==2:
68
69
        return HttpResponseRedirect(BDD_CHOICES[1][0])
        # return home(request, BDD_CHOICES[1][0])
Georges Gressot's avatar
Georges Gressot committed
70
71
72
    else:
        class BddSel_Form(forms.Form):
            bddname = forms.ChoiceField(required = True, widget=forms.Select, choices=BDD_CHOICES)
Georges Gressot's avatar
Georges Gressot committed
73

Georges Gressot's avatar
Georges Gressot committed
74
        f = BddSel_Form(request.POST or None)
Georges Gressot's avatar
Georges Gressot committed
75

Georges Gressot's avatar
Georges Gressot committed
76
77
        if f.is_valid():
            bdd = f.cleaned_data['bddname']
78
79
            return HttpResponseRedirect(bdd)
            # return home(request, bdd)
Georges Gressot's avatar
Georges Gressot committed
80

Georges Gressot's avatar
Georges Gressot committed
81
82
83
84
85
86
    #abstract :
    librnbr =0
    itemrecnbr =0
    instrnbr =0
    usernbr =len(User.objects.all())
    projnbr =len(BDD_CHOICES) -1
Georges Gressot's avatar
Georges Gressot committed
87
    totcand =0
Georges Gressot's avatar
Georges Gressot committed
88
89
90
91
    for bdd in BDD_CHOICES[1:]:
        librnbr +=len(Library.objects.using(bdd[0]).all())
        itemrecnbr +=len(ItemRecord.objects.using(bdd[0]).all())
        instrnbr +=len(Instruction.objects.using(bdd[0]).all())
Georges Gressot's avatar
Georges Gressot committed
92
93
94
95
96
97
        cand =[]
        for e in ItemRecord.objects.using(bdd[0]).all():
            if len(ItemRecord.objects.using(bdd[0]).filter(sid =e.sid)) >1 and not e.sid in cand:
                cand.append(e.sid)
        totcand +=len(cand)

Georges Gressot's avatar
Georges Gressot committed
98
    librnbr =librnbr - projnbr #checkers are not libraries ! (one checker per project)
Georges Gressot's avatar
Georges Gressot committed
99

Georges Gressot's avatar
Georges Gressot committed
100
101
102
    return render(request, 'epl/selectbdd.html', locals())


Georges Gressot's avatar
Georges Gressot committed
103
def logstatus(request):
Georges Gressot's avatar
Georges Gressot committed
104
    if request.user.is_authenticated:
Georges Gressot's avatar
Georges Gressot committed
105
        k = request.user.get_username()
Georges Gressot's avatar
Georges Gressot committed
106
107
108
    else:
        k =0
    return k
109

110

Georges Gressot's avatar
Georges Gressot committed
111
def home(request, bdd):
Georges Gressot's avatar
Georges Gressot committed
112

Georges Gressot's avatar
rollon    
Georges Gressot committed
113
114
    "Homepage"

Georges Gressot's avatar
Georges Gressot committed
115
    k =logstatus(request)
116
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
117

Georges Gressot's avatar
Georges Gressot committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
    #Vérification que tous les utilisateurs sont bien enregistrés
    email_list =[]
    for lib in Library.objects.using(bdd).all():
        if lib.contact and lib.contact not in email_list:
            email_list.append(lib.contact)
        if lib.contact_bis and lib.contact_bis not in email_list:
            email_list.append(lib.contact_bis)
        if lib.contact_ter and lib.contact_ter not in email_list:
            email_list.append(lib.contact_ter)
    for adm in BddAdmin.objects.using(bdd).all():
        if adm.contact not in email_list:
            email_list.append(adm.contact)
    utermail_list =[]
    for uter in Utilisateur.objects.using(bdd).all():
        utermail_list.append(uter.mail)

    diffa =set(email_list) - set(utermail_list)
    diffb =set(utermail_list) - set(email_list)
    if diffa !=set():
        messages.info(request, _("Anomalie détectée. Pas d'utilisateur associé aux mails suivants : ") + str(diffa) + ". " + "Veuillez alerter l'administrateur")

    if diffb != set():
        messages.info(request, _("Anomalie détectée. Les utilisateurs dont les mails suivent sont inutilisés : ") + str(diffb) + ". " + "Veuillez alerter l'administrateur")

Georges Gressot's avatar
rollon    
Georges Gressot committed
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
    #La partie de code ci-dessous est reproduite dans la vue adminbase(request, bdd) = Synchronisation de la base locale (utilisateurs) avec la base générale (users)
    for e in Utilisateur.objects.using(bdd).all():#1/2 création d'éventuels nouveaux users dans la base générale
        try:
            user =User.objects.get(username =e.username)
        except:
            user =User.objects.create_user(username =e.username, email =e.mail, password ="glass onion")

    #2/2 (see upper, this order is important)
    suffixe = "@" + str(bdd)
    for j in User.objects.all(): #Suppression d'users pour lesquels l'utilisateur a été supprimé de la base locale
        if j.username[-3:] ==suffixe:
            try:
                utilisateur =Utilisateur.objects.using(bdd).get(username =j.username)
            except:
                j.delete() #suppression dans la bdd générale
Georges Gressot's avatar
Georges Gressot committed
157
158
159

    project = Project.objects.using(bdd).all().order_by('pk')[0].name

Georges Gressot's avatar
...    
Georges Gressot committed
160
    LIBRARY_CHOICES = ('', 'Choisissez votre bibliothèque'),('checker','checker'),
Georges Gressot's avatar
Georges Gressot committed
161
162
163
164
    if Library.objects.using(bdd).all().exclude(name ='checker'):
        for l in Library.objects.using(bdd).all().exclude(name ='checker').order_by('name'):
            LIBRARY_CHOICES += (l.name, l.name),

Georges Gressot's avatar
...    
Georges Gressot committed
165
166
167
168
169
170
171
172
173
174
175
    class FeatureForm(forms.ModelForm):
        class Meta:
            model = Feature
            fields = ('libname', 'feaname',)
            widgets = {
                'libname' : forms.Select(choices=LIBRARY_CHOICES),
                'feaname' : forms.RadioSelect(choices=FEATURE_CHOICES),
            }

    #Feature input :
    i = Feature()
Georges Gressot's avatar
Georges Gressot committed
176

Georges Gressot's avatar
...    
Georges Gressot committed
177
    form = FeatureForm(request.POST, instance =i)
Georges Gressot's avatar
Georges Gressot committed
178

Georges Gressot's avatar
...    
Georges Gressot committed
179
180
181
182
183
184
185
186
187
    if form.is_valid():
        lid = Library.objects.using(bdd).get(name =i.libname).lid
        feature =i.feaname
        if not Feature.objects.using(bdd).filter(feaname =feature, libname =i.libname):
            i.save(using=bdd)

        if lid =="999999999":
            if feature =='instrtodo':
                return instrtodo(request, bdd, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
188
            else:
Georges Gressot's avatar
...    
Georges Gressot committed
189
190
191
192
193
194
195
196
197
198
                return checkinstr(request, bdd)
        else:
            if feature =='ranking':
                return ranktotake(request, bdd, lid, 'title')
            elif feature =='arbitration':
                return arbitration(request, bdd, lid, 'title')
            elif feature =='instrtodo':
                return instrtodo(request, bdd, lid, 'title')
            elif feature =='edition':
                return tobeedited(request, bdd, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
199

Georges Gressot's avatar
Georges Gressot committed
200
    #abstract :
Georges Gressot's avatar
Georges Gressot committed
201
    usernbr =len(Utilisateur.objects.using(bdd).all())
202
203
204
    librnbr =len(Library.objects.using(bdd).all()) -1  #checkers are not libraries ! (one checker per project)
    itemrecnbr =len(ItemRecord.objects.using(bdd).all())
    instrnbr =len(Instruction.objects.using(bdd).all())
Georges Gressot's avatar
Georges Gressot committed
205
206
207
208
    cand =[]
    for e in ItemRecord.objects.using(bdd).all():
        if len(ItemRecord.objects.using(bdd).filter(sid =e.sid)) >1 and not e.sid in cand:
            cand.append(e.sid)
209
    totcand =len(cand)
Georges Gressot's avatar
Georges Gressot committed
210

211
    return render(request, 'epl/home.html', locals())
212

Georges Gressot's avatar
rollon    
Georges Gressot committed
213
@login_required
Georges Gressot's avatar
Georges Gressot committed
214
215
216
def adminbase(request, bdd):

    #contrôle d'accès ici
Georges Gressot's avatar
rollon    
Georges Gressot committed
217
218
219
    if not len(BddAdmin.objects.using(bdd).filter(contact =request.user.email)):
        messages.info(request, _("Vous avez été renvoyé à cette page parce que vous n'avez pas les droits d'accès à la page que vous demandiez"))
        return home(request, bdd)
Georges Gressot's avatar
Georges Gressot committed
220
221
222

    k =logstatus(request)
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
223
    url ="/" + bdd + "/adminbase"
Georges Gressot's avatar
Georges Gressot committed
224
    suffixe = "@" + str(bdd)
Georges Gressot's avatar
Georges Gressot committed
225

226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
    # gestion des alertes (début)
    class AlertSettings(forms.Form):
        gkr = forms.BooleanField(required=False, initial =Proj_setting.objects.using(bdd)[0].rkg)
        bra = forms.BooleanField(required=False, initial =Proj_setting.objects.using(bdd)[0].arb)
        sni = forms.BooleanField(required=False, initial =Proj_setting.objects.using(bdd)[0].ins)
        ide = forms.BooleanField(required=False, initial =Proj_setting.objects.using(bdd)[0].edi)

    projsetform = AlertSettings(request.POST or None)
    if projsetform.is_valid():
        settg =Proj_setting.objects.using(bdd).all().order_by('pk')[0]
        settg.rkg =projsetform.cleaned_data['gkr']
        settg.arb =projsetform.cleaned_data['bra']
        settg.ins =projsetform.cleaned_data['sni']
        settg.edi =projsetform.cleaned_data['ide']
        settg.save(using =bdd)
        messages.info(request, _("Les alertes ont été reconfigurées avec succès"))
    # gestion des alertes (fin)

Georges Gressot's avatar
Georges Gressot committed
244
245
246
247
248
249
    EXCLUSION_CHOICES = ('', ''),
    for e in Exclusion.objects.using(bdd).all().order_by('label'):
        EXCLUSION_CHOICES += (e.label, e.label),
    EXCLUSION_CHOICES += ("Autre (Commenter)", _("Autre (Commenter)")),
    exclnbr =len(EXCLUSION_CHOICES) -1
    project = Project.objects.using(bdd).all().order_by('pk')[0].name
Georges Gressot's avatar
Georges Gressot committed
250
251
    abstract =Project.objects.using(bdd).all().order_by('pk')[0].descr
    extractdate =Project.objects.using(bdd).all().order_by('pk')[0].date
Georges Gressot's avatar
Georges Gressot committed
252
253

    #Stuff about project
Georges Gressot's avatar
Georges Gressot committed
254
    class ProjNameForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
255
        projname = forms.CharField(required =True, widget=forms.TextInput(attrs={'size': '30'}), max_length=30, label =_("project code name"))
Georges Gressot's avatar
Georges Gressot committed
256
257
258
259
260
261
262
263
264
265
266
267
    class ProjDescrForm(forms.Form):
        projdescr =forms.CharField(required =True, widget=forms.Textarea(attrs={'rows':1, 'cols':50},), max_length=300, label =_("project description"))
    class ProjDateForm(forms.Form):
        projdate =forms.CharField(required =True, widget=forms.TextInput(attrs={'size': '50'}), max_length=50, label =_("database extraction date"))
    projnamform = ProjNameForm(request.POST or None)
    projdescform = ProjDescrForm(request.POST or None)
    projdateform = ProjDateForm(request.POST or None)

    if projnamform.is_valid():
        prj =Project.objects.using(bdd).all().order_by('pk')[0]
        prj.name =projnamform.cleaned_data['projname']
        prj.save(using =bdd)
Georges Gressot's avatar
Georges Gressot committed
268
269
        messages.info(request, _("Le nom du projet a été modifié avec succès"))
        # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
270
271
272
273
274

    if projdescform.is_valid():
        prj =Project.objects.using(bdd).all().order_by('pk')[0]
        prj.descr =projdescform.cleaned_data['projdescr']
        prj.save(using =bdd)
Georges Gressot's avatar
Georges Gressot committed
275
276
        messages.info(request, _("Le résumé du projet a été modifié avec succès"))
        # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
277
278
279
280
281

    if projdateform.is_valid():
        prj =Project.objects.using(bdd).all().order_by('pk')[0]
        prj.date =projdateform.cleaned_data['projdate']
        prj.save(using =bdd)
Georges Gressot's avatar
Georges Gressot committed
282
283
        messages.info(request, _("La date d'extraction de la base a été modifiée avec succès"))
        # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
284

Georges Gressot's avatar
Georges Gressot committed
285
    #Stuff about exclusions
Georges Gressot's avatar
Georges Gressot committed
286
287
288
    class ExcluForm(forms.Form):
        exclusup = forms.CharField(required =True, widget=forms.TextInput(attrs={'size': '30'}), max_length=30, label =_("exclusion suppl"))
    exclform =ExcluForm(request.POST or None)
Georges Gressot's avatar
Georges Gressot committed
289
290
291
292
293
    class ExcluSupprForm(forms.Form):
        exclreason = forms.ChoiceField(required = True, widget=forms.Select, choices=EXCLUSION_CHOICES[:-1], label =_("Motif d'exclusion à supprimer"))
        exclmod = forms.CharField(required =False, widget=forms.TextInput(attrs={'size': '30'}), max_length=30, label =_("exclusion modifiée"))
        suppr = forms.BooleanField(required=False)
    exclsupprform =ExcluSupprForm(request.POST or None)
Georges Gressot's avatar
Georges Gressot committed
294

Georges Gressot's avatar
Georges Gressot committed
295
    if exclform.is_valid():
Georges Gressot's avatar
Georges Gressot committed
296
297
298
        try:
            op =Exclusion.objects.using(bdd).get(label =exclform.cleaned_data['exclusup'])
            messages.info(request, _('Cette exclusion existe déjà'))
Georges Gressot's avatar
Georges Gressot committed
299
            # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
300
301
302
303
304
        except:
            newexcl =Exclusion()
            newexcl.label =exclform.cleaned_data['exclusup']
            newexcl.save(using =bdd)
            messages.info(request, _('Exclusion ajoutée avec succès'))
Georges Gressot's avatar
Georges Gressot committed
305
            # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
    if exclsupprform.is_valid():
        op =Exclusion.objects.using(bdd).get(label =exclsupprform.cleaned_data['exclreason'])
        if exclsupprform.cleaned_data['suppr'] ==True:
            if len(ItemRecord.objects.using(bdd).filter(excl =exclsupprform.cleaned_data['exclreason'])):
                messages.info(request, _('Suppression impossible : Cete exclusion a déjà servi (vous pouvez éventuellement modifier son intitulé)'))
            else:
                op.delete(using =bdd)
                messages.info(request, _('Exclusion supprimée avec succès'))
        else:
            if exclsupprform.cleaned_data['exclmod']:
                for it in ItemRecord.objects.using(bdd).filter(excl =exclsupprform.cleaned_data['exclreason']):
                    if it.excl ==exclsupprform.cleaned_data['exclreason']:
                        it.excl =exclsupprform.cleaned_data['exclmod']
                        it.save(using =bdd)
                op.label =exclsupprform.cleaned_data['exclmod']
                op.save(using =bdd)
                messages.info(request, _('Exclusion modifiée avec succès'))
            else:
                messages.info(request, _("Vous n'avez pas complété le formulaire correctement"))
Georges Gressot's avatar
Georges Gressot committed
325

Georges Gressot's avatar
Georges Gressot committed
326
327

    #Stuff about libraries
Georges Gressot's avatar
Georges Gressot committed
328
    LIBRARY_CHOICES = ('', _('Sélectionnez la bibliothèque')), ('checker', 'checker'),
Georges Gressot's avatar
Georges Gressot committed
329
330
331
332
    if Library.objects.using(bdd).all().exclude(name ='checker'):
        for l in Library.objects.using(bdd).all().exclude(name ='checker').order_by('name'):
            LIBRARY_CHOICES += (l.name, l.name),

Georges Gressot's avatar
rollong    
Georges Gressot committed
333
334
    CONTACT_CHOICE =('', _('Contact')), ('1', '1'), ('2', '2'), ('3', '3'),

Georges Gressot's avatar
Georges Gressot committed
335
    class LibrMCurNameForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
336
337
        curname = forms.ChoiceField(required = True, widget=forms.Select, choices=LIBRARY_CHOICES, label =_("bibliothèque"))
        # curname = forms.CharField(required =True, widget=forms.TextInput(attrs={'size': '30'}), max_length=30, label =_("nom de la bib"))
Georges Gressot's avatar
Georges Gressot committed
338
    class LibrMNewNameForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
339
        newlibrname = forms.CharField(required =True, widget=forms.TextInput(attrs={'size': '30', 'title': _("Action rétroactive applicable à l'ensemble des instructions")}), max_length=30, label =_("nom de la bib"))
Georges Gressot's avatar
rollong    
Georges Gressot committed
340
    class LibrMCtcForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
341
342
        name = forms.ChoiceField(required = True, widget=forms.Select, choices=LIBRARY_CHOICES, label =_("bibliothèque"))
        # name = forms.CharField(required =True, widget=forms.TextInput(attrs={'size': '30'}), max_length=30, label =_("nom de la bib"))
Georges Gressot's avatar
rollong    
Georges Gressot committed
343
344
345
        contactnbr =forms.ChoiceField(required = True, widget=forms.Select, choices=CONTACT_CHOICE)
        contact = forms.EmailField(required =False, label ='email 1')
        ident = forms.CharField(required =False, widget=forms.TextInput(attrs=\
Georges Gressot's avatar
Georges Gressot committed
346
347
        {'placeholder': "Oriane@" + bdd, 'title': _("Suffixe obligatoire") + \
        ' : ' + '@' + bdd + '. ' + \
Georges Gressot's avatar
Georges Gressot committed
348
        _("Saisissez un nom d'utilisateur valide. Il ne peut contenir que des lettres, des nombres ou les caractères « @ », « . », « + », « - » et « _ ».")}), \
Georges Gressot's avatar
rollong    
Georges Gressot committed
349
350
        max_length=30, label =_("identifiant 1"))
        suppr = forms.BooleanField(required=False)
Georges Gressot's avatar
Georges Gressot committed
351

Georges Gressot's avatar
Georges Gressot committed
352
    liblist =Library.objects.using(bdd).exclude(name ='checker')
Georges Gressot's avatar
Georges Gressot committed
353
    sizelib =len(liblist)
Georges Gressot's avatar
Georges Gressot committed
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
    try:
        bis = Utilisateur.objects.using(bdd).get(mail =Library.objects.using(bdd).get(name ='checker').contact_bis)
    except:
        bis =None
    try:
        ter = Utilisateur.objects.using(bdd).get(mail =Library.objects.using(bdd).get(name ='checker').contact_ter)
    except:
        ter =None

    libtuple =(Library.objects.using(bdd).get(name ='checker'), Utilisateur.objects.using(bdd).get(mail =Library.objects.using(bdd).get(name ='checker').contact), bis, ter),
    for libelmt in liblist:
        try:
            bis = Utilisateur.objects.using(bdd).get(mail =Library.objects.using(bdd).get(name =libelmt.name).contact_bis)
        except:
            bis =None
        try:
            ter = Utilisateur.objects.using(bdd).get(mail =Library.objects.using(bdd).get(name =libelmt.name).contact_ter)
        except:
            ter =None
        libtuple +=(Library.objects.using(bdd).get(name =libelmt.name), Utilisateur.objects.using(bdd).get(mail =Library.objects.using(bdd).get(name =libelmt.name).contact), bis, ter),
Georges Gressot's avatar
Georges Gressot committed
374

Georges Gressot's avatar
Georges Gressot committed
375
376
    formlibname = LibrMCurNameForm(request.POST or None)
    formnewlibname = LibrMNewNameForm(request.POST or None)
Georges Gressot's avatar
rollong    
Georges Gressot committed
377
378
    formlibct = LibrMCtcForm(request.POST or None)

Georges Gressot's avatar
Georges Gressot committed
379
380
381
    if formlibname.is_valid() and formnewlibname.is_valid():
        if not formlibname.cleaned_data['curname'] ==formnewlibname.cleaned_data['newlibrname']:
            if formlibname.cleaned_data['curname'] =='checker' or formnewlibname.cleaned_data['newlibrname'] =='checker':
Georges Gressot's avatar
Georges Gressot committed
382
383
                messages.info(request, _("'checker' est un nom réservé"))
                # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
384
            else:
Georges Gressot's avatar
Georges Gressot committed
385
386
387
388
389
390
391
392
393
394
395
396
397
                try:
                    bibliot =Library.objects.using(bdd).get(name =formlibname.cleaned_data['curname'])
                    curname = formlibname.cleaned_data['curname']
                    newname = formnewlibname.cleaned_data['newlibrname']
                    for insn in Instruction.objects.using(bdd).filter(name =curname):
                        insn.name =newname
                        insn.save(using =bdd)
                    for inso in Instruction.objects.using(bdd).filter(oname =curname):
                        inso.oname =newname
                        inso.save(using =bdd)
                    lib = Library.objects.using(bdd).get(name =curname)
                    lib.name =formnewlibname.cleaned_data['newlibrname']
                    lib.save(using =bdd)
Georges Gressot's avatar
Georges Gressot committed
398
399
                    messages.info(request, _("Nom de la bibliothèque modifié avec succès"))
                    # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
400
                except:
Georges Gressot's avatar
Georges Gressot committed
401
402
                    pass
                    # messages.info(request, _("Pas de bibliothèque au nom que vous avez indiqué"))
Georges Gressot's avatar
Georges Gressot committed
403
                    # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
404

Georges Gressot's avatar
rollong    
Georges Gressot committed
405
    BDD_CHOICES =('', ''),
Georges Gressot's avatar
Georges Gressot committed
406
    for i in [n for n in range(100)]:
Georges Gressot's avatar
rollong    
Georges Gressot committed
407
408
409
410
        if os.path.isfile('{:02d}.db'.format(i)):
            p = Project.objects.using('{:02d}'.format(i)).all().order_by('pk')[0].name
            BDD_CHOICES += ('{:02d}'.format(i), p),
    BDD_CHOICES =BDD_CHOICES[1:]
Georges Gressot's avatar
Georges Gressot committed
411

Georges Gressot's avatar
rollong    
Georges Gressot committed
412
    if formlibct.is_valid():
Georges Gressot's avatar
Georges Gressot committed
413
414
415
416
417
418
        try:
            if Library.objects.using(bdd).get(name =formlibct.cleaned_data['name']) in Library.objects.using(bdd).all():
                lib = Library.objects.using(bdd).get(name =formlibct.cleaned_data['name'])
                if formlibct.cleaned_data['suppr'] ==True:
                    compteura =0
                    if formlibct.cleaned_data['contactnbr'] =='2':
Georges Gressot's avatar
Georges Gressot committed
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
                        try:
                            for u in Library.objects.using(bdd).all():
                                if u.contact ==lib.contact_bis:
                                    compteura +=1
                                if u.contact_bis ==lib.contact_bis:
                                    compteura +=1
                                if u.contact_ter ==lib.contact_bis:
                                    compteura +=1
                            for v in BddAdmin.objects.using(bdd).all():
                                if v.contact ==lib.contact_bis:
                                    compteura +=1
                            if compteura ==1:
                                user =User.objects.get(username =Utilisateur.objects.using(bdd).get(mail =lib.contact_bis).username)
                                uter =Utilisateur.objects.using(bdd).get(mail =lib.contact_bis)
                                user.delete()
                                uter.delete()
                            lib.contact_bis =None
                            lib.save(using =bdd)
                            messages.info(request, _('Contact supprimé avec succès'))
                        except:
                            messages.info(request, _("(Le contact était déjà vacant)"))

Georges Gressot's avatar
Georges Gressot committed
441
442
                    compteurb =0
                    if formlibct.cleaned_data['contactnbr'] =='3':
Georges Gressot's avatar
Georges Gressot committed
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
                        try:
                            for u in Library.objects.using(bdd).all():
                                if u.contact ==lib.contact_ter:
                                    compteurb +=1
                                if u.contact_bis ==lib.contact_ter:
                                    compteurb +=1
                                if u.contact_ter ==lib.contact_ter:
                                    compteurb +=1
                            for v in BddAdmin.objects.using(bdd).all():
                                if v.contact ==lib.contact_ter:
                                    compteurb +=1
                            if compteurb ==1:
                                user =User.objects.get(username =Utilisateur.objects.using(bdd).get(mail =lib.contact_ter).username)
                                uter =Utilisateur.objects.using(bdd).get(mail =lib.contact_ter)
                                user.delete()
                                uter.delete()
                            lib.contact_ter =None
                            lib.save(using =bdd)
                            messages.info(request, _('Contact supprimé avec succès'))
                        except:
                            messages.info(request, _("(Le contact était déjà vacant)"))
                        # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
465
                    if formlibct.cleaned_data['contactnbr'] =='1':
Georges Gressot's avatar
Georges Gressot committed
466
467
                        messages.info(request, _('Le contact principal ne peut pas être supprimé'))
                        # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
468
                else:#formlibct.cleaned_data['suppr'] ==False
Georges Gressot's avatar
Georges Gressot committed
469
470
471
472
473
                    if not formlibct.cleaned_data['ident'] and formlibct.cleaned_data['contact']:
                        messages.info(request, _("Echec : Vous avez omis l'identifiant"))
                    elif formlibct.cleaned_data['ident'] and not formlibct.cleaned_data['contact']:
                        messages.info(request, _("Echec : Vous avez omis l'email"))
                    else:#Formulaire complet
Georges Gressot's avatar
Georges Gressot committed
474
475
                        try:#utilisateur déjà présent dans la base
                            uter =Utilisateur.objects.using(bdd).get(username =formlibct.cleaned_data['ident'], mail =formlibct.cleaned_data['contact'])
Georges Gressot's avatar
Georges Gressot committed
476
                            if formlibct.cleaned_data['contactnbr'] =='1':
Georges Gressot's avatar
Georges Gressot committed
477
478
479
480
481
482
483
484
485
486
                                lib.contact =formlibct.cleaned_data['contact']
                                lib.save(using =bdd)
                            if formlibct.cleaned_data['contactnbr'] =='2':
                                lib.contact_bis =formlibct.cleaned_data['contact']
                                lib.save(using =bdd)
                            if formlibct.cleaned_data['contactnbr'] =='3':
                                lib.contact_ter =formlibct.cleaned_data['contact']
                                lib.save(using =bdd)
                                messages.info(request, _("Modification effectuée avec succès (réemploi d'un utilisateur déjà présent dans la base)"))
                                # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
487
488
489
490
491
492
493
                        except:#utilisateur absent de la base
                            if len(Utilisateur.objects.using(bdd).filter(username =formlibct.cleaned_data['ident'])):
                                messages.info(request, _("Echec : l'identifiant est déjà attribué à un autre utilisateur"))
                            elif len(Utilisateur.objects.using(bdd).filter(mail =formlibct.cleaned_data['contact'])):
                                messages.info(request, _("Echec : l'email est déjà attribué à un autre utilisateur"))
                            else:
                                if str(formlibct.cleaned_data['ident'])[-3:] !=suffixe:
Georges Gressot's avatar
roll on    
Georges Gressot committed
494
                                    messages.info(request, _("Echec : L'identifiant doit se terminer en {}".format(suffixe)))
Georges Gressot's avatar
Georges Gressot committed
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
                                else:
                                    try:
                                        user =User.objects.create_user(username =formlibct.cleaned_data['ident'], email =formlibct.cleaned_data['contact'], password ="glass onion")
                                        uter =Utilisateur(username =formlibct.cleaned_data['ident'], mail =formlibct.cleaned_data['contact'])
                                        uter.save(using =bdd)
                                        if formlibct.cleaned_data['contactnbr'] =='1':
                                            lib.contact =formlibct.cleaned_data['contact']
                                            lib.save(using =bdd)
                                        if formlibct.cleaned_data['contactnbr'] =='2':
                                            lib.contact_bis =formlibct.cleaned_data['contact']
                                            lib.save(using =bdd)
                                        if formlibct.cleaned_data['contactnbr'] =='3':
                                            lib.contact_ter =formlibct.cleaned_data['contact']
                                            lib.save(using =bdd)
                                        messages.info(request, _("Modification effectuée avec succès (un nouvel utilisateur a été créé)"))
                                    except:
                                        messages.info(request, _("L'identifiant ne respecte pas le format prescrit"))
Georges Gressot's avatar
Georges Gressot committed
512
        except:
Georges Gressot's avatar
Georges Gressot committed
513
            pass
Georges Gressot's avatar
Georges Gressot committed
514

Georges Gressot's avatar
Georges Gressot committed
515
516
    #Stuff about bddadministrators
    admintuple =('', "Sélectionnez l'administrateur"),
Georges Gressot's avatar
Georges Gressot committed
517
    for b in BddAdmin.objects.using(bdd).all():
Georges Gressot's avatar
roll on    
Georges Gressot committed
518
        admintuple +=(b.contact, Utilisateur.objects.using(bdd).get(mail =BddAdmin.objects.using(bdd).get(contact =b.contact).contact)),
Georges Gressot's avatar
Georges Gressot committed
519
    admintup =admintuple[1:]
Georges Gressot's avatar
on    
Georges Gressot committed
520
521
    sizeadm =len(BddAdmin.objects.using(bdd).all())

Georges Gressot's avatar
Georges Gressot committed
522
    class ProjadmAjForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
523
524
        contactajadm = forms.EmailField(required =True, label ='current email')
        identajadm = forms.CharField(required =True, widget=forms.TextInput(attrs=\
Georges Gressot's avatar
Georges Gressot committed
525
        {'placeholder': "Rosemonde@" + bdd, 'title': _("Suffixe obligatoire") + \
Georges Gressot's avatar
on    
Georges Gressot committed
526
527
528
        ' : ' + '@' + bdd + '. ' + \
        "Saisissez un nom d'utilisateur valide. Il ne peut contenir que des lettres, des nombres ou les caractères « @ », « . », « + », « - » et « _ »."}), \
        max_length=30, label =_("identifiant"))
Georges Gressot's avatar
Georges Gressot committed
529

Georges Gressot's avatar
Georges Gressot committed
530
531
532
    projajadmform =ProjadmAjForm(request.POST or None)

    class ProjadmSupprForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
533
534
        contactsuadm = forms.ChoiceField(required = True, widget=forms.Select, choices=admintuple, label =_("email courant"))
        suppradm = forms.BooleanField(required=True)
Georges Gressot's avatar
Georges Gressot committed
535
536
537

    projsuppradmform =ProjadmSupprForm(request.POST or None)

Georges Gressot's avatar
roll on    
Georges Gressot committed
538
    if projajadmform.is_valid():
Georges Gressot's avatar
Georges Gressot committed
539
        try:
Georges Gressot's avatar
roll on    
Georges Gressot committed
540
541
            newadm =BddAdmin.objects.using(bdd).get(contact =projajadmform.cleaned_data['contactajadm'])
            messages.info(request, _("(Administrateur déjà enregistré)"))
Georges Gressot's avatar
Georges Gressot committed
542
        except:
Georges Gressot's avatar
roll on    
Georges Gressot committed
543
544
545
546
547
548
            try:
                uter =Utilisateur.objects.using(bdd).get(username =projajadmform.cleaned_data['identajadm'], mail =projajadmform.cleaned_data['contactajadm'])
                newadm =BddAdmin(contact =projajadmform.cleaned_data['contactajadm'])
                newadm.save(using =bdd)
                messages.info(request, _("Administrateur ajouté avec succès (réemploi d'un utilisateur déjà présent dans la base)"))
            except:
Georges Gressot's avatar
Georges Gressot committed
549
                try:
Georges Gressot's avatar
roll on    
Georges Gressot committed
550
551
                    uter =Utilisateur.objects.using(bdd).get(username =projajadmform.cleaned_data['identajadm'])
                    messages.info(request, _("Echec : L'identifiant saisi est déjà utilisé"))
Georges Gressot's avatar
Georges Gressot committed
552
                except:
Georges Gressot's avatar
roll on    
Georges Gressot committed
553
554
                    try:
                        uter =Utilisateur.objects.using(bdd).get(mail =projajadmform.cleaned_data['contactajadm'])
Georges Gressot's avatar
rollon    
Georges Gressot committed
555
                        messages.info(request, _("Echec : L'email saisi est déjà utilisé"))
Georges Gressot's avatar
roll on    
Georges Gressot committed
556
557
558
559
560
561
562
563
564
565
566
567
568
                    except:
                        if str(projajadmform.cleaned_data['identajadm'])[-3:] !=suffixe:
                            messages.info(request, _("Echec : L'identifiant doit se terminer en {}".format(suffixe)))
                        else:
                            try:
                                uter =Utilisateur(username =projajadmform.cleaned_data['identajadm'], mail =projajadmform.cleaned_data['contactajadm'])
                                user =User.objects.create_user(username =projajadmform.cleaned_data['identajadm'], email =projajadmform.cleaned_data['contactajadm'], password ="glass onion")
                                uter.save(using =bdd)
                                newadm =BddAdmin(contact =projajadmform.cleaned_data['contactajadm'])
                                newadm.save(using =bdd)
                                messages.info(request, _("Administrateur ajouté avec succès (un nouvel utilisateur a été créé)"))
                            except:
                                messages.info(request, _("Echec : L'identifiant ne respecte pas le format prescrit"))
Georges Gressot's avatar
Georges Gressot committed
569
570
571
572
573

    if projsuppradmform.is_valid():
        if len(BddAdmin.objects.using(bdd).all()) ==1:
            messages.info(request, _("Vous ne pouvez pas supprimer le dernier administrateur restant"))
        else:
Georges Gressot's avatar
Georges Gressot committed
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
            suppradm =BddAdmin.objects.using(bdd).get(contact =projsuppradmform.cleaned_data['contactsuadm'])
            compteurc =0
            for u in Library.objects.using(bdd).all():
                if u.contact ==suppradm.contact:
                    compteurc +=1
                if u.contact_bis ==suppradm.contact:
                    compteurc +=1
                if u.contact_ter ==suppradm.contact:
                    compteurc +=1
            for v in BddAdmin.objects.using(bdd).all():
                if v.contact ==suppradm.contact:
                    compteurc +=1
            if compteurc ==1:
                user =User.objects.get(username =Utilisateur.objects.using(bdd).get(mail =projsuppradmform.cleaned_data['contactsuadm']).username)
                uter =Utilisateur.objects.using(bdd).get(mail =projsuppradmform.cleaned_data['contactsuadm'])
                user.delete()
                uter.delete()
Georges Gressot's avatar
Georges Gressot committed
591
            suppradm.delete(using =bdd)
Georges Gressot's avatar
Georges Gressot committed
592
593
            messages.info(request, _('Administrateur supprimé avec succès'))

Georges Gressot's avatar
roll on    
Georges Gressot committed
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
    #Stuff about utilisateurs :
    uterstuple =('', "Sélectionnez l'utilisateur"),
    for u in Utilisateur.objects.using(bdd).all().order_by("username"):
        uterstuple +=(u.mail, Utilisateur.objects.using(bdd).get(mail =u.mail)),
    sizeuters =len(Utilisateur.objects.using(bdd).all())

    class UtModForm(forms.Form):
        uterxy = forms.ChoiceField(required = True, widget=forms.Select, choices=uterstuple, label =_("Utilisateur"))
        newuterid = forms.CharField(required =False, widget=forms.TextInput(attrs=\
        {'placeholder': "Marcel@" + bdd, 'title': _("Suffixe obligatoire") + \
        ' : ' + '@' + bdd + '. ' + \
        "Saisissez un nom d'utilisateur valide. Il ne peut contenir que des lettres, des nombres ou les caractères « @ », « . », « + », « - » et « _ »."}), \
        max_length=30, label =_("nouvel identifiant de l'utilisateur"))
        newutermail = forms.EmailField(required =False, label ="nouvel email de l'utilisateur")

    utermodform =UtModForm(request.POST or None)
Georges Gressot's avatar
Georges Gressot committed
610

Georges Gressot's avatar
roll on    
Georges Gressot committed
611
612
613
614
615
616
    if utermodform.is_valid():
        if utermodform.cleaned_data['newuterid'] and utermodform.cleaned_data['newutermail']:
            messages.info(request, _("Echec : Ne complétez qu'un des arguments à la fois"))
        else:
            try:
                uter =Utilisateur.objects.using(bdd).get(mail =utermodform.cleaned_data['newutermail'])
Georges Gressot's avatar
rollon    
Georges Gressot committed
617
                messages.info(request, _("Echec : L'email saisi est déjà utilisé"))
Georges Gressot's avatar
roll on    
Georges Gressot committed
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
            except:
                try:
                    uter =Utilisateur.objects.using(bdd).get(username =utermodform.cleaned_data['newuterid'])
                    messages.info(request, _("Echec : L'identifiant saisi est déjà utilisé"))
                except:
                    if utermodform.cleaned_data['newuterid']:
                        if str(utermodform.cleaned_data['newuterid'])[-3:] !=suffixe:
                            messages.info(request, _("Echec : L'identifiant doit se terminer en {}".format(suffixe)))
                        else:
                            try:
                                uter =Utilisateur.objects.using(bdd).get(mail =utermodform.cleaned_data['uterxy'])
                                uter.username =utermodform.cleaned_data['newuterid']
                                user =User.objects.get(username =Utilisateur.objects.using(bdd).get(mail =utermodform.cleaned_data['uterxy']).username)
                                user.username =utermodform.cleaned_data['newuterid']
                                uter.save(using =bdd)
Georges Gressot's avatar
rollon    
Georges Gressot committed
633
                                user.save()
Georges Gressot's avatar
roll on    
Georges Gressot committed
634
635
636
637
                                messages.info(request, _("L'identifiant de l'utilisateur a été modifié avec succès"))
                            except:
                                messages.info(request, _("L'identifiant ne respecte pas le format prescrit"))
                    elif utermodform.cleaned_data['newutermail']:
Georges Gressot's avatar
rollon    
Georges Gressot committed
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
                        try:
                            uter =Utilisateur.objects.using(bdd).get(mail =utermodform.cleaned_data['uterxy'])
                            uter.mail =utermodform.cleaned_data['newutermail']
                            user =User.objects.get(username =Utilisateur.objects.using(bdd).get(mail =utermodform.cleaned_data['uterxy']).username)
                            for l in Library.objects.using(bdd).all():
                                if l.contact ==utermodform.cleaned_data['uterxy']:
                                    l.contact =utermodform.cleaned_data['newutermail']
                                if l.contact_bis ==utermodform.cleaned_data['uterxy']:
                                    l.contact_bis =utermodform.cleaned_data['newutermail']
                                if l.contact_ter ==utermodform.cleaned_data['uterxy']:
                                    l.contact_ter =utermodform.cleaned_data['newutermail']
                                l.save(using =bdd)
                            if BddAdmin.objects.using(bdd).filter(contact =utermodform.cleaned_data['uterxy']):
                                adm =BddAdmin.objects.using(bdd).get(contact =utermodform.cleaned_data['uterxy'])
                                adm.contact =utermodform.cleaned_data['newutermail']
                                adm.save(using =bdd)
                            uter.save(using =bdd)
                            user.save()
                            messages.info(request, _("L'email de l'utilisateur a été modifié avec succès"))
                        except:
                            pass
Georges Gressot's avatar
roll on    
Georges Gressot committed
659
660
661
662



    # (la suppression éventuelle de l'utilisateur et du user est factorisée en fin de vue) ????
Georges Gressot's avatar
Georges Gressot committed
663

Georges Gressot's avatar
Georges Gressot committed
664
665
666
667
668
    # messages.debug(request, '%s SQL statements were executed.' % count)
    # messages.info(request, 'Three credits remain in your account.')
    # messages.success(request, 'Profile details updated.')
    # messages.warning(request, 'Your account expires in three days.')
    # messages.error(request, 'Document deleted.')
Georges Gressot's avatar
Georges Gressot committed
669
670
671
672
673
    # messages.info(request, 'Hello world.')
    # messages.info(request, messages.SUCCESS, 'Hello wolafùlrld.')

    if request.method =="POST":
        return HttpResponseRedirect(url)
Georges Gressot's avatar
rollon    
Georges Gressot committed
674
675
676
    else:#request.method =="GET
    #La partie de code ci-dessous est reproduite dans la vue home(request, bdd) = Synchronisation de la base locale (utilisateurs) avec la base générale (users)
        for e in Utilisateur.objects.using(bdd).all():#1/2 création d'éventuels nouveaux users dans la base générale
Georges Gressot's avatar
Georges Gressot committed
677
678
679
680
681
            try:
                user =User.objects.get(username =e.username)
            except:
                user =User.objects.create_user(username =e.username, email =e.mail, password ="glass onion")

Georges Gressot's avatar
rollon    
Georges Gressot committed
682
        #2/2 (see upper, this order is important)
Georges Gressot's avatar
Georges Gressot committed
683
684
685
686
687
688
689
        suffixe = "@" + str(bdd)
        for j in User.objects.all(): #Suppression d'users pour lesquels l'utilisateur a été supprimé de la base locale
            if j.username[-3:] ==suffixe:
                try:
                    utilisateur =Utilisateur.objects.using(bdd).get(username =j.username)
                except:
                    j.delete() #suppression dans la bdd générale
Georges Gressot's avatar
Georges Gressot committed
690

Georges Gressot's avatar
Georges Gressot committed
691
692
    return render(request, 'epl/adminbase.html', locals())

Georges Gressot's avatar
Georges Gressot committed
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
@login_required
def globadm(request):

    """Global administration"""

    #contrôle d'accès ici
    if not request.user.is_staff:
        messages.info(request, _("Vous avez été renvoyé à cette page parce que vous n'avez pas les droits d'accès à la page que vous demandiez"))
        return selectbdd(request)

    k =logstatus(request)
    version =epl_version
    date =date_version
    host = str(request.get_host())

    return render(request, 'epl/globadm.html', locals())


Georges Gressot's avatar
Georges Gressot committed
711

Georges Gressot's avatar
Georges Gressot committed
712
def about(request):
713

Georges Gressot's avatar
Georges Gressot committed
714
    k =logstatus(request)
715
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
716
    date =date_version
717
    host = str(request.get_host())
Georges Gressot's avatar
Georges Gressot committed
718
    return render(request, 'epl/about.html', locals())
719
720


Georges Gressot's avatar
Georges Gressot committed
721
def contact(request):
722

Georges Gressot's avatar
Georges Gressot committed
723
    k =logstatus(request)
724
725
726
727
728
    version =epl_version
    date =date_version
    host = str(request.get_host())

    class ContactForm(forms.Form):
729
730
        object_list = (("Demande d'information", _("Demande d'information")), ("Bug", _("Bug")),\
         ("Réclamation", _("Réclamation")), ("Suggestion", _("Suggestion")), ("Avis", _("Avis")),  ("Autre", _("Autre")))
731
732
733
734
735
736
737
738
739
        object = forms.ChoiceField(required = True, widget=forms.Select, choices=object_list, label =_("Objet"))
        email = forms.EmailField(required = True, label =_("Votre adresse mail de contact"))
        email_confirm =forms.EmailField(required = True, label =_("Confirmation de l'adresse mail"))
        content = forms.CharField(required=True, widget=forms.Textarea, label =_("Votre message"))

    form = ContactForm(request.POST or None)
    if form.is_valid():
        recipient = form.cleaned_data['email']
        recipient_confirm = form.cleaned_data['email_confirm']
740
        subject2 = form.cleaned_data['object']
741
742
        body = form.cleaned_data['content']
        if recipient ==recipient_confirm:
Georges Gressot's avatar
Georges Gressot committed
743
744
745
            subject2 = "[eplouribousse]" + " - " + subject2
            subject1 = subject2 + " - " + version + " - " + host
            message1 = subject1 + " :\n" + "\n" + body
Georges Gressot's avatar
Georges Gressot committed
746
747
            message2 = _("Votre message a bien été envoyé au développeur de l'application qui y répondra prochainement")\
             + ".\n" + _("Ne répondez pas au présent mail s'il vous plaît") + ".\n" + \
748
             "Rappel de l'objet de votre message" + " : " + subject2 + \
Georges Gressot's avatar
Georges Gressot committed
749
750
751
             "\n" + _("Rappel de votre message") + " :\n" + \
              _("***** Début *****") + "\n" + _("Objet") +  " : " + subject2 + \
              "\n" + _("Corps") + " : " + "\n" + body + "\n" + _("*****  Fin  *****")
752
753
            dest1 = ["eplouribousse@gmail.com"]
            dest2 = [recipient]
754
755
            send_mail(subject1, message1, recipient, dest1, fail_silently=True, )
            send_mail(subject2, message2, replymail, dest2, fail_silently=True, )
756
757
            return render(request, 'epl/confirmation.html', locals())
        else:
758
759
760
761
            info =_("Attention : Les adresses doivent être identiques") + "."
    else:
        if request.method =="POST":
            info =_("Vérifier que les adresses sont correctes") + "."
762
763
764
765

    return render(request, 'epl/contact.html', locals())


766
767


Georges Gressot's avatar
Georges Gressot committed
768
def webmstr(request):
769

Georges Gressot's avatar
Georges Gressot committed
770
    k =logstatus(request)
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
    version =epl_version
    date =date_version
    host = str(request.get_host())

    class ContactForm(forms.Form):
        object_list = (("Demande d'information", _("Demande d'information")), ("Bug", _("Bug")),\
         ("Réclamation", _("Réclamation")), ("Suggestion", _("Suggestion")), ("Avis", _("Avis")),  ("Autre", _("Autre")))
        object = forms.ChoiceField(required = True, widget=forms.Select, choices=object_list, label =_("Objet"))
        email = forms.EmailField(required = True, label =_("Votre adresse mail de contact"))
        email_confirm =forms.EmailField(required = True, label =_("Confirmation de l'adresse mail"))
        content = forms.CharField(required=True, widget=forms.Textarea, label =_("Votre message"))

    form = ContactForm(request.POST or None)
    if form.is_valid():
        recipient = form.cleaned_data['email']
        recipient_confirm = form.cleaned_data['email_confirm']
        subject2 = form.cleaned_data['object']
        body = form.cleaned_data['content']
        if recipient ==recipient_confirm:
            subject2 = "[eplouribousse]" + " - " + subject2
            subject1 = subject2 + " - " + version + " - " + host
            message1 = subject1 + " :\n" + "\n" + body
Georges Gressot's avatar
Georges Gressot committed
793
794
795
796
797
798
            message2 = _("Votre message a bien été envoyé au webmaster qui y répondra prochainement")\
             + ".\n" + _("Ne répondez pas au présent mail s'il vous plaît") + ".\n" \
             + _("Rappel de votre message") + " :\n" + \
             _("***** Début *****") + "\n" + _("Objet") +  " : " + subject2 + \
             "\n" + _("Corps") + " : " + "\n" + body + "\n" + _("*****  Fin  *****")
            dest1 = [webmaster]
799
800
801
802
803
804
805
806
807
808
809
810
811
            dest2 = [recipient]
            send_mail(subject1, message1, recipient, dest1, fail_silently=True, )
            send_mail(subject2, message2, replymail, dest2, fail_silently=True, )
            return render(request, 'epl/confirmation.html', locals())
        else:
            info =_("Attention : Les adresses doivent être identiques") + "."
    else:
        if request.method =="POST":
            info =_("Vérifier que les adresses sont correctes") + "."

    return render(request, 'epl/webmaster.html', locals())


Georges Gressot's avatar
on ...    
Georges Gressot committed
812
813
814
815
816
817
818
819
820
821
822
823
def projmstr(request, bdd):

    k =logstatus(request)
    version =epl_version
    date =date_version
    host = str(request.get_host())
    project = Project.objects.using(bdd).all().order_by('pk')[0].name
    dest1 =[]
    for bddadm in BddAdmin.objects.using(bdd).all():
        dest1.append(bddadm.contact)

    class ContactForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
824
825
826
827
828
829
        object_list = (("Signalement d'une anomalie", _("Signalement d'une anomalie")), \
        ("Modification des infos projet (nom, résumé, date d'extraction)", _("Modification des infos projet (nom, résumé, date d'extraction)")), \
        ("Ajout, modification ou suppression de motifs d'exclusion", _("Ajout, modification ou suppression de motifs d'exclusion")),\
         ("Ajout, modification ou suppression de correspondants d'une bibliothèque", _("Ajout, modification ou suppression de correspondants d'une bibliothèque")), \
         ("Ajout, modification ou suppression d'administrateurs", _("Ajout, modification ou suppression d'administrateurs")), \
         ("Ajout, modification ou suppression d'utilisateurs", _("Ajout, modification ou suppression d'utilisateurs")), \
Georges Gressot's avatar
on ...    
Georges Gressot committed
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
         ("Info d'un des administrateurs du projet à ses co-administrateurs", _("Info d'un des administrateurs du projet à ses co-administrateurs")), \
         ("Autre", _("Autre")))
        object = forms.ChoiceField(required = True, widget=forms.Select, choices=object_list, label =_("Objet"))
        email = forms.EmailField(required = True, label =_("Votre adresse mail de contact"))
        email_confirm =forms.EmailField(required = True, label =_("Confirmation de l'adresse mail"))
        content = forms.CharField(required=True, widget=forms.Textarea, label =_("Votre message"))

    form = ContactForm(request.POST or None)
    if form.is_valid():
        recipient = form.cleaned_data['email']
        recipient_confirm = form.cleaned_data['email_confirm']
        subject2 = form.cleaned_data['object']
        body = form.cleaned_data['content']
        if recipient ==recipient_confirm:
            subject2 = "[eplouribousse]" + " - " + subject2
            subject1 = subject2 + " - " + version + " - " + host
            message1 = subject1 + " :\n" + "\n" + body
            message2 = _("Votre message a bien été envoyé à l'administrateur du projet qui y répondra prochainement")\
             + ".\n" + _("Ne répondez pas au présent mail s'il vous plaît") + ".\n" \
             + _("Rappel de votre message") + " :\n" + \
             _("***** Début *****") + "\n" + _("Objet") +  " : " + subject2 + \
             "\n" + _("Corps") + " : " + "\n" + body + "\n" + _("*****  Fin  *****")
            dest2 = [recipient]
            send_mail(subject1, message1, recipient, dest1, fail_silently=True, )
            send_mail(subject2, message2, replymail, dest2, fail_silently=True, )
            return render(request, 'epl/confirmation.html', locals())
        else:
            info =_("Attention : Les adresses doivent être identiques") + "."
    else:
        if request.method =="POST":
            info =_("Vérifier que les adresses sont correctes") + "."

    return render(request, 'epl/projmaster.html', locals())


Georges Gressot's avatar
Georges Gressot committed
865
def confirm(request):
866

Georges Gressot's avatar
Georges Gressot committed
867
    k =logstatus(request)
868
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
869

870
871
872
    return render(request, 'epl/confirmation.html', locals())


Georges Gressot's avatar
Georges Gressot committed
873
def router(request, bdd, lid):
874

Georges Gressot's avatar
Georges Gressot committed
875
876
    if not Feature.objects.using(bdd).filter(libname =Library.objects.using(bdd).get(lid =lid).name).exclude(feaname = "ranking").exclude(feaname ="arbitration").exclude(feaname ="instrtodo").exclude(feaname ="edition"):
        return home(request, bdd)
877
    else:
Georges Gressot's avatar
Georges Gressot committed
878
        newestfeature =Feature.objects.using(bdd).filter(libname =Library.objects.using(bdd).get(lid =lid).name).exclude(feaname = "ranking").exclude(feaname ="arbitration").exclude(feaname ="instrtodo").exclude(feaname ="edition")[0]
879
        key =newestfeature.feaname.split('$')
880
        if key[0] =="10":
Georges Gressot's avatar
Georges Gressot committed
881
            return ranktotake(request, bdd, lid, 'title')
882
        elif key[0] =="11":
Georges Gressot's avatar
Georges Gressot committed
883
            return xranktotake(request, bdd, lid, key[1], 'title')
884
        elif key[0] =="12":
Georges Gressot's avatar
Georges Gressot committed
885
            return modifranklist(request, bdd, lid, 'title')
886
        elif key[0] =="20":
Georges Gressot's avatar
Georges Gressot committed
887
            return arbitration(request, bdd, lid, 'title')
888
        elif key[0] =="21":
Georges Gressot's avatar
Georges Gressot committed
889
            return xarbitration(request, bdd, lid, key[1], 'title')
890
        elif key[0] =="22":
Georges Gressot's avatar
Georges Gressot committed
891
            return x1arb(request, bdd, lid, key[1], 'title')
892
        elif key[0] =="23":
Georges Gressot's avatar
Georges Gressot committed
893
            return x0arb(request, bdd, lid, key[1], 'title')
894
        elif key[0] =="24":
Georges Gressot's avatar
Georges Gressot committed
895
            return arbrk1(request, bdd, lid, 'title')
896
        elif key[0] =="25":
Georges Gressot's avatar
Georges Gressot committed
897
            return arbnork1(request, bdd, lid, 'title')
898
        elif key[0] =="30":
Georges Gressot's avatar
Georges Gressot committed
899
            return instrtodo(request, bdd, lid, 'title')
900
        elif key[0] =="31":
Georges Gressot's avatar
Georges Gressot committed
901
            return xinstrlist(request, bdd, lid, key[1], 'title')
902
        elif key[0] =="32":
Georges Gressot's avatar
Georges Gressot committed
903
            return xckbd(request, bdd, eval(key[1]))
904
        elif key[0] =="33":
Georges Gressot's avatar
Georges Gressot committed
905
            return xcknbd(request, bdd, eval(key[1]))
906
        elif key[0] =="34":
Georges Gressot's avatar
Georges Gressot committed
907
            return xckall(request, bdd, eval(key[1]))
Georges Gressot's avatar
Georges Gressot committed
908
        elif key[0] =="35":
Georges Gressot's avatar
Georges Gressot committed
909
            return instroneb(request, bdd, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
910
        elif key[0] =="36":
Georges Gressot's avatar
Georges Gressot committed
911
            return instrotherb(request, bdd, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
912
        elif key[0] =="37":
Georges Gressot's avatar
Georges Gressot committed
913
            return instronenotb(request, bdd, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
914
        elif key[0] =="38":
Georges Gressot's avatar
Georges Gressot committed
915
            return instrothernotb(request, bdd, lid, 'title')
916
        elif key[0] =="40":
Georges Gressot's avatar
Georges Gressot committed
917
            return tobeedited(request, bdd, lid, 'title')
918
        elif key[0] =="41":
Georges Gressot's avatar
Georges Gressot committed
919
            return mothered(request, bdd, lid, 'title')
920
        elif key[0] =="42":
Georges Gressot's avatar
Georges Gressot committed
921
            return notmothered(request, bdd, lid, 'title')
922
        elif key[0] =="43":
Georges Gressot's avatar
Georges Gressot committed
923
            return xmothered(request, bdd, lid, key[1], 'title')
924
        elif key[0] =="44":
Georges Gressot's avatar
Georges Gressot committed
925
            return xnotmothered(request, bdd, lid, key[1], 'title')
926

Georges Gressot's avatar
Georges Gressot committed
927
    return render(request, 'epl/router.html', locals())
928

929

Georges Gressot's avatar
Georges Gressot committed
930
def lang(request):
Georges Gressot's avatar
Georges Gressot committed
931
    k =logstatus(request)
932
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
933

Georges Gressot's avatar
Georges Gressot committed
934
    return render(request, 'epl/language.html', locals())
935
936


937
def logout_view(request):
938

Georges Gressot's avatar
Georges Gressot committed
939
    "Homepage special disconnected"
940

Georges Gressot's avatar
Georges Gressot committed
941
    logout(request)
942

943
944
    # Redirect to a success page.

Georges Gressot's avatar
Georges Gressot committed
945
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
946

947
    return render(request, 'epl/disconnect.html', locals())
948
949


Georges Gressot's avatar
Georges Gressot committed
950
def notintime(request, bdd, sid, lid):
951

Georges Gressot's avatar
Georges Gressot committed
952
    k =logstatus(request)
953
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
954

Georges Gressot's avatar
Georges Gressot committed
955
    library = Library.objects.using(bdd).get(lid = lid).name
Georges Gressot's avatar
Georges Gressot committed
956
957
    if lid =="999999999":
        try:
Georges Gressot's avatar
Georges Gressot committed
958
            title = ItemRecord.objects.using(bdd).get(sid =sid, rank =1).title
Georges Gressot's avatar
Georges Gressot committed
959
        except:
960
            title = sid
Georges Gressot's avatar
Georges Gressot committed
961
    else:
Georges Gressot's avatar
Georges Gressot committed
962
        title = ItemRecord.objects.using(bdd).get(sid =sid, lid =lid).title
963
    return render(request, 'epl/notintime.html', locals())
964

965

Georges Gressot's avatar
Georges Gressot committed
966
def indicators(request, bdd):
967

Georges Gressot's avatar
Georges Gressot committed
968
    k =logstatus(request)
Georges Gressot's avatar
Georges Gressot committed
969
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
970

Georges Gressot's avatar
Georges Gressot committed
971
    #Indicators :
972

Georges Gressot's avatar
Georges Gressot committed
973
    #Number of rankings (exclusions included) :
Georges Gressot's avatar
Georges Gressot committed
974
    rkall = len(ItemRecord.objects.using(bdd).exclude(rank =99))
975

Georges Gressot's avatar
Georges Gressot committed
976
    #Number of rankings (exclusions excluded) :
Georges Gressot's avatar
Georges Gressot committed
977
    rkright = len(ItemRecord.objects.using(bdd).exclude(rank =99).exclude(rank =0))
978

979
    #Number of exclusions (collections) :
Georges Gressot's avatar
Georges Gressot committed
980
    exclus = len(ItemRecord.objects.using(bdd).filter(rank =0))
981

Georges Gressot's avatar
Georges Gressot committed
982
    #number of libraries :
Georges Gressot's avatar
Georges Gressot committed
983
    nlib = len(Library.objects.using(bdd).all())
984

Georges Gressot's avatar
Georges Gressot committed
985
986
    #Exclusions details
    dict ={}
Georges Gressot's avatar
Georges Gressot committed
987
988
989
990
    EXCLUSION_CHOICES = ('', ''),
    for e in Exclusion.objects.using(bdd).all().order_by('label'):
        EXCLUSION_CHOICES += (e.label, e.label),
    EXCLUSION_CHOICES += ("Autre (Commenter)", _("Autre (Commenter)")),
Georges Gressot's avatar
Georges Gressot committed
991
992
    for e in EXCLUSION_CHOICES:
        exclusion =str(e[0])
Georges Gressot's avatar
Georges Gressot committed
993
        value =len(ItemRecord.objects.using(bdd).filter(excl =e[0]))
Georges Gressot's avatar
Georges Gressot committed
994
995
        dict[exclusion] =value
    del dict['']
996

Georges Gressot's avatar
Georges Gressot committed
997
    #Collections involved in arbitration for claiming 1st rank and number of serials concerned
998
    c1st, s1st =0,[]
Georges Gressot's avatar
Georges Gressot committed
999
1000
    for i in ItemRecord.objects.using(bdd).filter(rank =1, status =0):