Revision 43a5b181
Added by Frédéric Péters over 12 years ago
calebasse/dossiers/views.py | ||
---|---|---|
11 | 11 |
from django.views.generic import View |
12 | 12 |
from django.views.generic.edit import DeleteView, FormMixin |
13 | 13 |
from django.contrib import messages |
14 |
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
|
14 | 15 |
|
15 | 16 |
from calebasse import cbv |
16 | 17 |
from calebasse.doc_templates import make_doc_from_template |
... | ... | |
384 | 385 |
def get_context_data(self, **kwargs): |
385 | 386 |
ctx = super(PatientRecordsHomepageView, self).get_context_data(**kwargs) |
386 | 387 |
ctx['search_form'] = forms.SearchForm(data=self.request.GET or None) |
387 |
ctx['patient_records'] = []
|
|
388 |
patient_records = []
|
|
388 | 389 |
ctx['stats'] = {"dossiers": 0, |
389 | 390 |
"En_contact": 0, |
390 | 391 |
"Fin_daccueil": 0, |
... | ... | |
402 | 403 |
else: |
403 | 404 |
state = current_state.status.name |
404 | 405 |
state_class = current_state.status.type.lower() |
405 |
ctx['patient_records'].append(
|
|
406 |
patient_records.append(
|
|
406 | 407 |
{ |
407 | 408 |
'object': patient_record, |
408 | 409 |
'next_rdv': next_rdv, |
... | ... | |
417 | 418 |
ctx['stats'][state] = 0 |
418 | 419 |
ctx['stats'][state] += 1 |
419 | 420 |
|
421 |
page = self.request.GET.get('page') |
|
422 |
paginator = Paginator(patient_records, 3) |
|
423 |
try: |
|
424 |
patient_records = paginator.page(page) |
|
425 |
except PageNotAnInteger: |
|
426 |
patient_records = paginator.page(1) |
|
427 |
except EmptyPage: |
|
428 |
patient_records = paginator.page(paginator.num_pages) |
|
429 |
|
|
430 |
query = self.request.GET.copy() |
|
431 |
if 'page' in query: |
|
432 |
del query['page'] |
|
433 |
ctx['query'] = query.urlencode() |
|
434 |
|
|
435 |
ctx['patient_records'] = patient_records |
|
420 | 436 |
return ctx |
421 | 437 |
|
422 | 438 |
patientrecord_home = PatientRecordsHomepageView.as_view() |
... | ... | |
652 | 668 |
def get_context_data(self, **kwargs): |
653 | 669 |
ctx = super(PatientRecordsQuotationsView, self).get_context_data(**kwargs) |
654 | 670 |
ctx['search_form'] = forms.QuotationsForm(data=self.request.GET or None) |
655 |
ctx['patient_records'] = []
|
|
671 |
patient_records = []
|
|
656 | 672 |
if self.request.GET: |
657 | 673 |
for patient_record in ctx['object_list'].filter(): |
658 | 674 |
next_rdv = get_next_rdv(patient_record) |
... | ... | |
663 | 679 |
else: |
664 | 680 |
state = current_state.status.name |
665 | 681 |
state_class = current_state.status.type.lower() |
666 |
ctx['patient_records'].append(
|
|
682 |
patient_records.append(
|
|
667 | 683 |
{ |
668 | 684 |
'object': patient_record, |
669 | 685 |
'state': state, |
... | ... | |
673 | 689 |
state = state.replace(' ', '_') |
674 | 690 |
state = state.replace("'", '') |
675 | 691 |
|
692 |
page = self.request.GET.get('page') |
|
693 |
paginator = Paginator(patient_records, 50) |
|
694 |
try: |
|
695 |
patient_records = paginator.page(page) |
|
696 |
except PageNotAnInteger: |
|
697 |
patient_records = paginator.page(1) |
|
698 |
except EmptyPage: |
|
699 |
patient_records = paginator.page(paginator.num_pages) |
|
700 |
|
|
701 |
ctx['patient_records'] = patient_records |
|
702 |
|
|
703 |
query = self.request.GET.copy() |
|
704 |
if 'page' in query: |
|
705 |
del query['page'] |
|
706 |
ctx['query'] = query.urlencode() |
|
707 |
|
|
676 | 708 |
return ctx |
677 | 709 |
|
678 | 710 |
patientrecord_quotations = PatientRecordsQuotationsView.as_view() |
Also available in: Unified diff
dossiers: add pagination to listings (#2094)