views.py 181 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

Georges Gressot's avatar
Georges Gressot committed
45
46
47
48
49
50
51
52
53
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)
54
55


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

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

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

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

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

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

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

Georges Gressot's avatar
Georges Gressot committed
82
83
84
85
86
87
    #abstract :
    librnbr =0
    itemrecnbr =0
    instrnbr =0
    usernbr =len(User.objects.all())
    projnbr =len(BDD_CHOICES) -1
Georges Gressot's avatar
Georges Gressot committed
88
    totcand =0
Georges Gressot's avatar
Georges Gressot committed
89
90
91
92
    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
93
94
95
96
97
98
        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
99
    librnbr =librnbr - projnbr #checkers are not libraries ! (one checker per project)
Georges Gressot's avatar
Georges Gressot committed
100

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


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

111

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

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

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

Georges Gressot's avatar
Georges Gressot committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    #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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    #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
158
159
160

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

Georges Gressot's avatar
...    
Georges Gressot committed
161
    LIBRARY_CHOICES = ('', 'Choisissez votre bibliothèque'),('checker','checker'),
Georges Gressot's avatar
Georges Gressot committed
162
163
164
165
    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
166
167
168
169
170
171
172
173
174
175
176
    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
177

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

Georges Gressot's avatar
...    
Georges Gressot committed
180
181
182
183
184
185
186
187
188
    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
189
            else:
Georges Gressot's avatar
...    
Georges Gressot committed
190
191
192
193
194
195
196
197
198
199
                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
200

Georges Gressot's avatar
Georges Gressot committed
201
    #abstract :
Georges Gressot's avatar
Georges Gressot committed
202
    usernbr =len(Utilisateur.objects.using(bdd).all())
203
204
205
    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
206
207
208
209
    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)
210
    totcand =len(cand)
Georges Gressot's avatar
Georges Gressot committed
211

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

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

    #contrôle d'accès ici
Georges Gressot's avatar
rollon    
Georges Gressot committed
218
219
220
    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
221
222
223

    k =logstatus(request)
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
224
    url ="/" + bdd + "/adminbase"
Georges Gressot's avatar
Georges Gressot committed
225
    suffixe = "@" + str(bdd)
Georges Gressot's avatar
Georges Gressot committed
226
227
228
229
230
231
232

    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
233
234
    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
235
236

    #Stuff about project
Georges Gressot's avatar
Georges Gressot committed
237
    class ProjNameForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
238
        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
239
240
241
242
243
244
245
246
247
248
249
250
    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
251
252
        messages.info(request, _("Le nom du projet a été modifié avec succès"))
        # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
253
254
255
256
257

    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
258
259
        messages.info(request, _("Le résumé du projet a été modifié avec succès"))
        # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
260
261
262
263
264

    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
265
266
        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
267

Georges Gressot's avatar
Georges Gressot committed
268
    #Stuff about exclusions
Georges Gressot's avatar
Georges Gressot committed
269
270
271
    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
272
273
274
275
276
    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
277

Georges Gressot's avatar
Georges Gressot committed
278
    if exclform.is_valid():
Georges Gressot's avatar
Georges Gressot committed
279
280
281
        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
282
            # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
283
284
285
286
287
        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
288
            # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    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
308

Georges Gressot's avatar
Georges Gressot committed
309
310

    #Stuff about libraries
Georges Gressot's avatar
Georges Gressot committed
311
    LIBRARY_CHOICES = ('', _('Sélectionnez la bibliothèque')), ('checker', 'checker'),
Georges Gressot's avatar
Georges Gressot committed
312
313
314
315
    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
316
317
    CONTACT_CHOICE =('', _('Contact')), ('1', '1'), ('2', '2'), ('3', '3'),

Georges Gressot's avatar
Georges Gressot committed
318
    class LibrMCurNameForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
319
320
        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
321
    class LibrMNewNameForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
322
        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
323
    class LibrMCtcForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
324
325
        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
326
327
328
        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
329
330
        {'placeholder': "Oriane@" + bdd, 'title': _("Suffixe obligatoire") + \
        ' : ' + '@' + bdd + '. ' + \
Georges Gressot's avatar
Georges Gressot committed
331
        _("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
332
333
        max_length=30, label =_("identifiant 1"))
        suppr = forms.BooleanField(required=False)
Georges Gressot's avatar
Georges Gressot committed
334

Georges Gressot's avatar
Georges Gressot committed
335
    liblist =Library.objects.using(bdd).exclude(name ='checker')
Georges Gressot's avatar
Georges Gressot committed
336
    sizelib =len(liblist)
Georges Gressot's avatar
Georges Gressot committed
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
    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
357

Georges Gressot's avatar
Georges Gressot committed
358
359
    formlibname = LibrMCurNameForm(request.POST or None)
    formnewlibname = LibrMNewNameForm(request.POST or None)
Georges Gressot's avatar
rollong    
Georges Gressot committed
360
361
    formlibct = LibrMCtcForm(request.POST or None)

Georges Gressot's avatar
Georges Gressot committed
362
363
364
    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
365
366
                messages.info(request, _("'checker' est un nom réservé"))
                # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
367
            else:
Georges Gressot's avatar
Georges Gressot committed
368
369
370
371
372
373
374
375
376
377
378
379
380
                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
381
382
                    messages.info(request, _("Nom de la bibliothèque modifié avec succès"))
                    # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
383
                except:
Georges Gressot's avatar
Georges Gressot committed
384
385
                    pass
                    # messages.info(request, _("Pas de bibliothèque au nom que vous avez indiqué"))
Georges Gressot's avatar
Georges Gressot committed
386
                    # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
387

Georges Gressot's avatar
rollong    
Georges Gressot committed
388
    BDD_CHOICES =('', ''),
Georges Gressot's avatar
Georges Gressot committed
389
    for i in [n for n in range(100)]:
Georges Gressot's avatar
rollong    
Georges Gressot committed
390
391
392
393
        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
394

Georges Gressot's avatar
rollong    
Georges Gressot committed
395
    if formlibct.is_valid():
Georges Gressot's avatar
Georges Gressot committed
396
397
398
399
400
401
        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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
                        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
424
425
                    compteurb =0
                    if formlibct.cleaned_data['contactnbr'] =='3':
Georges Gressot's avatar
Georges Gressot committed
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
                        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
448
                    if formlibct.cleaned_data['contactnbr'] =='1':
Georges Gressot's avatar
Georges Gressot committed
449
450
                        messages.info(request, _('Le contact principal ne peut pas être supprimé'))
                        # return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
451
                else:#formlibct.cleaned_data['suppr'] ==False
Georges Gressot's avatar
Georges Gressot committed
452
453
454
455
456
                    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
457
458
                        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
459
                            if formlibct.cleaned_data['contactnbr'] =='1':
Georges Gressot's avatar
Georges Gressot committed
460
461
462
463
464
465
466
467
468
469
                                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
470
471
472
473
474
475
476
                        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
477
                                    messages.info(request, _("Echec : L'identifiant doit se terminer en {}".format(suffixe)))
Georges Gressot's avatar
Georges Gressot committed
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
                                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
495
        except:
Georges Gressot's avatar
Georges Gressot committed
496
            pass
Georges Gressot's avatar
Georges Gressot committed
497

Georges Gressot's avatar
Georges Gressot committed
498
499
    #Stuff about bddadministrators
    admintuple =('', "Sélectionnez l'administrateur"),
Georges Gressot's avatar
Georges Gressot committed
500
    for b in BddAdmin.objects.using(bdd).all():
Georges Gressot's avatar
roll on    
Georges Gressot committed
501
        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
502
    admintup =admintuple[1:]
Georges Gressot's avatar
on    
Georges Gressot committed
503
504
    sizeadm =len(BddAdmin.objects.using(bdd).all())

Georges Gressot's avatar
Georges Gressot committed
505
    class ProjadmAjForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
506
507
        contactajadm = forms.EmailField(required =True, label ='current email')
        identajadm = forms.CharField(required =True, widget=forms.TextInput(attrs=\
Georges Gressot's avatar
Georges Gressot committed
508
        {'placeholder': "Rosemonde@" + bdd, 'title': _("Suffixe obligatoire") + \
Georges Gressot's avatar
on    
Georges Gressot committed
509
510
511
        ' : ' + '@' + 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
512

Georges Gressot's avatar
Georges Gressot committed
513
514
515
    projajadmform =ProjadmAjForm(request.POST or None)

    class ProjadmSupprForm(forms.Form):
Georges Gressot's avatar
Georges Gressot committed
516
517
        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
518
519
520

    projsuppradmform =ProjadmSupprForm(request.POST or None)

Georges Gressot's avatar
roll on    
Georges Gressot committed
521
    if projajadmform.is_valid():
Georges Gressot's avatar
Georges Gressot committed
522
        try:
Georges Gressot's avatar
roll on    
Georges Gressot committed
523
524
            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
525
        except:
Georges Gressot's avatar
roll on    
Georges Gressot committed
526
527
528
529
530
531
            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
532
                try:
Georges Gressot's avatar
roll on    
Georges Gressot committed
533
534
                    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
535
                except:
Georges Gressot's avatar
roll on    
Georges Gressot committed
536
537
                    try:
                        uter =Utilisateur.objects.using(bdd).get(mail =projajadmform.cleaned_data['contactajadm'])
Georges Gressot's avatar
rollon    
Georges Gressot committed
538
                        messages.info(request, _("Echec : L'email saisi est déjà utilisé"))
Georges Gressot's avatar
roll on    
Georges Gressot committed
539
540
541
542
543
544
545
546
547
548
549
550
551
                    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
552
553
554
555
556

    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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
            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
574
            suppradm.delete(using =bdd)
Georges Gressot's avatar
Georges Gressot committed
575
576
            messages.info(request, _('Administrateur supprimé avec succès'))

Georges Gressot's avatar
roll on    
Georges Gressot committed
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
    #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
593

Georges Gressot's avatar
roll on    
Georges Gressot committed
594
595
596
597
598
599
    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
600
                messages.info(request, _("Echec : L'email saisi est déjà utilisé"))
Georges Gressot's avatar
roll on    
Georges Gressot committed
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
            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
616
                                user.save()
Georges Gressot's avatar
roll on    
Georges Gressot committed
617
618
619
620
                                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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
                        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
642
643
644
645



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

Georges Gressot's avatar
Georges Gressot committed
647
648
649
650
651
    # 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
652
653
654
655
656
    # 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
657
658
659
    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
660
661
662
663
664
            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
665
        #2/2 (see upper, this order is important)
Georges Gressot's avatar
Georges Gressot committed
666
667
668
669
670
671
672
        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
673

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

Georges Gressot's avatar
Georges Gressot committed
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
@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
694

Georges Gressot's avatar
Georges Gressot committed
695
def about(request):
696

Georges Gressot's avatar
Georges Gressot committed
697
    k =logstatus(request)
698
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
699
    date =date_version
700
    host = str(request.get_host())
Georges Gressot's avatar
Georges Gressot committed
701
    return render(request, 'epl/about.html', locals())
702
703


Georges Gressot's avatar
Georges Gressot committed
704
def contact(request):
705

Georges Gressot's avatar
Georges Gressot committed
706
    k =logstatus(request)
707
708
709
710
711
    version =epl_version
    date =date_version
    host = str(request.get_host())

    class ContactForm(forms.Form):
712
713
        object_list = (("Demande d'information", _("Demande d'information")), ("Bug", _("Bug")),\
         ("Réclamation", _("Réclamation")), ("Suggestion", _("Suggestion")), ("Avis", _("Avis")),  ("Autre", _("Autre")))
714
715
716
717
718
719
720
721
722
        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']
723
        subject2 = form.cleaned_data['object']
724
725
        body = form.cleaned_data['content']
        if recipient ==recipient_confirm:
Georges Gressot's avatar
Georges Gressot committed
726
727
728
            subject2 = "[eplouribousse]" + " - " + subject2
            subject1 = subject2 + " - " + version + " - " + host
            message1 = subject1 + " :\n" + "\n" + body
Georges Gressot's avatar
Georges Gressot committed
729
730
            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" + \
731
             "Rappel de l'objet de votre message" + " : " + subject2 + \
Georges Gressot's avatar
Georges Gressot committed
732
733
734
             "\n" + _("Rappel de votre message") + " :\n" + \
              _("***** Début *****") + "\n" + _("Objet") +  " : " + subject2 + \
              "\n" + _("Corps") + " : " + "\n" + body + "\n" + _("*****  Fin  *****")
735
736
            dest1 = ["eplouribousse@gmail.com"]
            dest2 = [recipient]
737
738
            send_mail(subject1, message1, recipient, dest1, fail_silently=True, )
            send_mail(subject2, message2, replymail, dest2, fail_silently=True, )
739
740
            return render(request, 'epl/confirmation.html', locals())
        else:
741
742
743
744
            info =_("Attention : Les adresses doivent être identiques") + "."
    else:
        if request.method =="POST":
            info =_("Vérifier que les adresses sont correctes") + "."
745
746
747
748

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


749
750


Georges Gressot's avatar
Georges Gressot committed
751
def webmstr(request):
752

Georges Gressot's avatar
Georges Gressot committed
753
    k =logstatus(request)
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
    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
776
777
778
779
780
781
            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]
782
783
784
785
786
787
788
789
790
791
792
793
794
            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
795
796
797
798
799
800
801
802
803
804
805
806
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
807
808
809
810
811
812
        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
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
         ("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
848
def confirm(request):
849

Georges Gressot's avatar
Georges Gressot committed
850
    k =logstatus(request)
851
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
852

853
854
855
    return render(request, 'epl/confirmation.html', locals())


Georges Gressot's avatar
Georges Gressot committed
856
def router(request, bdd, lid):
857

Georges Gressot's avatar
Georges Gressot committed
858
859
    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)
860
    else:
Georges Gressot's avatar
Georges Gressot committed
861
        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]
862
        key =newestfeature.feaname.split('$')
863
        if key[0] =="10":
Georges Gressot's avatar
Georges Gressot committed
864
            return ranktotake(request, bdd, lid, 'title')
865
        elif key[0] =="11":
Georges Gressot's avatar
Georges Gressot committed
866
            return xranktotake(request, bdd, lid, key[1], 'title')
867
        elif key[0] =="12":
Georges Gressot's avatar
Georges Gressot committed
868
            return modifranklist(request, bdd, lid, 'title')
869
        elif key[0] =="20":
Georges Gressot's avatar
Georges Gressot committed
870
            return arbitration(request, bdd, lid, 'title')
871
        elif key[0] =="21":
Georges Gressot's avatar
Georges Gressot committed
872
            return xarbitration(request, bdd, lid, key[1], 'title')
873
        elif key[0] =="22":
Georges Gressot's avatar
Georges Gressot committed
874
            return x1arb(request, bdd, lid, key[1], 'title')
875
        elif key[0] =="23":
Georges Gressot's avatar
Georges Gressot committed
876
            return x0arb(request, bdd, lid, key[1], 'title')
877
        elif key[0] =="24":
Georges Gressot's avatar
Georges Gressot committed
878
            return arbrk1(request, bdd, lid, 'title')
879
        elif key[0] =="25":
Georges Gressot's avatar
Georges Gressot committed
880
            return arbnork1(request, bdd, lid, 'title')
881
        elif key[0] =="30":
Georges Gressot's avatar
Georges Gressot committed
882
            return instrtodo(request, bdd, lid, 'title')
883
        elif key[0] =="31":
Georges Gressot's avatar
Georges Gressot committed
884
            return xinstrlist(request, bdd, lid, key[1], 'title')
885
        elif key[0] =="32":
Georges Gressot's avatar
Georges Gressot committed
886
            return xckbd(request, bdd, eval(key[1]))
887
        elif key[0] =="33":
Georges Gressot's avatar
Georges Gressot committed
888
            return xcknbd(request, bdd, eval(key[1]))
889
        elif key[0] =="34":
Georges Gressot's avatar
Georges Gressot committed
890
            return xckall(request, bdd, eval(key[1]))
Georges Gressot's avatar
Georges Gressot committed
891
        elif key[0] =="35":
Georges Gressot's avatar
Georges Gressot committed
892
            return instroneb(request, bdd, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
893
        elif key[0] =="36":
Georges Gressot's avatar
Georges Gressot committed
894
            return instrotherb(request, bdd, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
895
        elif key[0] =="37":
Georges Gressot's avatar
Georges Gressot committed
896
            return instronenotb(request, bdd, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
897
        elif key[0] =="38":
Georges Gressot's avatar
Georges Gressot committed
898
            return instrothernotb(request, bdd, lid, 'title')
899
        elif key[0] =="40":
Georges Gressot's avatar
Georges Gressot committed
900
            return tobeedited(request, bdd, lid, 'title')
901
        elif key[0] =="41":
Georges Gressot's avatar
Georges Gressot committed
902
            return mothered(request, bdd, lid, 'title')
903
        elif key[0] =="42":
Georges Gressot's avatar
Georges Gressot committed
904
            return notmothered(request, bdd, lid, 'title')
905
        elif key[0] =="43":
Georges Gressot's avatar
Georges Gressot committed
906
            return xmothered(request, bdd, lid, key[1], 'title')
907
        elif key[0] =="44":
Georges Gressot's avatar
Georges Gressot committed
908
            return xnotmothered(request, bdd, lid, key[1], 'title')
909

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

912

Georges Gressot's avatar
Georges Gressot committed
913
def lang(request):
Georges Gressot's avatar
Georges Gressot committed
914
    k =logstatus(request)
915
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
916

Georges Gressot's avatar
Georges Gressot committed
917
    return render(request, 'epl/language.html', locals())
918
919


920
def logout_view(request):
921

Georges Gressot's avatar
Georges Gressot committed
922
    "Homepage special disconnected"
923

Georges Gressot's avatar
Georges Gressot committed
924
    logout(request)
925

926
927
    # Redirect to a success page.

Georges Gressot's avatar
Georges Gressot committed
928
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
929

930
    return render(request, 'epl/disconnect.html', locals())
931
932


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

Georges Gressot's avatar
Georges Gressot committed
935
    k =logstatus(request)
936
    version =epl_version
Georges Gressot's avatar
Georges Gressot committed
937

Georges Gressot's avatar
Georges Gressot committed
938
    library = Library.objects.using(bdd).get(lid = lid).name
Georges Gressot's avatar
Georges Gressot committed
939
940
    if lid =="999999999":
        try:
Georges Gressot's avatar
Georges Gressot committed
941
            title = ItemRecord.objects.using(bdd).get(sid =sid, rank =1).title
Georges Gressot's avatar
Georges Gressot committed
942
        except:
943
            title = sid
Georges Gressot's avatar
Georges Gressot committed
944
    else:
Georges Gressot's avatar
Georges Gressot committed
945
        title = ItemRecord.objects.using(bdd).get(sid =sid, lid =lid).title
946
    return render(request, 'epl/notintime.html', locals())
947

948

Georges Gressot's avatar
Georges Gressot committed
949
def indicators(request, bdd):
950

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

Georges Gressot's avatar
Georges Gressot committed
954
    #Indicators :
955

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

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

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

Georges Gressot's avatar
Georges Gressot committed
965
    #number of libraries :
Georges Gressot's avatar
Georges Gressot committed
966
    nlib = len(Library.objects.using(bdd).all())
967

Georges Gressot's avatar
Georges Gressot committed
968
969
    #Exclusions details
    dict ={}
Georges Gressot's avatar
Georges Gressot committed
970
971
972
973
    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
974
975
    for e in EXCLUSION_CHOICES:
        exclusion =str(e[0])
Georges Gressot's avatar
Georges Gressot committed
976
        value =len(ItemRecord.objects.using(bdd).filter(excl =e[0]))
Georges Gressot's avatar
Georges Gressot committed
977
978
        dict[exclusion] =value
    del dict['']
979

Georges Gressot's avatar
Georges Gressot committed
980
    #Collections involved in arbitration for claiming 1st rank and number of serials concerned
981
    c1st, s1st =0,[]
Georges Gressot's avatar
Georges Gressot committed
982
983
    for i in ItemRecord.objects.using(bdd).filter(rank =1, status =0):
        if len(ItemRecord.objects.using(bdd).filter(rank =1, sid =i.sid)) >1:
Georges Gressot's avatar
Georges Gressot committed
984
            c1st +=1
985
986
987
            if i.sid not in s1st:
                s1st.append(i.sid)
    s1st = len(s1st)
988

Georges Gressot's avatar
Georges Gressot committed
989
    #Collections involved in arbitration for 1st rank not claimed by any of the libraries
990
    cnone, snone =0,[]