-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement dumpdata view and admin command
This feature provides ways to serialize the data of an APIS instance to be able to import it in a freshly installed instance later on. The main logic is implemented in the `utils.helper.datadump_serializer` method. It serializes the important models to json - with natural foreign keys. There is both a view ('/apisdumpdata.json') and an admin command ('apisdumpdata') that output the serialized data as HttpResponse or to stdout. Closes: #273
- Loading branch information
Showing
4 changed files
with
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from apis_core.utils.helpers import datadump_serializer | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Dump APIS data" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"args", | ||
metavar="app_labels", | ||
nargs="*", | ||
help=("Optional additional app_labels."), | ||
) | ||
|
||
def handle(self, *app_labels, **options): | ||
print(datadump_serializer(app_labels, "json")) |
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,19 @@ | ||
from django.http import HttpResponse | ||
from django.views import View | ||
from django.contrib.auth.mixins import UserPassesTestMixin | ||
|
||
from apis_core.utils.helpers import datadump_serializer | ||
|
||
|
||
class Dumpdata(UserPassesTestMixin, View): | ||
def test_func(self): | ||
return self.request.user.is_staff | ||
|
||
def get(self, request, *args, **kwargs): | ||
app_labels = request.GET.get("app_labels", []) | ||
data = datadump_serializer(app_labels, "json") | ||
|
||
headers = { | ||
"Content-Type": "application/json", | ||
} | ||
return HttpResponse(headers=headers, content=data) |
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