viewinfo.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import vyos
  2. import perms
  3. import vmsg
  4. from django.conf import settings
  5. class prepareClass:
  6. all_instances = []
  7. hostname_default = None
  8. is_superuser = False
  9. request = None
  10. msg = None
  11. debug = False
  12. vycontrol_credits = False
  13. title = ""
  14. def prepare(request, title=None):
  15. p = prepareClass()
  16. p.all_instances = perms.instance_getall_by_group(request)
  17. p.hostname_default = perms.get_hostname_prefered(request)
  18. p.is_superuser = perms.get_is_superuser(request.user)
  19. p.request = request
  20. p.msg = vmsg.msg()
  21. p.debug = settings.DEBUG
  22. p.vycontrol_credits = settings.VYCONTROL_CREDITS
  23. if title != None:
  24. p.title = title
  25. return p
  26. def context(prepare):
  27. contextPrepare = {
  28. 'instances': prepare.all_instances,
  29. 'hostname_default': prepare.hostname_default,
  30. 'is_superuser' : prepare.is_superuser,
  31. 'username': prepare.request.user,
  32. 'msg' : prepare.msg.get_all(),
  33. 'debugactive' : prepare.debug,
  34. 'vycontrol_credits' : prepare.vycontrol_credits,
  35. 'title' : prepare.title,
  36. }
  37. return contextPrepare