generate_keypair.py
21 lines
| 581 B
| text/x-python
|
PythonLexer
|
r836 | __author__ = 'neko259' | |
from django.core.management import BaseCommand | |||
from django.db import transaction | |||
|
r1015 | from boards.models import KeyPair, Post | |
|
r836 | ||
class Command(BaseCommand): | |||
help = 'Generates the new keypair. The first one will be primary.' | |||
@transaction.atomic | |||
def handle(self, *args, **options): | |||
|
r1015 | first_key = not KeyPair.objects.has_primary() | |
|
r836 | key = KeyPair.objects.generate_key( | |
|
r1015 | primary=first_key) | |
print(key) | |||
if first_key: | |||
for post in Post.objects.filter(global_id=None): | |||
post.set_global_id() |