|
| 1 | +from django.shortcuts import render |
| 2 | +from django.views.generic import TemplateView, UpdateView, DeleteView |
| 3 | +from backend.DAL.DAO.deviceDAO import * |
| 4 | +from backend.views.utils import AdminRequired |
| 5 | +from backend.DAL.models.device import DeviceCredential |
| 6 | +from django.urls import reverse_lazy |
| 7 | + |
| 8 | + |
| 9 | +class CredentialPageView(AdminRequired, TemplateView): |
| 10 | + template_name = 'credential.html' |
| 11 | + |
| 12 | + |
| 13 | + def get_context_data(self, **kwargs): |
| 14 | + context = super().get_context_data(**kwargs) |
| 15 | + context['credentials'] = getAllDeviceCredential() |
| 16 | + context['settings'] = 0 |
| 17 | + context['page'] = "Credentials" |
| 18 | + return context |
| 19 | + |
| 20 | + |
| 21 | +class CreateCredentialView(AdminRequired, TemplateView): |
| 22 | + template_name = "credential.html" |
| 23 | + |
| 24 | + def get_context_data(self, **kwargs): |
| 25 | + context = super().get_context_data(**kwargs) |
| 26 | + context['settings'] = 1 |
| 27 | + context['page'] = "Create Credentials" |
| 28 | + return context |
| 29 | + |
| 30 | + def post(self, request ,*args, **kwargs): |
| 31 | + createCredential( |
| 32 | + title = request.POST.get('title'), |
| 33 | + username = request.POST.get('username'), |
| 34 | + password = request.POST.get('password'), |
| 35 | + ) |
| 36 | + result = "The credentials have been successfully upgraded." |
| 37 | + return render(request, self.template_name, {'result': result, 'sucess': 1}) |
| 38 | + |
| 39 | + |
| 40 | +class UpdateCredentialView(AdminRequired, UpdateView): |
| 41 | + template_name = 'credential.html' |
| 42 | + model = DeviceCredential |
| 43 | + fields = ['title','username','password'] |
| 44 | + success_url = reverse_lazy("credentialList") |
| 45 | + |
| 46 | + def get_context_data(self, **kwargs): |
| 47 | + context = super().get_context_data(**kwargs) |
| 48 | + context['settings'] = 2 |
| 49 | + context['page'] = "Manage Credentials" |
| 50 | + return context |
| 51 | + |
| 52 | + |
| 53 | +class DeleteCredentialView(AdminRequired, DeleteView): |
| 54 | + template_name = 'credential.html' |
| 55 | + model = DeviceCredential |
| 56 | + success_url = reverse_lazy("credentialList") |
| 57 | + |
| 58 | + def get_context_data(self, **kwargs): |
| 59 | + context = super().get_context_data(**kwargs) |
| 60 | + context['settings'] = 3 |
| 61 | + context['page'] = "Delete Credentials" |
| 62 | + return context |
0 commit comments