Adds command to get admin code

This commit is contained in:
Mouse Reeve 2022-02-17 10:59:28 -08:00
parent b4e0749f73
commit ed536e6b41
5 changed files with 26 additions and 1 deletions

View file

@ -0,0 +1,18 @@
""" Get your admin code to allow install """
from django.core.management.base import BaseCommand
from bookwyrm import models
def get_admin_code():
"""get that code"""
return models.SiteSettings.objects.get().admin_code
class Command(BaseCommand):
"""command-line options"""
help = "Gets admin code for configuring BookWyrm"
# pylint: disable=unused-argument
def handle(self, *args, **options):
"""execute init"""
self.stdout.write(get_admin_code())

View file

@ -10,7 +10,9 @@ class Command(BaseCommand):
help = "Generate preview images" help = "Generate preview images"
# pylint: disable=no-self-use
def add_arguments(self, parser): def add_arguments(self, parser):
"""options for how the command is run"""
parser.add_argument( parser.add_argument(
"--all", "--all",
"-a", "-a",
@ -38,6 +40,7 @@ class Command(BaseCommand):
preview_images.generate_site_preview_image_task.delay() preview_images.generate_site_preview_image_task.delay()
self.stdout.write(" OK 🖼") self.stdout.write(" OK 🖼")
# pylint: disable=consider-using-f-string
if options["all"]: if options["all"]:
# Users # Users
users = models.User.objects.filter( users = models.User.objects.filter(

View file

@ -30,7 +30,7 @@
<p class="help" id="desc_admin_key"> <p class="help" id="desc_admin_key">
{% blocktrans trimmed %} {% blocktrans trimmed %}
An admin key was created when you installed BookWyrm. An admin key was created when you installed BookWyrm.
You can get your admin key by running <code>./bw-dev admin-code</code> from the command line on your server. You can get your admin key by running <code>./bw-dev admin_code</code> from the command line on your server.
{% endblocktrans %} {% endblocktrans %}
</p> </p>
</div> </div>

3
bw-dev
View file

@ -197,6 +197,9 @@ case "$CMD" in
--endpoint-url ${AWS_S3_ENDPOINT_URL}\ --endpoint-url ${AWS_S3_ENDPOINT_URL}\
--cors-configuration file:///bw/$config_file" "$@" --cors-configuration file:///bw/$config_file" "$@"
;; ;;
admin_code)
runweb python manage.py admin_code
;;
runweb) runweb)
runweb "$@" runweb "$@"
;; ;;

View file

@ -30,4 +30,5 @@ generate_thumbnails
generate_preview_images generate_preview_images
copy_media_to_s3 copy_media_to_s3
set_cors_to_s3 set_cors_to_s3
admin_code
runweb" -o bashdefault -o default bw-dev runweb" -o bashdefault -o default bw-dev