684dcf69349aa60290df42fb79a2c71a5dff1f37
[cas.git] / src / ssh_keys / views.py
1 from django.contrib.auth.mixins import LoginRequiredMixin
2 from django.views.generic import ListView, CreateView, DeleteView
3 from .models import SSHKey
4
5
6 class SSHKeysView(LoginRequiredMixin, ListView):
7     def get_queryset(self):
8         return SSHKey.objects.filter(user=self.request.user)
9
10
11 class AddSSHKeyView(LoginRequiredMixin, CreateView):
12     fields = ['key']
13     model = SSHKey
14     success_url = '/ssh/'
15     template_name = 'ssh_keys/sshkey_add.html'
16
17     def form_valid(self, form):
18         form.instance.user = self.request.user
19         return super().form_valid(form)
20
21     
22 class DeleteSSHKeyView(LoginRequiredMixin, DeleteView):
23     success_url = '/ssh/'
24
25     def get_queryset(self):
26         return SSHKey.objects.filter(user=self.request.user)
27