views.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from django.shortcuts import render
  2. from django.http import HttpResponse
  3. from django.template import loader
  4. from django.shortcuts import redirect
  5. from django.contrib.auth import authenticate
  6. from django.views.generic.base import TemplateView
  7. from django.conf import settings
  8. from django.contrib.auth.models import User
  9. import vyos
  10. def index(request):
  11. users_admin = User.objects.filter(
  12. is_active=True,
  13. is_superuser=True
  14. )
  15. if users_admin.count() > 0:
  16. if request.user.is_authenticated:
  17. return redirect('interface:interface-list')
  18. else:
  19. return redirect('registration-login')
  20. else:
  21. if 'username' in request.POST and 'password' in request.POST:
  22. user = User.objects.create_superuser(username=request.POST['username'], password=request.POST['password'])
  23. user.save()
  24. return redirect('registration-login')
  25. template = loader.get_template('registration/start.html')
  26. context = {
  27. 'users_admin': users_admin.all()
  28. }
  29. return HttpResponse(template.render(context, request))