Le repo des sources pour le site web des JM2L
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

helpers.py 6.1 KiB

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