Le repo des sources pour le site web des JM2L
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

160 行
6.3 KiB

  1. # -*- coding: utf8 -*-
  2. from .models import DBSession, JM2L_Year, Sejour
  3. from datetime import timedelta, datetime
  4. import itertools
  5. from jm2l.const import CurrentYear
  6. def get_current_year():
  7. """ This function is intended to return the year of the next edition """
  8. return CurrentYear
  9. class DummySejour(object):
  10. def __init__(self, event):
  11. self.Me = event['request'].user
  12. self.CurrentEventYear = DBSession.query(JM2L_Year).filter(JM2L_Year.state == 'Ongoing').first()
  13. self.Sejour = None
  14. if self.Me:
  15. self.Sejour = DBSession.query(Sejour) \
  16. .filter(Sejour.user_id == self.Me.uid) \
  17. .filter(Sejour.for_year == self.CurrentEventYear.year_uid) \
  18. .first()
  19. class Sejour_helpers(DummySejour):
  20. def __init__(self, event):
  21. super(Sejour_helpers, self).__init__(event)
  22. if self.Sejour and self.Sejour.arrival_time is None:
  23. self.Sejour = None
  24. def StartEvent(self):
  25. # This function return the start of the event
  26. return self.CurrentYear
  27. def PossibleDate(self, type_date="arrival"):
  28. arrival, departure = False, False
  29. tab_result = list()
  30. if type_date == "arrival":
  31. # Let's say people should arrive until 2 day before
  32. arrival = True
  33. my_day_range = range(2, -1, -1)
  34. elif type_date == "departure":
  35. # Let's say people should go back home until 2 day after
  36. departure = True
  37. my_day_range = range(3)
  38. else:
  39. return tab_result
  40. if self.Sejour:
  41. arr_date = datetime.strftime(self.Sejour.arrival_time, "%d %B %Y")
  42. dep_date = datetime.strftime(self.Sejour.depart_time, "%d %B %Y")
  43. else:
  44. arr_date = datetime.strftime(self.CurrentEventYear.start_time, "%d %B %Y")
  45. dep_date = datetime.strftime(self.CurrentEventYear.end_time, "%d %B %Y")
  46. for one_day in my_day_range:
  47. if arrival:
  48. tmp_day = self.CurrentEventYear.end_time - timedelta(days=one_day)
  49. elif departure:
  50. tmp_day = self.CurrentEventYear.start_time + timedelta(days=one_day)
  51. day_name = datetime.strftime(tmp_day, "%A")
  52. day_num = datetime.strftime(tmp_day, "%d/%m/%y")
  53. day_string = datetime.strftime(tmp_day, "%d %B %Y")
  54. if arrival and arr_date == day_string:
  55. tab_result.append((day_num, day_name, 'selected="selected"'))
  56. elif departure and dep_date == day_string:
  57. tab_result.append((day_num, day_name, 'selected="selected"'))
  58. else:
  59. tab_result.append((day_num, day_name, ""))
  60. return tab_result
  61. def PossibleTime(self, type_date="arrival"):
  62. arr_time, dep_time = "10:00", "19:00"
  63. tab_result = list()
  64. if self.Sejour:
  65. arr_time = datetime.strftime(self.Sejour.arrival_time, "%H:%M")
  66. dep_time = datetime.strftime(self.Sejour.depart_time, "%H:%M")
  67. for hour in range(24):
  68. for minutes in range(0, 60, 10):
  69. str_time = "%.2d:%.2d" % (hour, minutes)
  70. disp_time = "%dh%.2d" % (hour, minutes)
  71. if type_date == "arrival" and str_time == arr_time:
  72. tab_result.append((str_time, disp_time, 'selected="selected"'))
  73. elif type_date == "departure" and str_time == dep_time:
  74. tab_result.append((str_time, disp_time, 'selected="selected"'))
  75. else:
  76. tab_result.append((str_time, disp_time, ""))
  77. return tab_result
  78. def IsCheck(self, InputControl):
  79. list_control_a = ['Arrival', 'Departure']
  80. list_control_b = ['PMR', 'Cov', 'Bras', 'Other']
  81. if InputControl not in map(':'.join, itertools.product(list_control_a, list_control_b)):
  82. return ""
  83. if self.Sejour:
  84. if InputControl.startswith('Arrival'):
  85. ctrl_val = 2 ** list_control_b.index(InputControl[8:])
  86. if self.Sejour.arrival_check & ctrl_val == ctrl_val:
  87. return "checked=\"checked\""
  88. else:
  89. return ""
  90. elif InputControl.startswith('Departure'):
  91. ctrl_val = 2 ** list_control_b.index(InputControl[10:])
  92. if self.Sejour.depart_check & ctrl_val == ctrl_val:
  93. return "checked=\"checked\""
  94. else:
  95. return ""
  96. else:
  97. return ""
  98. else:
  99. return ""
  100. class Orga_helpers(DummySejour):
  101. def __init__(self, event):
  102. super(Orga_helpers, self).__init__(event)
  103. self.Orga_tasks = [
  104. u"Participer au fléchage de l'événement.",
  105. u"Faire les courses.",
  106. u"Participer à l'accueil des visiteurs.",
  107. u"Accompagner, Guider les visiteurs.",
  108. u"Accompagner, Guider les intervenants.",
  109. u"Déplacer le matériel / le mobilier",
  110. u"Monter / Démonter les stands",
  111. u"Participer à la préparation / à vider les poubelles",
  112. u"Participer à la préparation / à vider les salles de conférence",
  113. u"Participer à la prise de son/vidéo des conférenciers.",
  114. u"Participer à poser, à repartir, à enlever les ralonges éléctriques.",
  115. u"Participer à poser, à repartir, à enlever les câbles réseau / le Wifi.",
  116. u"Remplir les frigos, s'assurer qu'ils soient toujours pleins. (Boissons)",
  117. u"Participer à la distribution des repas.",
  118. u"Faire du café et s'assurer de sa disponibilité.",
  119. u"Participer à la publication / au montage des vidéos des conférenciers.",
  120. u"Autres"
  121. ]
  122. def IsChecked(self, nb):
  123. nb = 2 ** nb
  124. if self.Sejour and self.Sejour.orga_part:
  125. if self.Sejour.orga_part & nb == nb:
  126. return "checked=\"checked\""
  127. else:
  128. return ""
  129. else:
  130. return ""
  131. def ChoosedList(self):
  132. """ Return choice validated by user """
  133. list_orga = []
  134. for num in range(0, len(self.Orga_tasks)):
  135. curs = 2 ** num
  136. if self.Sejour.orga_part & curs == curs:
  137. list_orga.append(self.Orga_tasks[num])
  138. return list_orga