4
4
from .models import QuantityOfRegisteredlibraries
5
5
from .models import PercentLibrariesTypeSphere
6
6
from django .shortcuts import render
7
+ from quero_cultura .views import sort_dict
7
8
import datetime
8
9
from celery .decorators import task
9
10
13
14
def index (request ):
14
15
15
16
last_register_percent_private_library = PercentPublicOrPrivateLibrary .objects .count ()
16
- percent_public_private = PercentPublicOrPrivateLibrary .objects [last_register_percent_private_library - 1 ]
17
+ percent_public_private = PercentPublicOrPrivateLibrary .objects [
18
+ last_register_percent_private_library - 1 ]
17
19
18
20
last_register_quantity_libraries = QuantityOfRegisteredlibraries .objects .count ()
19
- quantity_libraries = QuantityOfRegisteredlibraries .objects [last_register_quantity_libraries - 1 ]
21
+ quantity_libraries = QuantityOfRegisteredlibraries .objects [
22
+ last_register_quantity_libraries - 1 ]
20
23
21
24
last_register_type_sphere_quantity = PercentLibrariesTypeSphere .objects .count ()
22
- type_sphere_total = PercentLibrariesTypeSphere .objects [last_register_type_sphere_quantity - 1 ]
25
+ type_sphere_total = PercentLibrariesTypeSphere .objects [
26
+ last_register_type_sphere_quantity - 1 ]
23
27
24
28
last_register_ocupation_area_quantity = PercentLibraryPerAreaOfActivity .objects .count ()
25
- ocupation_area_total = PercentLibraryPerAreaOfActivity .objects [last_register_ocupation_area_quantity - 1 ]
29
+ ocupation_area_total = PercentLibraryPerAreaOfActivity .objects [
30
+ last_register_ocupation_area_quantity - 1 ]
26
31
27
32
context = {
28
33
'total_libraries' : percent_public_private ._total_libraries ,
29
34
'amount_public_libraries' : percent_public_private ._total_public_libraries ,
30
35
'amount_private_libraries' : percent_public_private ._total_private_libraries ,
31
36
'quantity_per_mouth' : quantity_libraries ._libraries_registered_monthly ,
32
37
'quantity_per_year' : quantity_libraries ._libraries_registered_yearly ,
33
- 'type_sphere_total' : type_sphere_total ._total_libraries_type_sphere ,
34
- 'ocupation_area_total' : ocupation_area_total ._libraries_per_activity ,
38
+ 'type_sphere_total' : sort_dict ( type_sphere_total ._total_libraries_type_sphere ) ,
39
+ 'ocupation_area_total' : sort_dict ( ocupation_area_total ._libraries_per_activity ) ,
35
40
'amount_of_ocupation_area' : ocupation_area_total ._amount_areas ,
36
41
}
37
42
@@ -54,8 +59,8 @@ def update_library_public_private_indicator():
54
59
public_libraries = 0
55
60
private_libraries = 0
56
61
total_libraries = 0
57
- undefined_library , public_libraries , private_libraries , total_libraries = set_libraries_amount (undefined_library ,
58
- public_libraries , private_libraries , total_libraries )
62
+ undefined_library , public_libraries , private_libraries , total_libraries = set_libraries_amount (undefined_library ,
63
+ public_libraries , private_libraries , total_libraries )
59
64
PercentPublicOrPrivateLibrary (total_libraries ,
60
65
datetime .datetime .now (),
61
66
public_libraries , private_libraries ).save ()
@@ -71,7 +76,8 @@ def set_libraries_amount(undefined_library, public_libraries, private_libraries,
71
76
72
77
def update_quantity_libraries ():
73
78
if (len (QuantityOfRegisteredlibraries .objects ) == 0 ):
74
- QuantityOfRegisteredlibraries (0 , DEFAULT_INITIAL_DATE , {'julho' :10 }, {'2010' :2 }).save ()
79
+ QuantityOfRegisteredlibraries (0 , DEFAULT_INITIAL_DATE , {
80
+ 'julho' : 10 }, {'2010' : 2 }).save ()
75
81
else :
76
82
undefined_library = 0
77
83
public_libraries = 0
@@ -90,22 +96,26 @@ def update_quantity_libraries():
90
96
91
97
def update_type_sphere_indicator ():
92
98
if (len (PercentLibrariesTypeSphere .objects ) == 0 ):
93
- PercentLibrariesTypeSphere (0 , DEFAULT_INITIAL_DATE ,{'Municipal' : 1 }).save ()
99
+ PercentLibrariesTypeSphere (0 , DEFAULT_INITIAL_DATE , {
100
+ 'Municipal' : 1 }).save ()
94
101
else :
95
- total_libraries = get_public_libraries () + get_private_libraries () + get_undefined_library ()
102
+ total_libraries = get_public_libraries () + get_private_libraries () + \
103
+ get_undefined_library ()
96
104
type_sphere_total = get_all_type_sphere ()
97
105
PercentLibrariesTypeSphere (total_libraries ,
98
- datetime .datetime .now (),
99
- type_sphere_total ).save ()
106
+ datetime .datetime .now (),
107
+ type_sphere_total ).save ()
100
108
101
109
102
110
def update_ocupation_area_indicator ():
103
111
if (len (PercentLibraryPerAreaOfActivity .objects ) == 0 ):
104
- PercentLibraryPerAreaOfActivity (0 , DEFAULT_INITIAL_DATE ,{'Leitura' : 1 },0 ).save ()
112
+ PercentLibraryPerAreaOfActivity (
113
+ 0 , DEFAULT_INITIAL_DATE , {'Leitura' : 1 }, 0 ).save ()
105
114
else :
106
115
ocupation_area_total = get_all_occupation_area ()
107
116
amount_ocupation_area = len (ocupation_area_total )
108
- total_libraries = get_public_libraries () + get_private_libraries () + get_undefined_library ()
117
+ total_libraries = get_public_libraries () + get_private_libraries () + \
118
+ get_undefined_library ()
109
119
PercentLibraryPerAreaOfActivity (total_libraries ,
110
120
datetime .datetime .now (),
111
121
ocupation_area_total ,
@@ -138,7 +148,7 @@ def get_private_libraries():
138
148
def get_undefined_library ():
139
149
count = 0
140
150
for librarie in get_all_libraries ():
141
- if ( librarie ["esfera" ] == None ):
151
+ if (librarie ["esfera" ] == None ):
142
152
count = count + 1
143
153
return count
144
154
@@ -208,7 +218,7 @@ def get_all_type_sphere():
208
218
209
219
210
220
def filter_sphere_type (per_type , library ):
211
- if (library ["esfera_tipo" ] != None ):
221
+ if (library ["esfera_tipo" ] != None or library [ "esfera_tipo" ] != "" ):
212
222
if not (library ["esfera_tipo" ] in per_type ):
213
223
per_type [library ["esfera_tipo" ]] = 1
214
224
else :
0 commit comments