1717from onegov .people import AgencyCollection
1818
1919
20- from typing import Literal , NamedTuple , TYPE_CHECKING , Any , Callable
20+ from typing import Literal , NamedTuple , TYPE_CHECKING , Iterator
2121if TYPE_CHECKING :
2222 from collections .abc import Iterable , Sequence
2323 from onegov .form import Form
@@ -77,7 +77,7 @@ def migrate_url(
7777 group_by = group_by or item .__class__ .__name__
7878
7979 def repl (matchobj : re .Match [str ]) -> str :
80- # replaces it with a new URI.
80+ # replaces it with a new URI.
8181 if self .use_domain :
8282 return f'{ matchobj .group (1 )} { new_uri } '
8383 return new_uri
@@ -89,33 +89,54 @@ def repl(matchobj: re.Match[str]) -> str:
8989 pattern = re .compile (re .escape (old_uri ))
9090
9191 def predicate (attr ) -> bool :
92+ nonlocal item
9293 return isinstance (attr , MutableDict )
94+ # todo: can it be an iterable which contains MUtableDict?
95+
96+ # todo: refactor away from getmembers()
9397
9498 # Migrate `meta` and `content`:
9599 if isinstance (item , ContentMixin ):
96- kv = getmembers (item , predicate )
97-
98- if len (kv ) > 2 :
99- breakpoint ()
100+ try :
101+ kv = getmembers (item , predicate )
102+ except NotImplementedError :
103+ print ('notimplementeed' )
104+ cal = "calendar_date_range"
105+ # go with pdb into predicate and check for
106+ try :
107+ kv = getmembers (item , predicate )
108+ breakpoint ()
109+ except Exception :
110+ breakpoint ()
100111
112+ # if len(kv) > 2:
113+ # breakpoint()
101114 kv : list [tuple [str , MutableDict ]]
102115 for el in kv :
103116 if not el :
104117 continue
118+ attribute_name = el [0 ]
119+ if attribute_name not in ContentMixin .__dict__ :
120+ continue
121+ if attribute_name == 'calendar_date_range' :
122+ breakpoint ()
105123
106124 if len (el ) != 2 :
107125 breakpoint ()
108126
109127 if el [0 ] == 'content' or el [0 ] == 'meta' and el [1 ]:
110- meta_or_content = el [1 ]
111-
112- for key , v in meta_or_content :
128+ content = el [1 ]
129+ for key , v in content .items (): # key might be 'lead'
130+ # 'text', 'people' etc.
131+ if not isinstance (v , str ) or not v :
132+ continue
113133 new_val = pattern .sub (repl , v )
114134 if v != new_val :
135+ breakpoint ()
136+ # get number of replacements so the count is
137+ # correct
115138 occurrences = len (pattern .findall (v ))
116139 count += occurrences
117- id_count = count_by_id .setdefault (group_by , defaultdict (int ))
118- id_count [meta_or_content ] += occurrences
119140
120141 try :
121142 item .name [key ] = new_val
0 commit comments