Skip to content

Commit

Permalink
Fixed django#1724 -- Renamed "patch" to "pull request"
Browse files Browse the repository at this point in the history
This follows Django ticket # 35894
  • Loading branch information
bmispelon committed Nov 11, 2024
1 parent 538d2e6 commit 257fda8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
Binary file modified dashboard/fixtures/dashboard_example_data.json.gz
Binary file not shown.
6 changes: 3 additions & 3 deletions dashboard/fixtures/dashboard_production_metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"model": "dashboard.category",
"pk": 2,
"fields": {
"name": "Patches",
"name": "Pull requests",
"position": 2
}
},
Expand Down Expand Up @@ -51,7 +51,7 @@
"model": "dashboard.tracticketmetric",
"pk": 2,
"fields": {
"name": "Patches needing review",
"name": "PRs needing review",
"slug": "patches",
"category": 2,
"position": 3,
Expand All @@ -67,7 +67,7 @@
"model": "dashboard.tracticketmetric",
"pk": 3,
"fields": {
"name": "Doc. patches needing review",
"name": "Doc. PRs needing review",
"slug": "doc-patches",
"category": 2,
"position": 4,
Expand Down
6 changes: 3 additions & 3 deletions dashboard/fixtures/dashboard_test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"fields": {
"position": 2,
"name": "Patches"
"name": "Pull requests"
},
"model": "dashboard.category",
"pk": 2
Expand Down Expand Up @@ -51,7 +51,7 @@
"fields": {
"category": 2,
"show_on_dashboard": true,
"name": "Patches needing review",
"name": "PRs needing review",
"period": "instant",
"show_sparkline": true,
"query": "status=!closed&needs_better_patch=0&needs_tests=0&needs_docs=0&has_patch=1&stage=Accepted",
Expand All @@ -67,7 +67,7 @@
"fields": {
"category": 2,
"show_on_dashboard": true,
"name": "Doc. patches needing review",
"name": "Doc. PRs needing review",
"period": "instant",
"show_sparkline": true,
"query": "status=!closed&needs_better_patch=0&component=Documentation&needs_tests=0&needs_docs=0&has_patch=1&stage=Accepted",
Expand Down
50 changes: 50 additions & 0 deletions dashboard/migrations/0003_rename_patch_to_pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from django.db import migrations

CATEGORY_RENAMES = {
"Patches": "Pull requests",
}

TRACMETRIC_RENAMES = {
"Patches needing review": "PRs needing review",
"Doc. patches needing review": "Doc. PRs needing review",
}


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 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(CATEGORY_RENAMES).items():
Category.objects.filter(name=old).update(name=new)

for old, new in _reverse(TRACMETRIC_RENAMES).items():
TracTicketMetric.objects.filter(name=old).update(name=new)


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0002_delete_rssfeedmetric_create_githubsearchcountmetric'),
]

operations = [
migrations.RunPython(rename, rename_backwards),
]

0 comments on commit 257fda8

Please sign in to comment.