mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-07 18:58:30 +02:00
Add black code formatter
This commit is contained in:
@@ -8,19 +8,19 @@ class Command(BaseCommand):
|
||||
help = "Creates a backup of the linkding database"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('destination', type=str, help='Backup file destination')
|
||||
parser.add_argument("destination", type=str, help="Backup file destination")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
destination = options['destination']
|
||||
destination = options["destination"]
|
||||
|
||||
def progress(status, remaining, total):
|
||||
self.stdout.write(f'Copied {total-remaining} of {total} pages...')
|
||||
self.stdout.write(f"Copied {total-remaining} of {total} pages...")
|
||||
|
||||
source_db = sqlite3.connect(os.path.join('data', 'db.sqlite3'))
|
||||
source_db = sqlite3.connect(os.path.join("data", "db.sqlite3"))
|
||||
backup_db = sqlite3.connect(destination)
|
||||
with backup_db:
|
||||
source_db.backup(backup_db, pages=50, progress=progress)
|
||||
backup_db.close()
|
||||
source_db.close()
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(f'Backup created at {destination}'))
|
||||
self.stdout.write(self.style.SUCCESS(f"Backup created at {destination}"))
|
||||
|
@@ -12,18 +12,20 @@ class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
User = get_user_model()
|
||||
superuser_name = os.getenv('LD_SUPERUSER_NAME', None)
|
||||
superuser_password = os.getenv('LD_SUPERUSER_PASSWORD', None)
|
||||
superuser_name = os.getenv("LD_SUPERUSER_NAME", None)
|
||||
superuser_password = os.getenv("LD_SUPERUSER_PASSWORD", None)
|
||||
|
||||
# Skip if option is undefined
|
||||
if not superuser_name:
|
||||
logger.info('Skip creating initial superuser, LD_SUPERUSER_NAME option is not defined')
|
||||
logger.info(
|
||||
"Skip creating initial superuser, LD_SUPERUSER_NAME option is not defined"
|
||||
)
|
||||
return
|
||||
|
||||
# Skip if user already exists
|
||||
user_exists = User.objects.filter(username=superuser_name).exists()
|
||||
if user_exists:
|
||||
logger.info('Skip creating initial superuser, user already exists')
|
||||
logger.info("Skip creating initial superuser, user already exists")
|
||||
return
|
||||
|
||||
user = User(username=superuser_name, is_superuser=True, is_staff=True)
|
||||
@@ -34,4 +36,4 @@ class Command(BaseCommand):
|
||||
user.set_unusable_password()
|
||||
|
||||
user.save()
|
||||
logger.info('Created initial superuser')
|
||||
logger.info("Created initial superuser")
|
||||
|
@@ -14,11 +14,11 @@ class Command(BaseCommand):
|
||||
if not settings.USE_SQLITE:
|
||||
return
|
||||
|
||||
connection = connections['default']
|
||||
connection = connections["default"]
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("PRAGMA journal_mode")
|
||||
current_mode = cursor.fetchone()[0]
|
||||
logger.info(f'Current journal mode: {current_mode}')
|
||||
if current_mode != 'wal':
|
||||
logger.info(f"Current journal mode: {current_mode}")
|
||||
if current_mode != "wal":
|
||||
cursor.execute("PRAGMA journal_mode=wal;")
|
||||
logger.info('Switched to WAL journal mode')
|
||||
logger.info("Switched to WAL journal mode")
|
||||
|
@@ -6,13 +6,15 @@ class Command(BaseCommand):
|
||||
help = "Creates an admin user non-interactively if it doesn't exist"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--username', help="Admin's username")
|
||||
parser.add_argument('--email', help="Admin's email")
|
||||
parser.add_argument('--password', help="Admin's password")
|
||||
parser.add_argument("--username", help="Admin's username")
|
||||
parser.add_argument("--email", help="Admin's email")
|
||||
parser.add_argument("--password", help="Admin's password")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
User = get_user_model()
|
||||
if not User.objects.filter(username=options['username']).exists():
|
||||
User.objects.create_superuser(username=options['username'],
|
||||
email=options['email'],
|
||||
password=options['password'])
|
||||
if not User.objects.filter(username=options["username"]).exists():
|
||||
User.objects.create_superuser(
|
||||
username=options["username"],
|
||||
email=options["email"],
|
||||
password=options["password"],
|
||||
)
|
||||
|
@@ -5,15 +5,17 @@ from bookmarks.services.importer import import_netscape_html
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Import Netscape HTML bookmark file'
|
||||
help = "Import Netscape HTML bookmark file"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('file', type=str, help='Path to file')
|
||||
parser.add_argument('user', type=str, help='Name of the user for which to import')
|
||||
parser.add_argument("file", type=str, help="Path to file")
|
||||
parser.add_argument(
|
||||
"user", type=str, help="Name of the user for which to import"
|
||||
)
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
filepath = kwargs['file']
|
||||
username = kwargs['user']
|
||||
filepath = kwargs["file"]
|
||||
username = kwargs["user"]
|
||||
with open(filepath) as html_file:
|
||||
html = html_file.read()
|
||||
user = User.objects.get(username=username)
|
||||
|
Reference in New Issue
Block a user