1
0

api.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from django.shortcuts import render
  2. from django.template import loader
  3. from django.urls import reverse
  4. from django.utils import timezone
  5. from django.http import HttpResponse, HttpResponseRedirect
  6. from django.contrib import messages
  7. from django.db.models import Q
  8. from django.contrib.auth import authenticate, login, logout
  9. from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
  10. from django.contrib.auth.models import User
  11. from core.views import gen_page_base, gen_page_sys, get_get_value
  12. from .forms import *
  13. from .models import *
  14. def text_to_icon(text):
  15. icon = "Error"
  16. if text == "0":
  17. icon = "<i class=\"far fa-star\"></i><i class=\"far fa-star\"></i>"
  18. elif text == "1":
  19. icon = "<i class=\"fas fa-star\"></i><i class=\"far fa-star\"></i>"
  20. elif text == "2":
  21. icon = "<i class=\"fas fa-star\"></i><i class=\"fas fa-star-half-alt\"></i>"
  22. elif text == "3":
  23. icon = "<i class=\"fas fa-star\"></i><i class=\"fas fa-star\"></i>"
  24. elif text == "NOUVELLE":
  25. icon = "<i class=\"far fa-calendar-plus\"></i>"
  26. elif text == "PROGRAMEE":
  27. icon = "<i class=\"far fa-calendar-alt\"></i>"
  28. elif text == "ENCOUR":
  29. icon = "<i class=\"far fa-calendar\"></i>"
  30. elif text == "FINI":
  31. icon = "<i class=\"fas fa-calendar-check\"></i>"
  32. return icon
  33. def taches_get_list(request):
  34. template = loader.get_template('parc_info_api_taches_get_list.html')
  35. data_query = Taches.objects.exclude(Tache_Statut = 'FINI').order_by('-Tache_Priorite','-Tache_Date_Cree')
  36. for item in data_query:
  37. item.Tache_Priorite = text_to_icon(item.Tache_Priorite)
  38. item.Tache_Statut = text_to_icon(item.Tache_Statut)
  39. html = template.render({
  40. 'data_query': data_query,
  41. }, request)
  42. return HttpResponse(html)
  43. def taches_get_info(request, id_tache):
  44. template = loader.get_template('parc_info_api_taches_get.html')
  45. item = Taches.objects.get(id = id_tache)
  46. item.Tache_Priorite = text_to_icon(item.Tache_Priorite)
  47. item.Tache_Statut = text_to_icon(item.Tache_Statut)
  48. html = template.render({
  49. 'item': item,
  50. }, request)
  51. return HttpResponse(html)
  52. def taches_edit_info(request, id_tache):
  53. template = loader.get_template('parc_info_api_taches_edit.html')
  54. if id_tache == None or id_tache == '0':
  55. item = Taches()
  56. item.Tache_Date_Programee = timezone.now()
  57. item.id = 0
  58. else :
  59. item = Taches.objects.get(id = id_tache)
  60. form = Edit_Tache_form(instance=item)
  61. html = template.render({
  62. 'form': form,
  63. 'item': item,
  64. }, request)
  65. return HttpResponse(html)