|
9 | 9 |
|
10 | 10 | from django.conf import settings |
11 | 11 | from django.template.loader import render_to_string |
| 12 | +from django.utils import timezone |
12 | 13 |
|
13 | 14 | from ietf.doc.storage_utils import store_file |
| 15 | +from ietf.liaisons.models import LiaisonStatement |
14 | 16 | from ietf.utils import log |
| 17 | +from ietf.utils.test_runner import disable_coverage |
15 | 18 |
|
16 | | -from .models import Group |
17 | | -from .utils import fill_in_charter_info, fill_in_wg_drafts, fill_in_wg_roles |
| 19 | +from .models import Group, GroupHistory |
| 20 | +from .utils import fill_in_charter_info, fill_in_wg_drafts, fill_in_wg_roles, save_group_in_history |
18 | 21 | from .views import extract_last_name, roles |
19 | 22 |
|
20 | 23 |
|
@@ -113,3 +116,117 @@ def generate_wg_summary_files_task(): |
113 | 116 | store_file("indexes", "1wg-summary.txt", f, allow_overwrite=True) |
114 | 117 | with summary_by_acronym_file.open("rb") as f: |
115 | 118 | store_file("indexes", "1wg-summary-by-acronym.txt", f, allow_overwrite=True) |
| 119 | + |
| 120 | +@shared_task |
| 121 | +@disable_coverage() |
| 122 | +def run_once_adjust_liaison_groups(): # pragma: no cover |
| 123 | + log.log("Starting run_once_adjust_liaison_groups") |
| 124 | + if all( |
| 125 | + [ |
| 126 | + Group.objects.filter( |
| 127 | + acronym__in=[ |
| 128 | + "3gpp-tsg-ct", |
| 129 | + "3gpp-tsg-ran-wg1", |
| 130 | + "3gpp-tsg-ran-wg4", |
| 131 | + "3gpp-tsg-sa", |
| 132 | + "3gpp-tsg-sa-wg5", |
| 133 | + "3gpp-tsgct", # duplicates 3gpp-tsg-ct above already |
| 134 | + "3gpp-tsgct-ct1", # will normalize all acronyms to hyphenated form |
| 135 | + "3gpp-tsgct-ct3", # and consistently match the name |
| 136 | + "3gpp-tsgct-ct4", # (particularly use of WG) |
| 137 | + "3gpp-tsgran", |
| 138 | + "3gpp-tsgran-ran2", |
| 139 | + "3gpp-tsgsa", # duplicates 3gpp-tsg-sa above |
| 140 | + "3gpp-tsgsa-sa2", # will normalize |
| 141 | + "3gpp-tsgsa-sa3", |
| 142 | + "3gpp-tsgsa-sa4", |
| 143 | + "3gpp-tsgt-wg2", |
| 144 | + ] |
| 145 | + ).count() |
| 146 | + == 16, |
| 147 | + not Group.objects.filter( |
| 148 | + acronym__in=[ |
| 149 | + "3gpp-tsg-ran-wg3", |
| 150 | + "3gpp-tsg-ct-wg1", |
| 151 | + "3gpp-tsg-ct-wg3", |
| 152 | + "3gpp-tsg-ct-wg4", |
| 153 | + "3gpp-tsg-ran", |
| 154 | + "3gpp-tsg-ran-wg2", |
| 155 | + "3gpp-tsg-sa-wg2", |
| 156 | + "3gpp-tsg-sa-wg3", |
| 157 | + "3gpp-tsg-sa-wg4", |
| 158 | + "3gpp-tsg-t-wg2", |
| 159 | + ] |
| 160 | + ).exists(), |
| 161 | + Group.objects.filter(acronym="o3gpptsgran3").exists(), |
| 162 | + not LiaisonStatement.objects.filter( |
| 163 | + to_groups__acronym__in=["3gpp-tsgct", "3gpp-tsgsa"] |
| 164 | + ).exists(), |
| 165 | + not LiaisonStatement.objects.filter( |
| 166 | + from_groups__acronym="3gpp-tsgct" |
| 167 | + ).exists(), |
| 168 | + LiaisonStatement.objects.filter(from_groups__acronym="3gpp-tsgsa").count() |
| 169 | + == 1, |
| 170 | + LiaisonStatement.objects.get(from_groups__acronym="3gpp-tsgsa").pk == 1448, |
| 171 | + ] |
| 172 | + ): |
| 173 | + for old_acronym, new_acronym, new_name in ( |
| 174 | + ("o3gpptsgran3", "3gpp-tsg-ran-wg3", "3GPP TSG RAN WG3"), |
| 175 | + ("3gpp-tsgct-ct1", "3gpp-tsg-ct-wg1", "3GPP TSG CT WG1"), |
| 176 | + ("3gpp-tsgct-ct3", "3gpp-tsg-ct-wg3", "3GPP TSG CT WG3"), |
| 177 | + ("3gpp-tsgct-ct4", "3gpp-tsg-ct-wg4", "3GPP TSG CT WG4"), |
| 178 | + ("3gpp-tsgran", "3gpp-tsg-ran", "3GPP TSG RAN"), |
| 179 | + ("3gpp-tsgran-ran2", "3gpp-tsg-ran-wg2", "3GPP TSG RAN WG2"), |
| 180 | + ("3gpp-tsgsa-sa2", "3gpp-tsg-sa-wg2", "3GPP TSG SA WG2"), |
| 181 | + ("3gpp-tsgsa-sa3", "3gpp-tsg-sa-wg3", "3GPP TSG SA WG3"), |
| 182 | + ("3gpp-tsgsa-sa4", "3gpp-tsg-sa-wg4", "3GPP TSG SA WG4"), |
| 183 | + ("3gpp-tsgt-wg2", "3gpp-tsg-t-wg2", "3GPP TSG T WG2"), |
| 184 | + ): |
| 185 | + group = Group.objects.get(acronym=old_acronym) |
| 186 | + save_group_in_history(group) |
| 187 | + group.time = timezone.now() |
| 188 | + group.acronym = new_acronym |
| 189 | + group.name = new_name |
| 190 | + if old_acronym.startswith("3gpp-tsgct-"): |
| 191 | + group.parent = Group.objects.get(acronym="3gpp-tsg-ct") |
| 192 | + elif old_acronym.startswith("3gpp-tsgsa-"): |
| 193 | + group.parent = Group.objects.get(acronym="3gpp-tsg-sa") |
| 194 | + group.save() |
| 195 | + group.groupevent_set.create( |
| 196 | + time=group.time, |
| 197 | + by_id=1, # (System) |
| 198 | + type="info_changed", |
| 199 | + desc=f"acronym changed from {old_acronym} to {new_acronym}, name set to {new_name}", |
| 200 | + ) |
| 201 | + |
| 202 | + for acronym, new_name in (("3gpp-tsg-ct", "3GPP TSG CT"),): |
| 203 | + group = Group.objects.get(acronym=acronym) |
| 204 | + save_group_in_history(group) |
| 205 | + group.time = timezone.now() |
| 206 | + group.name = new_name |
| 207 | + group.save() |
| 208 | + group.groupevent_set.create( |
| 209 | + time=group.time, |
| 210 | + by_id=1, # (System) |
| 211 | + type="info_changed", |
| 212 | + desc=f"name set to {new_name}", |
| 213 | + ) |
| 214 | + |
| 215 | + ls = LiaisonStatement.objects.get(pk=1448) |
| 216 | + ls.from_groups.remove(Group.objects.get(acronym="3gpp-tsgsa")) |
| 217 | + ls.from_groups.add(Group.objects.get(acronym="3gpp-tsg-sa")) |
| 218 | + |
| 219 | + # Rewriting history to effectively merge the histories of the duplicate groups |
| 220 | + GroupHistory.objects.filter(parent__acronym="3gpp-tsgsa").update( |
| 221 | + parent=Group.objects.get(acronym="3gpp-tsg-sa") |
| 222 | + ) |
| 223 | + GroupHistory.objects.filter(parent__acronym="3gpp-tsgct").update( |
| 224 | + parent=Group.objects.get(acronym="3gpp-tsg-ct") |
| 225 | + ) |
| 226 | + |
| 227 | + deleted = Group.objects.filter( |
| 228 | + acronym__in=["3gpp-tsgsa", "3gpp-tsgct"] |
| 229 | + ).delete() |
| 230 | + log.log(f"Deleted Groups: {deleted}") |
| 231 | + else: |
| 232 | + log.log("* Refusing to continue as preconditions have changed") |
0 commit comments