byro-leinelab/byro_leinelab/management/commands/export_keyholder.py

37 lines
1.2 KiB
Python
Raw Permalink Normal View History

2018-07-08 22:07:59 +02:00
from os import path
2018-01-18 22:46:07 +01:00
from django.conf import settings
from django.core.management import BaseCommand
2018-07-08 22:07:59 +02:00
from django.db.models import Q
2018-01-18 22:46:07 +01:00
from django.template.loader import get_template
from django.utils import timezone
class Command(BaseCommand):
def handle(self, *args, **options):
2024-12-29 04:21:21 +01:00
from byro_leinelab.models import ShackProfile
2018-01-18 22:46:07 +01:00
2024-12-29 04:21:21 +01:00
profiles = LabProfile.objects.filter(
2018-01-18 22:46:07 +01:00
member__memberships__end__isnull=True,
is_keyholder=True,
).order_by('member__number')
for task in ["open", "close"]:
context = {
'task': task,
'profiles': [
{
'name': profile.member.name,
'number': profile.member.number,
'nick': profile.member.profile_profile.nick,
'key': profile.ssh_public_key,
}
for profile in profiles
],
}
content = get_template('shackspace/portal_authorized_keys.txt').render(context)
with open(path.join(settings.BASE_DIR, f'authorized_keys.{task}'), 'w') as f:
f.write(content)