drought_backup/users/views.py

51 lines
1.3 KiB
Python

import requests
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
from django.urls import reverse_lazy
from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView
from users.form import UserForm
def server_status(request):
return render(request, 'user/status.html')
def server_status_proxy(request):
r = requests.get('http://127.0.0.1/server-status')
return HttpResponse(r.text)
class UserListView(ListView):
model = User
context_object_name = 'user'
template_name = 'user/user_list.html'
class UserDetailView(DetailView):
model = User
context_object_name = 'user'
template_name = 'user/user_detail.html'
class UserCreateView(CreateView):
form_class = UserForm
template_name = 'user/user_create.html'
success_url = reverse_lazy('user-create')
class UserUpdateView(UpdateView):
model = User
form_class = UserForm
template_name = 'user/user_update.html'
def UserDetailView(request,pk):
user = User.objects.filter(pk=pk)
return render(request,'user/user_detail.html',{'user':user})
class UserDeleteView(DeleteView):
model = User
template_name = 'user/user_delete.html'
success_url = reverse_lazy('user-list')