Le repo des sources pour le site web des JM2L
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

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