@@ -46,36 +46,35 @@ def _fetch_content_type_counts(self):
4646 empty _ct_inventory.
4747 """
4848
49- if "counts" not in self ._cache :
50- if (
51- self .item ._ct_inventory
52- and self .item ._ct_inventory .get ("_version_" , - 1 ) == INVENTORY_VERSION
53- ):
54-
55- try :
56- self ._cache ["counts" ] = self ._from_inventory (
57- self .item ._ct_inventory
58- )
59- except KeyError :
60- # It's possible that the inventory does not fit together
61- # with the current models anymore, f.e. because a content
62- # type has been removed.
63- pass
64-
65- if "counts" not in self ._cache :
66- super (TrackerContentProxy , self )._fetch_content_type_counts ()
67-
68- self .item ._ct_inventory = self ._to_inventory (self ._cache ["counts" ])
69-
70- self .item .__class__ .objects .filter (id = self .item .id ).update (
71- _ct_inventory = self .item ._ct_inventory
49+ if "counts" not in self ._cache and (
50+ self .item ._ct_inventory
51+ and self .item ._ct_inventory .get ("_version_" , - 1 ) == INVENTORY_VERSION
52+ ):
53+
54+ try :
55+ self ._cache ["counts" ] = self ._from_inventory (
56+ self .item ._ct_inventory
7257 )
58+ except KeyError :
59+ # It's possible that the inventory does not fit together
60+ # with the current models anymore, f.e. because a content
61+ # type has been removed.
62+ pass
63+
64+ if "counts" not in self ._cache :
65+ super (TrackerContentProxy , self )._fetch_content_type_counts ()
66+
67+ self .item ._ct_inventory = self ._to_inventory (self ._cache ["counts" ])
68+
69+ self .item .__class__ .objects .filter (id = self .item .id ).update (
70+ _ct_inventory = self .item ._ct_inventory
71+ )
7372
74- # Run post save handler by hand
75- if hasattr (self .item , "get_descendants" ):
76- self .item .get_descendants (include_self = False ).update (
77- _ct_inventory = None
78- )
73+ # Run post save handler by hand
74+ if hasattr (self .item , "get_descendants" ):
75+ self .item .get_descendants (include_self = False ).update (
76+ _ct_inventory = None
77+ )
7978 return self ._cache ["counts" ]
8079
8180 def _translation_map (self ):
@@ -104,19 +103,20 @@ def _from_inventory(self, inventory):
104103
105104 map = self ._translation_map ()
106105
107- return dict (
108- ( region , [(pk , map [- ct ]) for pk , ct in items ])
106+ return {
107+ region : [(pk , map [- ct ]) for pk , ct in items ]
109108 for region , items in inventory .items ()
110109 if region != "_version_"
111- )
110+ }
112111
113112 def _to_inventory (self , counts ):
114113 map = self ._translation_map ()
115114
116- inventory = dict (
117- ( region , [(pk , map [ct ]) for pk , ct in items ])
115+ inventory = {
116+ region : [(pk , map [ct ]) for pk , ct in items ]
118117 for region , items in counts .items ()
119- )
118+ }
119+
120120 inventory ["_version_" ] = INVENTORY_VERSION
121121 return inventory
122122
0 commit comments