views.py 127 KB
Newer Older
1
2
epl_version ="v1.20.0 (Wulfégonde)"
date_version ="March 23, 2021"
Georges Gressot's avatar
Georges Gressot committed
3
# Mise au niveau de :
4
5
# epl_version ="v1.21-beta.2 (~Berchilde)"
# date_version ="April 16, 2021"
6

Georges Gressot's avatar
Georges Gressot committed
7
8
9
10
11
12
13
14
15
16
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

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

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

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

23
24
from django.contrib.auth import logout

25
26
from django.http import HttpResponseRedirect

27
lastrked =None
28
29
30
31
32
33
wbmstr =""
try:
    wbmstr = ReplyMail.objects.all().order_by('pk')[1].sendermail
    zz =1
except:
    pass
34

Georges Gressot's avatar
Georges Gressot committed
35
36
37
38
39
40
41
42
43
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)
44

45
46
47
48
try:
    replymail =ReplyMail.objects.all().order_by('pk')[0].sendermail
except:
    replymail =BddAdmin.objects.all().order_by('pk')[0].contact
49

Georges Gressot's avatar
Georges Gressot committed
50

Georges Gressot's avatar
Georges Gressot committed
51
52
53
54
55
56
def logstatus(request):
    if request.user.is_authenticated:
        k = request.user.get_username()
    else:
        k =0
    return k
57

58

Georges Gressot's avatar
Georges Gressot committed
59
def home(request):
Georges Gressot's avatar
Georges Gressot committed
60

61
    k = logstatus(request)
62
    version =epl_version
63
    webmaster =wbmstr
64

Georges Gressot's avatar
Georges Gressot committed
65
    "Homepage"
Georges Gressot's avatar
Georges Gressot committed
66

Georges Gressot's avatar
Georges Gressot committed
67
    project = Project.objects.all().order_by('pk')[0].name
68

Georges Gressot's avatar
Georges Gressot committed
69
70
    #Feature input :
    i = Feature()
71
72
    form = FeatureForm(request.POST, instance =i)
    if form.is_valid():
Georges Gressot's avatar
Georges Gressot committed
73
74
        lid = Library.objects.get(name =i.libname).lid
        feature =i.feaname
75
        if not Feature.objects.filter(feaname =feature, libname =i.libname):
76
            i.save()
77

Georges Gressot's avatar
Georges Gressot committed
78
79
        if lid =="999999999":
            if feature =='instrtodo':
Georges Gressot's avatar
Georges Gressot committed
80
                return instrtodo(request, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
81
82
83
84
            else:
                return checkinstr(request)
        else:
            if feature =='ranking':
Georges Gressot's avatar
Georges Gressot committed
85
                return ranktotake(request, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
86
            elif feature =='arbitration':
Georges Gressot's avatar
Georges Gressot committed
87
                return arbitration(request, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
88
            elif feature =='instrtodo':
Georges Gressot's avatar
Georges Gressot committed
89
                return instrtodo(request, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
90
            elif feature =='edition':
Georges Gressot's avatar
Georges Gressot committed
91
                return tobeedited(request, lid, 'title')
92

93
    return render(request, 'epl/home.html', locals())
94
95


Georges Gressot's avatar
Georges Gressot committed
96
def about(request):
97
98

    k = logstatus(request)
99
    version =epl_version
100
    webmaster =wbmstr
Georges Gressot's avatar
Georges Gressot committed
101
    date =date_version
102
    host = str(request.get_host())
Georges Gressot's avatar
Georges Gressot committed
103
    return render(request, 'epl/about.html', locals())
104
105


106
107
108
109
def contact(request):

    k = logstatus(request)
    version =epl_version
110
    webmaster =wbmstr
111
112
113
114
    date =date_version
    host = str(request.get_host())

    class ContactForm(forms.Form):
115
116
        object_list = (("Demande d'information", _("Demande d'information")), ("Bug", _("Bug")),\
         ("Réclamation", _("Réclamation")), ("Suggestion", _("Suggestion")), ("Avis", _("Avis")),  ("Autre", _("Autre")))
117
118
119
120
121
122
123
124
125
        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']
126
        subject2 = form.cleaned_data['object']
127
128
        body = form.cleaned_data['content']
        if recipient ==recipient_confirm:
Georges Gressot's avatar
Georges Gressot committed
129
130
131
            subject2 = "[eplouribousse]" + " - " + subject2
            subject1 = subject2 + " - " + version + " - " + host
            message1 = subject1 + " :\n" + "\n" + body
132
            message2 = "Votre message a bien été envoyé au développeur de l'application"\
133
134
             + ".\n" + "Ne répondez pas au présent message s'il vous plaît" + ".\n" + \
             "Rappel de l'objet de votre message" + " : " + subject2 + \
135
136
             "\n" + "Rappel de votre message" + " :\n" + "\n" + \
             _("***** Début *****") + "\n" + body + "\n" + _("*****  Fin  *****")
137
138
            dest1 = ["eplouribousse@gmail.com"]
            dest2 = [recipient]
139
140
            send_mail(subject1, message1, recipient, dest1, fail_silently=True, )
            send_mail(subject2, message2, replymail, dest2, fail_silently=True, )
141
142
            return render(request, 'epl/confirmation.html', locals())
        else:
143
144
145
146
            info =_("Attention : Les adresses doivent être identiques") + "."
    else:
        if request.method =="POST":
            info =_("Vérifier que les adresses sont correctes") + "."
147
148
149
150

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


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197


def webmstr(request):

    k = logstatus(request)
    version =epl_version
    webmaster =wbmstr
    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
            message2 = "Votre message a bien été envoyé au webmaster"\
             + ".\n" + "Ne répondez pas au présent message s'il vous plaît" + ".\n" + \
             "Rappel de l'objet de votre message" + " : " + subject2 + \
             "\n" + "Rappel de votre message" + " :\n" + "\n" + \
             _("***** Début *****") + "\n" + body + "\n" + _("*****  Fin  *****")
            dest1 = [wbmstr]
            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())


198
199
200
201
def confirm(request):

    k = logstatus(request)
    version =epl_version
202
    webmaster =wbmstr
203
204
205
206

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


207
def router(request, lid):
208

209
    if not Feature.objects.filter(libname =Library.objects.get(lid =lid).name).exclude(feaname = "ranking").exclude(feaname ="arbitration").exclude(feaname ="instrtodo").exclude(feaname ="edition"):
Georges Gressot's avatar
Georges Gressot committed
210
        return home(request)
211
    else:
212
        newestfeature =Feature.objects.filter(libname =Library.objects.get(lid =lid).name).exclude(feaname = "ranking").exclude(feaname ="arbitration").exclude(feaname ="instrtodo").exclude(feaname ="edition")[0]
213
        key =newestfeature.feaname.split('$')
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
        if key[0] =="10":
            return ranktotake(request, lid, 'title')
        elif key[0] =="11":
            return xranktotake(request, lid, key[1], 'title')
        elif key[0] =="12":
            return modifranklist(request, lid, 'title')
        elif key[0] =="20":
            return arbitration(request, lid, 'title')
        elif key[0] =="21":
            return xarbitration(request, lid, key[1], 'title')
        elif key[0] =="22":
            return x1arb(request, lid, key[1], 'title')
        elif key[0] =="23":
            return x0arb(request, lid, key[1], 'title')
        elif key[0] =="24":
            return arbrk1(request, lid, 'title')
        elif key[0] =="25":
            return arbnork1(request, lid, 'title')
        elif key[0] =="30":
            return instrtodo(request, lid, 'title')
        elif key[0] =="31":
            return xinstrlist(request, lid, key[1], 'title')
        elif key[0] =="32":
237
            return xckbd(request, eval(key[1]))
238
        elif key[0] =="33":
239
            return xcknbd(request, eval(key[1]))
240
        elif key[0] =="34":
241
            return xckall(request, eval(key[1]))
Georges Gressot's avatar
Georges Gressot committed
242
243
244
245
246
247
248
249
        elif key[0] =="35":
            return instroneb(request, lid, 'title')
        elif key[0] =="36":
            return instrotherb(request, lid, 'title')
        elif key[0] =="37":
            return instronenotb(request, lid, 'title')
        elif key[0] =="38":
            return instrothernotb(request, lid, 'title')
250
251
252
253
254
255
256
257
258
259
        elif key[0] =="40":
            return tobeedited(request, lid, 'title')
        elif key[0] =="41":
            return mothered(request, lid, 'title')
        elif key[0] =="42":
            return notmothered(request, lid, 'title')
        elif key[0] =="43":
            return xmothered(request, lid, key[1], 'title')
        elif key[0] =="44":
            return xnotmothered(request, lid, key[1], 'title')
260

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

263

Georges Gressot's avatar
Georges Gressot committed
264
def lang(request):
265
    k = logstatus(request)
266
    version =epl_version
267
    webmaster =wbmstr
268

Georges Gressot's avatar
Georges Gressot committed
269
    return render(request, 'epl/language.html', locals())
270
271


Georges Gressot's avatar
Georges Gressot committed
272
def logout_view(request):
273

Georges Gressot's avatar
Georges Gressot committed
274
    "Homepage sepcial disconnected"
275

Georges Gressot's avatar
Georges Gressot committed
276
    logout(request)
277

278
279
    # Redirect to a success page.

Georges Gressot's avatar
Georges Gressot committed
280
    version =epl_version
281
    webmaster =wbmstr
Georges Gressot's avatar
Georges Gressot committed
282
    project = Project.objects.all().order_by('pk')[0].name
283

Georges Gressot's avatar
Georges Gressot committed
284
285
    #Feature input :
    i = Feature()
286
287
    form = FeatureForm(request.POST, instance =i)
    if form.is_valid():
Georges Gressot's avatar
Georges Gressot committed
288
289
290
291
292
293
        lid = Library.objects.get(name =i.libname).lid
        feature =i.feaname
        # if not Feature.objects.filter(feaname = i.feaname, libname =i.libname):
        i.save()
        if lid =="999999999":
            if feature =='instrtodo':
Georges Gressot's avatar
Georges Gressot committed
294
                return instrtodo(request, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
295
296
297
298
            else:
                return checkinstr(request)
        else:
            if feature =='ranking':
Georges Gressot's avatar
Georges Gressot committed
299
                return ranktotake(request, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
300
            elif feature =='arbitration':
Georges Gressot's avatar
Georges Gressot committed
301
                return arbitration(request, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
302
            elif feature =='instrtodo':
Georges Gressot's avatar
Georges Gressot committed
303
                return instrtodo(request, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
304
            elif feature =='edition':
Georges Gressot's avatar
Georges Gressot committed
305
                return tobeedited(request, lid, 'title')
Georges Gressot's avatar
Georges Gressot committed
306

307
    return render(request, 'epl/disconnect.html', locals())
308
309


Georges Gressot's avatar
Georges Gressot committed
310
def notintime(request, sid, lid):
311
312

    k = logstatus(request)
313
    version =epl_version
314
    webmaster =wbmstr
315

316
    library = Library.objects.get(lid = lid).name
Georges Gressot's avatar
Georges Gressot committed
317
318
    if lid =="999999999":
        try:
319
            title = ItemRecord.objects.get(sid =sid, rank =1).title
Georges Gressot's avatar
Georges Gressot committed
320
        except:
321
            title = sid
Georges Gressot's avatar
Georges Gressot committed
322
    else:
323
324
        title = ItemRecord.objects.get(sid =sid, lid =lid).title
    return render(request, 'epl/notintime.html', locals())
325

326

Georges Gressot's avatar
Georges Gressot committed
327
def indicators(request):
328

Georges Gressot's avatar
Georges Gressot committed
329
330
    k = logstatus(request)
    version =epl_version
331
    webmaster =wbmstr
332

Georges Gressot's avatar
Georges Gressot committed
333
    #Indicators :
334

Georges Gressot's avatar
Georges Gressot committed
335
336
    #Number of rankings (exclusions included) :
    rkall = len(ItemRecord.objects.exclude(rank =99))
337

Georges Gressot's avatar
Georges Gressot committed
338
339
    #Number of rankings (exclusions excluded) :
    rkright = len(ItemRecord.objects.exclude(rank =99).exclude(rank =0))
340

341
    #Number of exclusions (collections) :
Georges Gressot's avatar
Georges Gressot committed
342
    exclus = len(ItemRecord.objects.filter(rank =0))
343

Georges Gressot's avatar
Georges Gressot committed
344
345
    #number of libraries :
    nlib = len(Library.objects.all())
346

Georges Gressot's avatar
Georges Gressot committed
347
348
349
350
351
352
353
    #Exclusions details
    dict ={}
    for e in EXCLUSION_CHOICES:
        exclusion =str(e[0])
        value =len(ItemRecord.objects.filter(excl =e[0]))
        dict[exclusion] =value
    del dict['']
354

Georges Gressot's avatar
Georges Gressot committed
355
    #Collections involved in arbitration for claiming 1st rank and number of serials concerned
356
    c1st, s1st =0,[]
Georges Gressot's avatar
Georges Gressot committed
357
358
359
    for i in ItemRecord.objects.filter(rank =1, status =0):
        if len(ItemRecord.objects.filter(rank =1, sid =i.sid)) >1:
            c1st +=1
360
361
362
            if i.sid not in s1st:
                s1st.append(i.sid)
    s1st = len(s1st)
363

Georges Gressot's avatar
Georges Gressot committed
364
    #Collections involved in arbitration for 1st rank not claimed by any of the libraries
365
    cnone, snone =0,[]
Georges Gressot's avatar
Georges Gressot committed
366
367
368
369
370
    for i in ItemRecord.objects.exclude(rank =0).exclude(rank =1).exclude(rank =99):
        if len(ItemRecord.objects.filter(sid =i.sid, rank =99)) ==0 and \
        len(ItemRecord.objects.filter(sid =i.sid, rank =1)) ==0 and \
        len(ItemRecord.objects.filter(sid =i.sid).exclude(rank =0)) >1:
            cnone +=1
371
372
373
            if i.sid not in snone:
                snone.append(i.sid)
    snone = len(snone)
374

Georges Gressot's avatar
Georges Gressot committed
375
376
377
    #Collections involved in arbitration for any of the two reasons and number of serials concerned
    ctotal = c1st + cnone
    stotal = s1st + snone
378

Georges Gressot's avatar
Georges Gressot committed
379
380
    #Number of collections :
    coll = len(ItemRecord.objects.all())
381

Georges Gressot's avatar
Georges Gressot committed
382
    #Number of potential candidates :
383
    cand =[]
Georges Gressot's avatar
Georges Gressot committed
384
    for e in ItemRecord.objects.all():
385
386
387
        if len(ItemRecord.objects.filter(sid =e.sid)) >1 and not e.sid in cand:
            cand.append(e.sid)
    cand = len(cand)
388

Georges Gressot's avatar
Georges Gressot committed
389
    #from which strict duplicates :
390
    dupl =[]
Georges Gressot's avatar
Georges Gressot committed
391
    for e in ItemRecord.objects.all():
392
393
394
        if len(ItemRecord.objects.filter(sid =e.sid)) ==2 and not e.sid in dupl:
            dupl.append(e.sid)
    dupl = len(dupl)
395

Georges Gressot's avatar
Georges Gressot committed
396
    #triplets :
397
    tripl =[]
Georges Gressot's avatar
Georges Gressot committed
398
    for e in ItemRecord.objects.all():
399
400
401
        if len(ItemRecord.objects.filter(sid =e.sid)) ==3 and not e.sid in tripl:
            tripl.append(e.sid)
    tripl = len(tripl)
402

Georges Gressot's avatar
Georges Gressot committed
403
    #quadruplets :
404
    qudrpl =[]
Georges Gressot's avatar
Georges Gressot committed
405
    for e in ItemRecord.objects.all():
406
407
408
        if len(ItemRecord.objects.filter(sid =e.sid)) ==4 and not e.sid in qudrpl:
            qudrpl.append(e.sid)
    qudrpl = len(qudrpl)
409

Georges Gressot's avatar
Georges Gressot committed
410
    #Unicas :
411
    isol =[]
Georges Gressot's avatar
Georges Gressot committed
412
    for e in ItemRecord.objects.all():
413
414
415
        if len(ItemRecord.objects.filter(sid =e.sid)) ==1 and not e.sid in isol:
            isol.append(e.sid)
    isol = len(isol)
416

Georges Gressot's avatar
Georges Gressot committed
417
418
    #candidate collections :
    candcoll =coll - isol
419

Georges Gressot's avatar
Georges Gressot committed
420
    #Number of descarded ressources for exclusion reason :
421
    discard =[]
Georges Gressot's avatar
Georges Gressot committed
422
    for i in ItemRecord.objects.filter(rank =0):
423
424
425
        if len(ItemRecord.objects.filter(sid =i.sid).exclude(rank =0)) ==1 and not i.sid in discard:
            discard.append(i.sid)
    discard = len(discard)
426

427
    #Number of real candidates (collections)
428
    realcandcoll =candcoll - (exclus + discard)
429

Georges Gressot's avatar
Georges Gressot committed
430
431
    #Number of ressources whose instruction of bound elements may begin :
    bdmaybeg = len(ItemRecord.objects.filter(rank =1, status =1))
432

Georges Gressot's avatar
Georges Gressot committed
433
434
    #Number of ressources whose bound elements are currently instructed  :
    bdonway = len(ItemRecord.objects.filter(rank =1, status =2))
435

Georges Gressot's avatar
Georges Gressot committed
436
437
    #Number of ressources whose instruction of not bound elements may begin :
    notbdmaybeg = len(ItemRecord.objects.filter(rank =1, status =3))
438

Georges Gressot's avatar
Georges Gressot committed
439
440
    #Number of ressources whose not bound elements are currently instructed  :
    notbdonway = len(ItemRecord.objects.filter(rank =1, status =4))
Georges Gressot's avatar
Georges Gressot committed
441

Georges Gressot's avatar
Georges Gressot committed
442
443
    #Number of ressources completely instructed :
    fullinstr = len(ItemRecord.objects.filter(rank =1, status =5))
444

Georges Gressot's avatar
Georges Gressot committed
445
446
    #Number of failing sheets :
    fail = len(ItemRecord.objects.filter(status =6, rank =1))
447

Georges Gressot's avatar
Georges Gressot committed
448
449
    #Number of instructions :
    instr = len(Instruction.objects.all())
450

451
452
453
454
455
456
457
458
459
460
461
    #Fiches incomplètement instruites, défectueuses ou dont le traitement peut débuter mais n'a pas débuté
    incomp = bdmaybeg + bdonway + notbdmaybeg + notbdonway + fail

    #Ressources pour lesquelles le positionnement doit être complété (hors arbitrage)
    stocomp =[]
    for i in ItemRecord.objects.filter(rank =99):
        if len(ItemRecord.objects.filter(sid =i.sid).exclude(rank =0)) >1 and not i.sid in stocomp:
            stocomp.append(i.sid)
    stocomp = len(stocomp)

    #Number of real candidates (ressources)
462
    realcand =stocomp + incomp + fullinstr
463

464
465
466
467
468
469
    #Absolute achievement :
    absolute_real = round(10000*(fullinstr + discard)/cand)/100

    #Relative achievement :
    relative_real = round(10000*fullinstr/realcand)/100

Georges Gressot's avatar
Georges Gressot committed
470
    return render(request, 'epl/indicators.html', locals())
471
472


473
def search(request):
474
# Lot of code for this view is similar with the code for "current_status" view : When changing here, think to change there
475
476
477

    k = logstatus(request)
    version =epl_version
478
    webmaster =wbmstr
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498

    libch = ('checker','checker'),
    for l in Library.objects.all().exclude(name ='checker').order_by('name'):
        libch += (l.name, l.name),

    class SearchForm(forms.Form):
        sid = forms.CharField(required = True, label =_("ppn"))
        lib = forms.ChoiceField(required = True, widget=forms.Select, choices=libch, label =_("Votre bibliothèque"))

    l =0
    form = SearchForm(request.POST or None)
    if form.is_valid():
        sid = form.cleaned_data['sid']
        lib = form.cleaned_data['lib']
        lid = Library.objects.get(name =lib).lid
        n = len(ItemRecord.objects.filter(sid =sid))
        ranklist =[] # if n==0
        progress =0
        action, laction =0,0
        alteraction, lalteraction =0,0
499

500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
        if ItemRecord.objects.filter(sid =sid):
            # Bibliographic data :
            title = ItemRecord.objects.filter(sid =sid)[0].title
            issn = ItemRecord.objects.filter(sid =sid)[0].issn
            pubhist = ItemRecord.objects.filter(sid =sid)[0].pubhist
        if ItemRecord.objects.filter(sid =sid, lid =lid):
            l =1
            # ItemRecord data :
            holdstat = ItemRecord.objects.get(sid =sid, lid = lid).holdstat
            missing = ItemRecord.objects.get(sid =sid, lid = lid).missing
            cn = ItemRecord.objects.get(sid =sid, lid = lid).cn

        if n ==1:
            bil =Library.objects.get(lid =ItemRecord.objects.get(sid =sid).lid).name

        elif n >1:
516
517
518
519
520
521
522
523
524
525

            #Calcul de l'avancement:
            higher_status =ItemRecord.objects.filter(sid =sid).order_by("-status")[0].status
            if higher_status ==6:
                if len(Instruction.objects.filter(sid =sid, name ="checker")):
                    progress =_("Anomalie signalée lors de la phase des non reliés")
                else:
                    progress =_("Anomalie signalée lors de la phase des reliés")
            elif higher_status ==5:
                progress =_("Instruction achevée")
526
                if ItemRecord.objects.filter(sid =sid, lid =lid).exclude(rank =0):
527
528
529
530
531
532
533
534
                    action, laction =_("Edition de la fiche de résultante"), "/ed/" + str(sid) + "/" + str(lid)
            elif higher_status ==4:
                if len(ItemRecord.objects.filter(sid =sid, status =4)) ==len(ItemRecord.objects.filter(sid =sid).exclude(rank =0)):
                    progress =_("En attente de validation finale par le contrôleur")
                    if lid =="999999999":
                        action, laction =_("Validation finale"), "/end/" + str(sid) + "/" + str(lid)
                else:
                    if lid !="999999999":
535
536
537
538
539
540
541
                        if ItemRecord.objects.filter(sid =sid, lid =lid, status =3):
                            if Instruction.objects.filter(sid =sid, bound =" ", name =Library.objects.get(lid =lid).name):
                                progress =_("Instruction des non reliés en cours pour votre collection")
                            else:
                                progress =_("Instruction des non reliés à débuter pour votre collection")
                            action, laction =_("Instruction"), "/add/" + str(sid) + "/" + str(lid)
                        else:
542
543
544
545
546
547
548
549
550
551
552
553
554
                            xname =Library.objects.get(lid =ItemRecord.objects.get(sid =sid, status =3).lid).name
                            if Instruction.objects.filter(sid =sid, bound =" ", name =xname):
                                progress =_("Instruction des non reliés en cours pour : ")
                            else:
                                progress =_("Instruction des non reliés en cours ; à débuter pour : ")
                    else:#lid ="999999999"
                        xname =Library.objects.get(lid =ItemRecord.objects.get(sid =sid, status =3).lid).name
                        if Instruction.objects.filter(sid =sid, bound =" ", name =xname):
                            progress =_("Instruction des non reliés en cours pour : ")
                        else:
                            progress =_("Instruction des non reliés en cours ; à débuter pour : ")
            elif higher_status ==3:
                if lid !="999999999":
555
556
557
558
559
560
561
                    if ItemRecord.objects.filter(sid =sid, lid =lid, status =3):
                        if Instruction.objects.filter(sid =sid, bound =" ", name =Library.objects.get(lid =lid).name):
                            progress =_("Instruction des non reliés en cours pour votre collection")
                        else:
                            progress =_("Instruction des non reliés à débuter pour votre collection")
                        action, laction =_("Instruction"), "/add/" + str(sid) + "/" + str(lid)
                    else:
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
                        xname =Library.objects.get(lid =ItemRecord.objects.get(sid =sid, status =3).lid).name
                        if Instruction.objects.filter(sid =sid, bound =" ", name =xname):
                            progress =_("Instruction des non reliés en cours pour : ")
                        else:
                            progress =_("Instruction des non reliés en cours ; à débuter pour : ")
                else:#lid ="999999999"
                    xname =Library.objects.get(lid =ItemRecord.objects.get(sid =sid, status =3).lid).name
                    if Instruction.objects.filter(sid =sid, bound =" ", name =xname):
                        progress =_("Instruction des non reliés en cours pour : ")
                    else:
                        progress =_("Instruction des non reliés en cours ; à débuter pour : ")
            elif higher_status ==2:
                if len(ItemRecord.objects.filter(sid =sid, status =2)) ==len(ItemRecord.objects.filter(sid =sid).exclude(rank =0)):
                    progress =_("En attente de validation intermédiaire par le contrôleur")
                    if lid =="999999999":
                        action, laction =_("Validation intermédiaire"), "/end/" + str(sid) + "/" + str(lid)
                else:
                    if lid !="999999999":
580
581
582
583
584
585
586
                        if ItemRecord.objects.filter(sid =sid, lid =lid, status =1):
                            if Instruction.objects.filter(sid =sid, bound ="x", name =Library.objects.get(lid =lid).name):
                                progress =_("Instruction des reliés en cours pour votre collection")
                            else:
                                progress =_("Instruction des reliés à débuter pour votre collection")
                            action, laction =_("Instruction"), "/add/" + str(sid) + "/" + str(lid)
                        else:
587
                            xname =Library.objects.get(lid =ItemRecord.objects.get(sid =sid, status =1).lid).name
588
                            if Instruction.objects.filter(sid =sid, bound ="x", name =xname):
589
590
591
592
593
                                progress =_("Instruction des reliés en cours pour : ")
                            else:
                                progress =_("Instruction des reliés en cours ; à débuter pour : ")
                    else:#lid ="999999999"
                        xname =Library.objects.get(lid =ItemRecord.objects.get(sid =sid, status =1).lid).name
594
                        if Instruction.objects.filter(sid =sid, bound ="x", name =xname):
595
596
597
598
599
                            progress =_("Instruction des reliés en cours pour : ")
                        else:
                            progress =_("Instruction des reliés en cours ; à débuter pour : ")
            elif higher_status ==1:
                if lid !="999999999":
600
601
602
603
604
605
606
                    if ItemRecord.objects.filter(sid =sid, lid =lid, status =1):
                        if Instruction.objects.filter(sid =sid, bound ="x", name =Library.objects.get(lid =lid).name):
                            progress =_("Instruction des reliés en cours pour votre collection")
                        else:
                            progress =_("Instruction des reliés à débuter pour votre collection")
                        action, laction =_("Instruction"), "/add/" + str(sid) + "/" + str(lid)
                    else:
607
                        xname =Library.objects.get(lid =ItemRecord.objects.get(sid =sid, status =1).lid).name
608
                        if Instruction.objects.filter(sid =sid, bound ="x", name =xname):
609
610
611
612
613
614
615
                            progress =_("Instruction des reliés en cours pour : ")
                        else:
                            progress =_("Instruction des reliés en cours ; à débuter pour : ")
                    if ItemRecord.objects.filter(sid =sid, lid =lid) and len(Instruction.objects.filter(sid =sid)) ==0:
                        alteraction, lalteraction =_("Modification éventuelle du rang de votre collection"), "/rk/" + str(sid) + "/" + str(lid)
                else:#lid ="999999999"
                    xname =Library.objects.get(lid =ItemRecord.objects.get(sid =sid, status =1).lid).name
616
                    if Instruction.objects.filter(sid =sid, bound ="x", name =xname):
617
618
619
                        progress =_("Instruction des reliés en cours pour : ")
                    else:
                        progress =_("Instruction des reliés en cours ; à débuter pour : ")
620
            else: # higher_status ==0
621
                if lid !="999999999":
622
623
624
625
626
                    if len(ItemRecord.objects.filter(sid =sid).exclude(rank =0)) <2:
                        progress =_("La ressource n'est plus candidate au dédoublonnement")
                        if ItemRecord.objects.filter(sid =sid, lid =lid, rank =0):
                             action, laction =_("Repositionnement éventuel de votre collection"), "/rk/" + str(sid) + "/" + str(lid)
                    elif ItemRecord.objects.filter(sid =sid, rank =99) and len(ItemRecord.objects.filter(sid =sid).exclude(rank =0)) >1:
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
                        if ItemRecord.objects.filter(sid =sid, rank =99, lid =lid):
                            progress =_("Positionnement à compléter pour votre collection")
                            action, laction =_("Positionnement de votre collection"), "/rk/" + str(sid) + "/" + str(lid)
                        else:
                            progress =_("Positionnement à compléter pour une ou plusieurs collections")
                            if ItemRecord.objects.filter(sid =sid, lid =lid):
                                alteraction, lalteraction =_("Modification éventuelle du rang de votre collection"), "/rk/" + str(sid) + "/" + str(lid)
                    elif len(ItemRecord.objects.filter(sid =sid, rank =1)) >1:
                        if ItemRecord.objects.filter(sid =sid, rank =1, lid =lid):
                            progress =_("Rang 1 revendiqué pour plusieurs collections dont la vôtre")
                            action, laction =_("Repositionnement éventuel de votre collection"), "/rk/" + str(sid) + "/" + str(lid)
                        else:
                            progress =_("Rang 1 revendiqué pour plusieurs collections mais pas la vôtre")
                            if ItemRecord.objects.filter(sid =sid, lid =lid):
                                alteraction, lalteraction =_("Modification éventuelle du rang de votre collection"), "/rk/" + str(sid) + "/" + str(lid)
642
                    else:# len(ItemRecord.objects.filter(sid =sid, rank =1)) ==0:
643
644
645
646
                        progress =_("Le rang 1 n'a été revendiqué pour aucune collection")
                        if ItemRecord.objects.filter(sid =sid, lid =lid):
                            action, laction =_("Repositionnement éventuel de votre collection"), "/rk/" + str(sid) + "/" + str(lid)
                else: #lid ="999999999"
647
648
649
                    if len(ItemRecord.objects.filter(sid =sid).exclude(rank =0)) <2:
                        progress =_("La ressource n'est plus candidate au dédoublonnement")
                    elif ItemRecord.objects.filter(sid =sid, rank =99) and len(ItemRecord.objects.filter(sid =sid).exclude(rank =0)) >1:
650
651
652
                        progress =_("Positionnement à compléter pour une ou plusieurs collections")
                    elif len(ItemRecord.objects.filter(sid =sid, rank =1)) >1:
                        progress =_("Rang 1 revendiqué pour plusieurs collections")
653
                    else:# len(ItemRecord.objects.filter(sid =sid, rank =1)) ==0:
654
655
                        progress =_("Le rang 1 n'a été revendiqué pour aucune collection")

656
657
            #Getting instructions for the considered ressource :
            instrlist = Instruction.objects.filter(sid = sid).order_by('line')
658
            size =len(instrlist)
659
660
661
662
663
664
665
666
667
668

            try:
                pklastone = Instruction.objects.filter(sid = sid).latest('pk').pk
            except:
                pklastone =0

            #Attachements :
            attchmt =ItemRecord.objects.filter(sid =sid).order_by('-status')
            attlist = [(Library.objects.get(lid =element.lid).name, element) for element in attchmt]

669
670
            rklist = ItemRecord.objects.filter(sid =sid).order_by('rank', 'lid')
            ranklist = [(element, Library.objects.get(lid =element.lid).name) for element in rklist]
671

672
673
    return render(request, 'epl/search.html', locals())

674
@login_required
675
def reinit(request, sid):
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717

    k = logstatus(request)
    version =epl_version
    webmaster =wbmstr
    info =""

    ressource =ItemRecord.objects.get(sid =sid, rank =1)

    umail, uname = request.user.email, request.user.username

    flag =0

    for u in BddAdmin.objects.all():
        if (u.contact, u.name) ==(umail, uname):
            flag =1

    if flag ==1:
        y = Flag()
        form = CheckForm(request.POST or None, instance =y)

        if form.is_valid():
            if y.flag:
                if Instruction.objects.filter(sid =sid, bound =" "):
                    for instr in Instruction.objects.filter(sid =sid).exclude(bound ="x"):
                        instr.delete()
                    for item in ItemRecord.objects.filter(sid =sid):
                        if item.rank ==1:
                            item.status =3
                            item.save()
                        else:
                            item.status =2
                            item.save()
                else:
                    for instr in Instruction.objects.filter(sid =sid):
                        instr.delete()
                    for item in ItemRecord.objects.filter(sid =sid):
                        if item.rank ==1:
                            item.status =1
                            item.save()
                        else:
                            item.status =0
                            item.save()
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734

                #Message data :
                nextlid =ItemRecord.objects.get(sid =sid, rank =1).lid
                nextlib =Library.objects.get(lid =nextlid)
                subject = "eplouribousse : " + str(sid) + " / " + str(nextlid)
                host = str(request.get_host())
                message = _("Votre tour est venu d'instruire la fiche eplouribousse pour le ppn ") + str(sid) + \
                " :\n" + "https://" + host + "/add/" + str(sid) + '/' + str(nextlid) + \
                " :\n" + _("(Ce message fait suite à une correction apportée par l'administrateur de la base de données)")
                dest = [nextlib.contact]
                if nextlib.contact_bis:
                    dest.append(nextlib.contact_bis)
                if nextlib.contact_ter:
                    dest.append(nextlib.contact_ter)
                send_mail(subject, message, replymail, dest, fail_silently=True, )

                return current_status(request, sid, "999999999")
735
736
737
738
739
740
741
742
            else:
                info =_("Vous n'avez pas coché !")

    else:
        return notintime(request, sid, lid)

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

743

744
@login_required
Georges Gressot's avatar
Georges Gressot committed
745
746
def takerank(request, sid, lid):

747
    k = logstatus(request)
748
    version =epl_version
749
    webmaster =wbmstr
750

Georges Gressot's avatar
Georges Gressot committed
751
    #Authentication control :
752
    if not request.user.email in [Library.objects.get(lid =lid).contact, Library.objects.get(lid =lid).contact_bis, Library.objects.get(lid =lid).contact_ter]:
Georges Gressot's avatar
Georges Gressot committed
753
754
        return home(request)

755
    #Control (takerank only if still possible ; status still ==0 for all attached libraries ;
756
    #or status ==1 but no instruction yet ; lid not "999999999")
757
758
759
760
761
762
763

    if len(list(ItemRecord.objects.filter(sid =sid).exclude(status =0).exclude(status =1))):
        return notintime(request, sid, lid)
    elif len(list(ItemRecord.objects.filter(sid =sid, status =1))) and len(list(Instruction.objects.filter(sid = sid))):
        return notintime(request, sid, lid)
    elif lid =="999999999":
        return notintime(request, sid, lid)
764

Georges Gressot's avatar
Georges Gressot committed
765
766
767
768
    # For position form :
    i = ItemRecord.objects.get(sid = sid, lid = lid)
    f = PositionForm(request.POST, instance=i)
    if f.is_valid():
769
770
771
772
773
774
775
776
777
778
779
780
        #last controls before modifications :
        if (len(list(ItemRecord.objects.filter(sid = sid, status =1))) and not len(list(Instruction.objects.filter(sid = sid)))) or\
        len(list(ItemRecord.objects.filter(sid = sid).exclude(status =0))) ==0:
            global lastrked
            lastrked =i
            # if len(ItemRecord.objects.filter(sid =sid).exclude(status =0)) ==0:
            if i.excl !='':
                i.rank =0
            f.save()
            # Other status modification if all libraries have taken rank :
            # Status = 1 : item whose lid identified library must begin bound elements instructions on the sid identified serial (rank =1, no arbitration)
            # ordering by pk for identical ranks upper than 1.
Georges Gressot's avatar
Georges Gressot committed
781
782
783

            if len(ItemRecord.objects.filter(sid =sid, status =1)): #Since it's possible when modifying
                for elmt in ItemRecord.objects.filter(sid =sid).exclude(rank =99):
784
785
786
                    if elmt.status !=0:
                        elmt.status =0
                        elmt.save()
Georges Gressot's avatar
Georges Gressot committed
787
788
789
790
791
792
793

            if len(ItemRecord.objects.filter(sid =sid, rank =99)) ==0 and len(ItemRecord.objects.filter(sid =sid, rank =1)) ==1 \
            and len(ItemRecord.objects.filter(sid =sid).exclude(rank =0)) >1:
                p = ItemRecord.objects.filter(sid =sid).exclude(rank =0).exclude(rank =99).order_by("rank", "pk")[0]
                p.status =1
                p.save()

794
795
796
        else:
            return notintime(request, sid, lid)

797
        return router(request, lid)
Georges Gressot's avatar
Georges Gressot committed
798
799

    # Item records list :
800
801
802
    itlist = ItemRecord.objects.filter(sid =  sid)
    itemlist = [(element, Library.objects.get(lid =element.lid).name) for element in itlist]
    # itemlist = list(itemlist)
Georges Gressot's avatar
Georges Gressot committed
803

804
805
806
807
    # restricted Item records list (without excluded collections) :
    r_itemlist = ItemRecord.objects.filter(sid =  sid).exclude(rank =0)
    r_itemlist = list(r_itemlist)

Georges Gressot's avatar
Georges Gressot committed
808
    # Ressource data :
809
    ress = itemlist[0][0]
Georges Gressot's avatar
Georges Gressot committed
810
811
812
813

    # Library data :
    lib = Library.objects.get(lid = lid)

814
    periscope = "https://periscope.sudoc.fr/?ppnviewed=" + str(sid) + "&orderby=SORT_BY_PCP&collectionStatus=&tree="
815
    for i in r_itemlist[:-1]:
816
        periscope = periscope + i.lid + "%2C"
817
    periscope = periscope + r_itemlist[-1].lid
818

819
    return render(request, 'epl/ranking.html', locals())
Georges Gressot's avatar
Georges Gressot committed
820
821


822
@login_required
Georges Gressot's avatar
Georges Gressot committed
823
824
def addinstr(request, sid, lid):

825
    k = logstatus(request)
826
    version =epl_version
827
    webmaster =wbmstr
828
    length =0
829

830
831
832
833
834
835
    q = "x"
    if len(list((Instruction.objects.filter(sid =sid)).filter(name ='checker'))):
        q =" "
    else:
        q ="x"

Georges Gressot's avatar
Georges Gressot committed
836
    #Authentication control :
837
    if not request.user.email in [Library.objects.get(lid =lid).contact, Library.objects.get(lid =lid).contact_bis, Library.objects.get(lid =lid).contact_ter]:
Georges Gressot's avatar
Georges Gressot committed
838
839
        return home(request)

840
841
    do = notintime(request, sid, lid)

842
    #Control (addinstr only if it's up to the considered lid)
Georges Gressot's avatar
suite    
Georges Gressot committed
843
    try:
844
        if lid !="999999999":
845
            if ItemRecord.objects.get(sid =sid, lid =lid).status not in [1, 3]:
846
847
                return do

848
849
        else: # i.e. lid =="999999999"
            if len(list((Instruction.objects.filter(sid =sid)).filter(name ='checker'))) ==2:
850
                return do
851
852
853
854
855
856
            elif len(list((Instruction.objects.filter(sid =sid)).filter(name ='checker'))) ==1:
                if len(list(ItemRecord.objects.filter(sid =sid).exclude(rank =0))) != len(list(ItemRecord.objects.filter(sid =sid, status =4))):
                    return do
            else: # i.e. len(list((Instruction.objects.filter(sid =sid)).filter(name ='checker'))) ==0
                if len(list(ItemRecord.objects.filter(sid =sid).exclude(rank =0))) != len(list(ItemRecord.objects.filter(sid =sid, status =2))):
                    return do
Georges Gressot's avatar
suite    
Georges Gressot committed
857
858
    except:
        z =1 #This is just to continue
859

860

Georges Gressot's avatar
Georges Gressot committed
861
862
863
864
865
866
867
    #Ressource data :
    itemlist = ItemRecord.objects.filter(sid = sid).exclude(rank =0).order_by("rank", 'pk')
    ress = itemlist[0]

    #Library data :
    lib = Library.objects.get(lid = lid)

Georges Gressot's avatar
Georges Gressot committed
868
    # Library list ordered by 'rank' (except "checker" which must be the last one)
Georges Gressot's avatar
Georges Gressot committed
869
870
871
872
    # to get from the precedent item list above :
    liblist = []
    for e in itemlist:
        liblist.append(Library.objects.get(lid = e.lid))
Georges Gressot's avatar
Georges Gressot committed
873
    liblist.append(Library.objects.get(name = 'checker'))
Georges Gressot's avatar
Georges Gressot committed
874

875
876
877
878
879
880
881
    #Remedied library list :
    remliblist = []
    for e in itemlist:
        remliblist.append(Library.objects.get(lid = e.lid))
    if (Library.objects.get(lid =lid)).name != 'checker':
        remliblist.remove(Library.objects.get(name = lib.name))

Georges Gressot's avatar
Georges Gressot committed
882
883
884
885
    #Info :
    info =""

    #Stage (bound or not bound) :
Georges Gressot's avatar
Georges Gressot committed
886
    if len(list((Instruction.objects.filter(sid =sid)).filter(name ='checker'))) ==0:
887
        bd =_('éléments reliés')
Georges Gressot's avatar
Georges Gressot committed
888
    elif len(list((Instruction.objects.filter(sid =sid)).filter(name ='checker'))) ==1:
889
        bd =_('éléments non reliés')
Georges Gressot's avatar
Georges Gressot committed
890
891
892
893
894
895
896
897
898

    if lid =="999999999":
        do = endinstr(request, sid, lid)
        return do

    else:
        #Instruction form instanciation and validation :
        i = Instruction(sid = sid, name = lib.name)
        f = InstructionForm(request.POST, instance =i)
899
900
901
902
903

        REM_CHOICES =('',''),
        bibliolist =[]
        if Instruction.objects.filter(sid =sid).exclude(name =Library.objects.get(lid =lid).name).exclude(name ='checker'):
            for e in Instruction.objects.filter(sid =sid).exclude(name =Library.objects.get(lid =lid).name).exclude(name ='checker'):
904
                if (e.exc or e.degr) and Library.objects.get(name =e.name).name not in bibliolist:
905
                    bibliolist.append(Library.objects.get(name =e.name).name)
906
            bibliolist.sort()
907
908
909
910
911
912
913
914
915
916
            length =len(bibliolist)
        if length:
            for l in bibliolist:
                REM_CHOICES += (l, l),

        class Instr_Form(forms.Form):
            oname = forms.ChoiceField(required = False, widget=forms.Select(attrs={'title': _("Intitulé de la bibliothèque ayant précédemment déclaré une 'exception' ou un 'améliorable'")}), choices=REM_CHOICES, label =_("Bibliothèque remédiée"),)

        foname = Instr_Form(request.POST or None)

Georges Gressot's avatar
Georges Gressot committed
917
        if f.is_valid():
918
919
            if foname.is_valid():
                i.oname = foname.cleaned_data['oname']
Georges Gressot's avatar
Georges Gressot committed
920
921
922
            i.bound =q
            #A line may only be registered once :
            if not len(Instruction.objects.filter(sid =sid, name =lib.name, bound =i.bound, oname =i.oname, descr =i.descr, exc =i.exc, degr =i.degr)):
923
924
                i.line +=1
                i.time =Now()
Georges Gressot's avatar
Georges Gressot committed
925
                f.save()
926
927
                url ="/add/" + str(sid) + "/" + str(lid)
                return HttpResponseRedirect(url)
Georges Gressot's avatar
Georges Gressot committed
928
            else:
Georges Gressot's avatar
Georges Gressot committed
929
                info = _("Vous ne pouvez pas valider deux fois la même ligne d'instruction.")
Georges Gressot's avatar
Georges Gressot committed
930
931
932
933

        #Renumbering instruction lines :
        try:
            instr = Instruction.objects.filter(sid = sid).order_by('line', '-pk')
934
            j, l =0, 1
Georges Gressot's avatar
Georges Gressot committed
935
            while j <= len(instr):
936
                instr[j].line = l
Georges Gressot's avatar
Georges Gressot committed
937
938
                instr[j].save()
                j +=1
939
                l +=1
Georges Gressot's avatar
Georges Gressot committed
940
941
942
943
944
945
946
947
948
        except:
            pass
        instrlist = Instruction.objects.filter(sid = sid).order_by('line')

        try:
            pklastone = Instruction.objects.filter(sid = sid).latest('pk').pk
        except:
            pklastone =0

949
950
951
    try:
        itrec =ItemRecord.objects.get(sid =sid, lid =lid)
    except:
952
        itrec =""
953

954
    return render(request, 'epl/addinstruction.html', { 'ressource' : ress, \
955
    'library' : lib, 'instructions' : instrlist , 'form' : f, 'foname' : foname, 'librarylist' : \
956
    liblist, 'remedied_lib_list' : remliblist, 'sid' : sid, 'stage' : bd, 'info' : info, \
957
    'lid' : lid, 'expected' : q, 'lastone' : pklastone, 'k' : k, 'version' : version, 'l' : length, 'itrec' : itrec, 'webmaster' : webmaster, })
958

959
960
961
962
963
@login_required
def selinstr(request, sid, lid):

    k = logstatus(request)
    version =epl_version
964
    webmaster =wbmstr
965
966
967
968
969
970
971

    #Authentication control :
    if not request.user.email in [Library.objects.get(lid =lid).contact, Library.objects.get(lid =lid).contact_bis, Library.objects.get(lid =lid).contact_ter]:
        return home(request)

    do = notintime(request, sid, lid)

972
    #Control (selinstr only if it's up to the considered library == same conditions as for addinstr if lid not "999999999")
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
    try:
        if lid !="999999999":
            if ItemRecord.objects.get(sid = sid, lid =lid).status not in [1, 3]:
                return do

        else: # i.e. lid =="999999999"
            return do

    except:
        z =1 #This is just to continue

    #Ressource data :
    itemlist = ItemRecord.objects.filter(sid = sid).exclude(rank =0).order_by("rank", 'pk')
    ress = itemlist[0]

    #Library data :
    lib = Library.objects.get(lid = lid)

    # Library list ordered by 'rank' (except "checker" which must be the last one)
    # to get from the precedent item list above :
    liblist = []
    for e in itemlist:
        liblist.append(Library.objects.get(lid = e.lid))
    liblist.append(Library.objects.get(name = 'checker'))

    #Remedied library list :
    remliblist = []
    for e in itemlist:
For faster browsing, not all history is shown. View entire blame