-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin projectnumber: Add command to reset projectnumber
- Loading branch information
Showing
5 changed files
with
40 additions
and
0 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
Empty file.
Empty file.
23 changes: 23 additions & 0 deletions
23
plugins/projectnumber/management/commands/resetprojectnumber.py
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,23 @@ | ||
from typing import Any | ||
|
||
from django.core.management.base import BaseCommand, CommandError, CommandParser | ||
|
||
from ...models import ProjectNumber | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Reset the project number counter' | ||
|
||
def add_arguments(self, parser: CommandParser) -> None: | ||
parser.add_argument('value', nargs='?', type=int, default=0, help='New project number counter value') | ||
|
||
def handle(self, *args: Any, value=0, **options: Any) -> str | None: | ||
if value < 0: | ||
raise CommandError('Project number counter must be a non-negative integer') | ||
|
||
counter, _ = ProjectNumber.objects.update_or_create( | ||
pk=1, | ||
defaults={'current_id': value}, | ||
create_defaults={'current_id': value}, | ||
) | ||
print(f'Project number was reset to {counter.current_id}') |
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