-
-
Notifications
You must be signed in to change notification settings - Fork 955
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #1724 -- Renamed "patch" to "pull request"
This follows Django ticket # 35894
- Loading branch information
Showing
4 changed files
with
79 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from django.db import migrations | ||
|
||
CATEGORY_RENAMES = { | ||
# old name: new name | ||
"Patches": "Pull requests", | ||
} | ||
|
||
TRACMETRIC_RENAMES = { | ||
# old name: new name | ||
"Patches needing review": "Tickets with PRs needing review", | ||
"Doc. patches needing review": "Doc. tickets with PRs needing review", | ||
} | ||
|
||
CATEGORY_CHANGES = { | ||
# Metric name: (old category, new category) | ||
"\"Easy\" tickets": ("Patches", "Accepted tickets by type"), | ||
} | ||
|
||
|
||
def _reverse(d): | ||
""" | ||
Reverse the given dict (values become keys and vice-versa). | ||
""" | ||
return {v: k for k, v in d.items()} | ||
|
||
|
||
def rename(apps, schema_editor): | ||
Category = apps.get_model("dashboard", "Category") | ||
TracTicketMetric = apps.get_model("dashboard", "TracTicketMetric") | ||
|
||
for metric, (old, new) in CATEGORY_CHANGES.items(): | ||
new_category = Category.objects.filter(name=new).first() | ||
if not new_category: | ||
continue | ||
metrics = TracTicketMetric.objects.filter(name=metric, category__name=old) | ||
metrics.update(category=new_category) | ||
|
||
for old, new in CATEGORY_RENAMES.items(): | ||
Category.objects.filter(name=old).update(name=new) | ||
|
||
for old, new in TRACMETRIC_RENAMES.items(): | ||
TracTicketMetric.objects.filter(name=old).update(name=new) | ||
|
||
|
||
def rename_backwards(apps, schema_editor): | ||
Category = apps.get_model("dashboard", "Category") | ||
TracTicketMetric = apps.get_model("dashboard", "TracTicketMetric") | ||
|
||
for old, new in _reverse(TRACMETRIC_RENAMES).items(): | ||
TracTicketMetric.objects.filter(name=old).update(name=new) | ||
|
||
for old, new in _reverse(CATEGORY_RENAMES).items(): | ||
Category.objects.filter(name=old).update(name=new) | ||
|
||
for metric, (new, old) in CATEGORY_CHANGES.items(): | ||
new_category = Category.objects.filter(name=new).first() | ||
if not new_category: | ||
continue | ||
metrics = TracTicketMetric.objects.filter(name=metric, category__name=old) | ||
metrics.update(category=new_category) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('dashboard', '0002_delete_rssfeedmetric_create_githubsearchcountmetric'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(rename, rename_backwards), | ||
] |