-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More migration stuff, more endpoints
- Add a system user for `last_modified_by` in migrations. This user is hidden by default in `CncUser.objects.all()` queries. - Clean up migrations a bit - Make the user management class available in migrations - Make map category slugs auto-generate - Pop fields that non-admins shouldn't see over the API - Start standardizing what our `response.data` is going to look like. I want to avoid the UI needing a `is list or is dict` check for api returns - Fix the pagination class to use limits and offsets - Make pagination return standard api format - Fix and test map category endpoint - Add standard map categories in a migration. Copied from https://github.com/CnCNet/cncnet-yr-client-package/blob/develop/package/INI/MPMaps.ini
- Loading branch information
1 parent
07d3a47
commit 2207cab
Showing
18 changed files
with
347 additions
and
95 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
72 changes: 0 additions & 72 deletions
72
kirovy/migrations/0003_cncfileextension_last_modified_by_and_more.py
This file was deleted.
Oops, something went wrong.
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,66 @@ | ||
# Generated by Django 4.2.5 on 2024-02-14 04:50 | ||
|
||
from django.db import migrations | ||
from django.db.backends.postgresql.schema import DatabaseSchemaEditor | ||
from django.db.migrations.state import StateApps | ||
from django.utils.text import slugify | ||
|
||
from kirovy import typing as t | ||
from kirovy.models import MapCategory as _MapCategory, CncUser as _User | ||
|
||
|
||
def _forward(apps: StateApps, schema_editor: DatabaseSchemaEditor): | ||
|
||
# This is necessary in case later migrations make schema changes to this model. | ||
# Importing them normally will use the latest schema state and will crash if those | ||
# migrations are after this one. | ||
MapCategory: t.Type[_MapCategory] = apps.get_model("kirovy", "MapCategory") | ||
CncUser: t.Type[_User] = apps.get_model("kirovy", "CncUser") | ||
|
||
migration_user = CncUser.objects.get_or_create_migration_user() | ||
|
||
yuri_category_names = { | ||
"Battle", | ||
"YR Ladder", | ||
"RA2 Ladder", | ||
"RA2 Pro 2v2", | ||
"Free For All", | ||
"Cooperative", | ||
"Naval War", | ||
"Unholy Alliance", | ||
"Megawealth", | ||
"Meat Grinder", | ||
"Team Alliance", | ||
"Land Rush", | ||
"Mod Maps", | ||
"Standard", | ||
"SFJ", | ||
"Blitz", | ||
"Survival", | ||
} | ||
|
||
for category_name in yuri_category_names: | ||
# Note: Custom overriden .save() doesn't work in migrations, so | ||
# we have to manually make the slug. | ||
category = MapCategory( | ||
name=category_name, | ||
slug=slugify(category_name), | ||
last_modified_by=migration_user, | ||
) | ||
category.save() | ||
|
||
|
||
def _backward(apps: StateApps, schema_editor: DatabaseSchemaEditor): | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("kirovy", "0002_add_games"), | ||
] | ||
|
||
# Elidable=false means that squashmigrations will not delete this. | ||
operations = [ | ||
migrations.RunPython(_forward, reverse_code=_backward, elidable=False), | ||
] |
Oops, something went wrong.