Le repo des sources pour le site web des JM2L
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

715 lines
28 KiB

  1. # -*- coding: utf8 -*-
  2. import datetime
  3. import sqlalchemy as sa
  4. import hashlib
  5. from pyramid.security import unauthenticated_userid
  6. from sqlalchemy.orm import relationship, backref
  7. from sqlalchemy import func
  8. from sqlalchemy import or_
  9. from sqlalchemy import (
  10. Column,
  11. Integer,
  12. Unicode,
  13. UnicodeText,
  14. DateTime,
  15. Enum,
  16. Boolean,
  17. ForeignKey
  18. )
  19. from slugify import slugify
  20. from webhelpers.text import urlify
  21. from webhelpers.paginate import PageURL_WebOb, Page
  22. from webhelpers.date import time_ago_in_words
  23. from sqlalchemy.ext.declarative import declarative_base
  24. from sqlalchemy.orm import (
  25. scoped_session,
  26. sessionmaker
  27. )
  28. from zope.sqlalchemy import ZopeTransactionExtension
  29. DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
  30. Base = declarative_base()
  31. CurrentYear = 2015
  32. class TasksArea(Base):
  33. __tablename__ = 'staff_tasks_area'
  34. uid = Column(Integer, primary_key=True)
  35. name = Column(Unicode(80))
  36. description = Column(UnicodeText)
  37. @classmethod
  38. def by_id(cls, uid):
  39. return DBSession.query(cls).filter(cls.uid == uid).first()
  40. class Tasks(Base):
  41. __tablename__ = 'staff_tasks'
  42. uid = Column(Integer, primary_key=True)
  43. area_uid = Column(Integer, ForeignKey('staff_tasks_area.uid') )
  44. due_date = Column(DateTime, default=None)
  45. closed_by = Column(Integer, ForeignKey('users.uid') )
  46. closed_date = Column(DateTime, default=None)
  47. closed = Column(Integer, default=0)
  48. name = Column(Unicode(80))
  49. description = Column(UnicodeText)
  50. area = relationship(TasksArea, backref=backref("tasks") )
  51. assignee = relationship('User', backref=backref("task_assoc") )
  52. @classmethod
  53. def by_id(cls, uid):
  54. return DBSession.query(cls).filter(cls.uid == uid).first()
  55. class User_Event(Base):
  56. """ Créer le lien entre la personne et l' évenement en fonction de l'année"""
  57. __tablename__ = 'user_event_link'
  58. uid = Column(Integer, primary_key=True)
  59. event_uid = Column(Integer, ForeignKey('events.uid') )
  60. #, primary_key=True)
  61. #
  62. user_uid = Column(Integer, ForeignKey('users.uid') )
  63. #, primary_key=True)
  64. #
  65. year_uid = Column(Integer, ForeignKey('jm2l_year.year_uid'), default=CurrentYear)
  66. role = Column(Unicode(80))
  67. # Define some relation
  68. #user = relationship('User', backref=backref("events_assoc") )
  69. #event = relationship('events', backref=backref("users_assoc") )
  70. class JM2L_Year(Base):
  71. __tablename__ = 'jm2l_year'
  72. year_uid = Column(Integer, primary_key=True)
  73. description = Column(UnicodeText)
  74. doss_presse = Column(UnicodeText)
  75. state = Column(Enum('Archived', 'Cancelled', 'Ongoing'))
  76. start_time = Column(DateTime, default=datetime.datetime.now)
  77. end_time = Column(DateTime, default=datetime.datetime.now)
  78. created = Column(DateTime, default=datetime.datetime.now)
  79. last_change = Column(DateTime, default=datetime.datetime.now)
  80. @property
  81. def AvailableTimeSlots(self, TimeStep=30):
  82. Available = self.end_time - self.start_time
  83. NbMinutes = Available.total_seconds()/60
  84. NbSteps = NbMinutes/TimeStep
  85. # Create the range of date each 30min
  86. date_list = [self.start_time + datetime.timedelta(minutes=TimeStep*x) for x in range(0, int(NbSteps))]
  87. # Remove out of range datetime
  88. # Remove hours > 19h
  89. date_list = filter(lambda x:x.hour < 19, date_list)
  90. # Remove hours < 10h
  91. date_list = filter(lambda x:x.hour >= 10, date_list)
  92. # Remove 12h < hours < 13h
  93. date_list = filter(lambda x: x.hour<12 or x.hour>=13, date_list)
  94. return date_list
  95. @property
  96. def DocLinks(self):
  97. from .upload import MediaPath
  98. return zip( sorted(MediaPath().get_list('presse', self.year_uid, 'Other')),
  99. sorted(MediaPath().get_thumb('presse', self.year_uid, 'Other'))
  100. )
  101. class User(Base):
  102. __tablename__ = 'users'
  103. uid = Column(Integer, primary_key=True)
  104. user_id = Column(Integer)
  105. nom = Column(Unicode(80))
  106. prenom = Column(Unicode(80))
  107. pseudo = Column(Unicode(80))
  108. slug = Column(Unicode(164))
  109. mail = Column(Unicode(100))
  110. password = Column(Unicode(100), nullable=False)
  111. fonction = Column(Unicode(80))
  112. website = Column(Unicode(100))
  113. phone = Column(Unicode(10))
  114. created = Column(DateTime, default=datetime.datetime.now)
  115. last_logged = Column(DateTime, default=datetime.datetime.now)
  116. last_change = Column(DateTime, default=datetime.datetime.now)
  117. active = Column(Integer, default=1)
  118. bio = Column(UnicodeText)
  119. gpg_key = Column(UnicodeText)
  120. soc_link = Column(UnicodeText)
  121. Staff = Column(Integer, default=0)
  122. vote_logo = Column(Integer, default=0)
  123. wifi_user = Column(Unicode(80), nullable=True)
  124. wifi_pass = Column(Unicode(80), nullable=True)
  125. # relations
  126. tiers = relationship('Tiers', secondary='user_tiers_link' )
  127. events = relationship('Event', secondary='user_event_link' )
  128. tiersship = relationship('User_Tiers', backref="matching_users")
  129. @classmethod
  130. def by_id(cls, uid):
  131. return DBSession.query(cls).filter(cls.uid == uid).first()
  132. @classmethod
  133. def by_mail(cls, mail):
  134. return DBSession.query(cls).filter(cls.mail == mail).first()
  135. @classmethod
  136. def by_slug(cls, slug):
  137. return DBSession.query(cls).filter(cls.slug == slug).first()
  138. @classmethod
  139. def by_user_id(cls, user_id):
  140. return DBSession.query(cls).filter(cls.user_id == user_id).first()
  141. @classmethod
  142. def by_name(cls, name):
  143. return DBSession.query(cls).filter(cls.nom == name).first()
  144. @classmethod
  145. def by_hash(cls, tsthash):
  146. for u in DBSession.query(cls):
  147. if u.my_hash==tsthash:
  148. return u
  149. return None
  150. @property
  151. def is_Intervenant(self, year=2015):
  152. """ This property will return if User do an event on specified year """
  153. return DBSession.query(Event).join(User_Event) \
  154. .filter(User_Event.user_uid==self.uid) \
  155. .filter(Event.for_year==year).count()
  156. @property
  157. def is_crew(self, year=2015):
  158. """ This property will return if User subscribe orga task on specified year """
  159. return DBSession.query(User,Sejour.orga_part).outerjoin(Sejour).filter(User.uid == self.uid).one()[1]
  160. def year_events(self, EventType='All', year=2015):
  161. if EventType=='All':
  162. return filter(lambda e: e.for_year==year, self.events)
  163. else:
  164. return filter(lambda e: e.for_year==year and e.event_type==EventType, self.events)
  165. @property
  166. def my_hash(self):
  167. m = hashlib.sha1()
  168. m.update("Nobody inspects ")
  169. if self.nom:
  170. m.update(unicode.encode(self.nom,'utf8'))
  171. if self.pseudo:
  172. m.update(unicode.encode(self.pseudo,'utf8'))
  173. if self.prenom:
  174. m.update(unicode.encode(self.prenom,'utf8'))
  175. m.update(" the spammish repetition")
  176. return m.hexdigest()
  177. @property
  178. def Photos(self):
  179. return DBSession.query(Media.filename) \
  180. .filter(Media.media_table=='users') \
  181. .filter(Media.media_type=='Image') \
  182. .filter(Media.link_id == self.user_id).all()
  183. @property
  184. def PhotosLinks(self):
  185. from .upload import MediaPath
  186. return MediaPath().get_list('users', self.uid)
  187. @property
  188. def PhotosThumb(self):
  189. from .upload import MediaPath
  190. return MediaPath().get_thumb('users', self.uid)
  191. def verify_password(self, password):
  192. return self.password == password
  193. class TiersOpt(Base):
  194. __tablename__ = 'tiers_opt'
  195. uid = Column(Integer, primary_key=True)
  196. entity_type = Column(Unicode(80), nullable=False)
  197. entity_subtype = Column(Unicode(80))
  198. entity_role = Column(Unicode(80))
  199. @property
  200. def slug_entity_type(self):
  201. return slugify(self.entity_type)
  202. @property
  203. def slug_entity_subtype(self):
  204. return slugify(self.entity_subtype)
  205. @classmethod
  206. def get_entity_type(cls):
  207. return DBSession.query(cls, func.count(Tiers.ent_type).label('count'))\
  208. .outerjoin(Tiers)\
  209. .group_by(cls.entity_type).all()
  210. @classmethod
  211. def get_entity_sub_type(cls, entity_type):
  212. return DBSession.query(cls, func.count(Tiers.ent_type).label('count'))\
  213. .outerjoin(Tiers)\
  214. .filter(cls.entity_type == entity_type)\
  215. .group_by(cls.entity_subtype).all()
  216. @classmethod
  217. def by_id(cls, uid):
  218. return DBSession.query(cls).filter(cls.uid == uid).first()
  219. class Tiers(Base):
  220. __tablename__ = 'tiers'
  221. uid = Column(Integer, primary_key=True)
  222. tiers_id = Column(Integer)
  223. name = Column(Unicode(100), nullable=False)
  224. slug = Column(Unicode(100))
  225. description = Column(UnicodeText)
  226. website = Column(Unicode(100))
  227. tiers_type = Column(Integer, ForeignKey('tiers_opt.uid'), default=1)
  228. created = Column(DateTime, default=datetime.datetime.now)
  229. last_change = Column(DateTime, default=datetime.datetime.now)
  230. # relations
  231. ent_type = relationship('TiersOpt')
  232. #members = relationship('User', secondary='user_tiers_link' )
  233. members = relationship(User,
  234. secondary='user_tiers_link',
  235. backref=backref('associate', uselist=False),
  236. lazy='dynamic')
  237. creator_id = Column(Integer)
  238. membership = relationship('User_Tiers', backref="matching_tiers")
  239. roles = relationship('Role_Tiers', backref="roles_tiers") #secondary='role_tiers_link' )
  240. @classmethod
  241. def by_id(cls, uid):
  242. return DBSession.query(cls).filter(cls.uid == uid).first()
  243. @classmethod
  244. def by_slug(cls, slug):
  245. return DBSession.query(cls).filter(cls.slug == slug).first()
  246. @property
  247. def get_entity_type(self):
  248. return DBSession.query(TiersOpt)\
  249. .filter(TiersOpt.uid == self.tiers_type).first()
  250. @property
  251. def logo(self):
  252. return DBSession.query(Media) \
  253. .filter(Media.media_table == 'tiers') \
  254. .filter(Media.media_type == 'Image') \
  255. .filter(Media.link_id == self.uid)
  256. @property
  257. def DocLinks(self):
  258. from .upload import MediaPath
  259. return zip( sorted( MediaPath().get_list('tiers', self.uid, 'Other') ),
  260. sorted( MediaPath().get_thumb('tiers', self.uid, 'Other') )
  261. )
  262. @property
  263. def PhotosLinks(self):
  264. from .upload import MediaPath
  265. return MediaPath().get_list('tiers', self.uid, 'Image')
  266. @property
  267. def ThumbLinks(self):
  268. from .upload import MediaPath
  269. return MediaPath().get_thumb('tiers', self.uid)
  270. class Role_Tiers(Base):
  271. """ Créer le lien entre le tiers et son rôle dans l'évenement en fonction de l'année"""
  272. __tablename__ = 'role_tiers_link'
  273. uid_role = Column(Integer, primary_key=True)
  274. year_uid = Column(Integer, ForeignKey('jm2l_year.year_uid'), default=CurrentYear)
  275. tiers_uid = Column(Integer, ForeignKey('tiers.uid'))
  276. tiers = relationship(Tiers, backref=backref("roles_assoc") )
  277. tiers_role = Column(Enum('Exposant', 'Sponsor', 'Donateur'))
  278. event_uid = Column(Integer, default=None) # Optionnal link with Event
  279. class User_Tiers(Base):
  280. """ Créer le lien entre la personne et le tiers en fonction de l'année"""
  281. __tablename__ = 'user_tiers_link'
  282. uid_tiers = Column(Integer, primary_key=True)
  283. year_uid = Column(Integer, ForeignKey('jm2l_year.year_uid'), default=CurrentYear)
  284. tiers_uid = Column(Integer, ForeignKey('tiers.uid'))
  285. tiers = relationship(Tiers, backref=backref("users_assoc") )
  286. user_uid = Column(Integer, ForeignKey('users.uid'))
  287. user = relationship(User, backref=backref("tiers_assoc") )
  288. role = Column(Unicode(80))
  289. class Media(Base):
  290. __tablename__ = 'medias'
  291. media_id = Column(Integer, primary_key=True)
  292. for_year = Column(Integer, ForeignKey('jm2l_year.year_uid'))
  293. media_table = Column(Enum('users', 'tiers', 'place', 'salle', 'RIB', 'Justif', 'event' ))
  294. media_type = Column(Enum('Image', 'Video', 'Pres', 'Document'))
  295. link_id = Column(Integer)
  296. mime_type = Column(Unicode(20))
  297. size = Column(Integer)
  298. width = Column(Integer)
  299. height = Column(Integer)
  300. length = Column(Integer)
  301. filename = Column(UnicodeText)
  302. created = Column(DateTime, default=datetime.datetime.now)
  303. @property
  304. def get_path(self):
  305. #return '/upload/%s/%s/%s' % (self.media_type, self.media_table, self.filename)
  306. return '/resources/%s/%s/%s' % (self.for_year, self.media_type, self.filename)
  307. class SallePhy(Base):
  308. """ Représente une salle dans les locaux """
  309. __tablename__ = 'phy_salle'
  310. uid = Column(Integer, primary_key=True)
  311. name = Column(Unicode(40)) # Numéro de salle vu de polytech
  312. slug = Column(Unicode(40))
  313. description = Column(UnicodeText) # Description du matériel disponible
  314. nb_places = Column(Integer, default=0) # Nombre de places assises
  315. @classmethod
  316. def by_id(cls, uid):
  317. return DBSession.query(cls).filter(cls.uid == uid).first()
  318. @property
  319. def PhotosLinks(self):
  320. from .upload import MediaPath
  321. return MediaPath().get_list('salle', self.uid, 'Image')
  322. class Salles(Base):
  323. __tablename__ = 'salle'
  324. salle_id = Column(Integer, primary_key=True)
  325. phy_salle_id = Column(Integer, ForeignKey('phy_salle.uid'))
  326. year_uid = Column(Integer, ForeignKey('jm2l_year.year_uid'), default=CurrentYear)
  327. name = Column(Unicode(40))
  328. place_type = Column(Enum('Conference', 'Stand', 'Atelier', 'Table ronde', 'MAO', 'Repas', 'Autres'))
  329. description = Column(UnicodeText) # Description du matériel disponible
  330. created = Column(DateTime, default=datetime.datetime.now)
  331. last_change = Column(DateTime, default=datetime.datetime.now)
  332. phy = relationship(SallePhy)
  333. @classmethod
  334. def by_id(cls, uid):
  335. return DBSession.query(cls).filter(cls.salle_id == uid).first()
  336. class Place(Base):
  337. __tablename__ = 'place'
  338. place_id = Column(Integer, primary_key=True)
  339. usage = Column(Boolean, default=False) # By Default / Extended
  340. place_type = Column(Enum('Aeroport', 'Gare', 'JM2L', \
  341. 'Hotel', 'Habitant', 'Restaurant', 'Autres'))
  342. display_name = Column(Unicode(20))
  343. name = Column(Unicode(80))
  344. slug = Column(Unicode(80))
  345. specific = Column(Unicode(80)) # eg Terminal 2
  346. gps_coord = Column(Unicode(30))
  347. adresse = Column(Unicode(100))
  348. codePostal = Column(Unicode(5))
  349. ville = Column(Unicode(40))
  350. website = Column(Unicode(100))
  351. description = Column(UnicodeText)
  352. created_by = Column(Integer, ForeignKey('users.user_id'))
  353. created = Column(DateTime, default=datetime.datetime.now)
  354. last_change = Column(DateTime, default=datetime.datetime.now)
  355. @classmethod
  356. def by_id(cls, uid):
  357. return DBSession.query(cls).filter(cls.place_id == uid).first()
  358. @classmethod
  359. def get_list(cls, All=False):
  360. if All:
  361. return DBSession.query(cls).all()
  362. else:
  363. return DBSession.query(cls).filter(cls.usage==True).all()
  364. class Itineraire(Base):
  365. __tablename__ = 'itineraire'
  366. itin_id = Column(Integer, primary_key=True)
  367. start_place = Column(Integer, ForeignKey('place.place_id')) # Place link
  368. arrival_place = Column(Integer, ForeignKey('place.place_id')) # Place link
  369. distance = Column(Integer)
  370. duration = Column(Integer)
  371. price = Column(Integer)
  372. tr_pied = Column(Boolean, default=False)
  373. tr_velo = Column(Boolean, default=False)
  374. tr_moto = Column(Boolean, default=False)
  375. tr_voiture = Column(Boolean, default=False)
  376. tr_bus = Column(Boolean, default=False)
  377. tr_taxi = Column(Boolean, default=False)
  378. tr_avion = Column(Boolean, default=False)
  379. description = Column(UnicodeText)
  380. created_by = Column(Integer, ForeignKey('users.user_id')) # User link
  381. created = Column(DateTime, default=datetime.datetime.now)
  382. last_change = Column(DateTime, default=datetime.datetime.now)
  383. # relations
  384. start = relationship(Place, foreign_keys=[start_place])
  385. arrival = relationship(Place, foreign_keys=[arrival_place])
  386. class Exchange_Cat(Base):
  387. __tablename__ = 'exchange_category'
  388. cat_id = Column(Integer, primary_key=True)
  389. exch_type = Column(Enum('H', 'C', 'M')) # Heberg, Co-voit, Materiel
  390. exch_subtype = Column(Unicode(80))
  391. description = Column(UnicodeText)
  392. class Exchange(Base):
  393. __tablename__ = 'exchanges'
  394. exch_id = Column(Integer, primary_key=True)
  395. for_year = Column(Integer, ForeignKey('jm2l_year.year_uid')) # link JM2L_Year
  396. exch_done = Column(Boolean, default=False)
  397. exch_state = Column(Enum('Ask', 'Proposal'))
  398. exch_type = Column(Enum('H', 'C', 'M')) # Heberg, Co-Voit, Materiel
  399. exch_categ = Column(Integer, ForeignKey('exchange_category.cat_id')) # Exchange_Cat link
  400. # Users
  401. asker_id = Column(Integer, ForeignKey('users.uid')) # User link
  402. provider_id = Column(Integer, ForeignKey('users.uid')) # User link
  403. start_time = Column(DateTime, default=datetime.datetime.now)
  404. end_time = Column(DateTime, default=datetime.datetime.now)
  405. # Co-voiturage
  406. itin_id = Column(Integer, ForeignKey('itineraire.itin_id')) # Itineraire link
  407. # Hebergement
  408. place_id = Column(Integer, ForeignKey('place.place_id')) # Place link
  409. # Materiel
  410. duration = Column(Integer)
  411. description = Column(UnicodeText)
  412. pictures = Column(Unicode(80))
  413. created_by = Column(Integer) # User link
  414. created = Column(DateTime, default=datetime.datetime.now)
  415. last_change = Column(DateTime, default=datetime.datetime.now)
  416. # relations
  417. Category = relationship(Exchange_Cat, backref="exchanges")
  418. Itin = relationship(Itineraire, backref="exchanged")
  419. asker = relationship(User, foreign_keys=[asker_id], backref="asked")
  420. provider = relationship(User, foreign_keys=[provider_id], backref="provided")
  421. @classmethod
  422. def by_id(cls, uid):
  423. return DBSession.query(cls).filter(cls.exch_id == uid).first()
  424. @classmethod
  425. def get_counters(cls):
  426. return DBSession.query(cls.exch_state, cls.exch_type, cls.exch_done, func.count(cls.exch_id))\
  427. .filter(cls.for_year==2015)\
  428. .group_by(cls.exch_state, cls.exch_type, cls.exch_done)
  429. @classmethod
  430. def get_my_counters(cls, uid):
  431. return DBSession.query(cls.exch_state, cls.exch_type, cls.exch_done, func.count(cls.exch_id))\
  432. .filter(cls.for_year==2015)\
  433. .filter( or_(cls.asker_id==uid, cls.provider_id==uid) )\
  434. .group_by(cls.exch_state, cls.exch_type, cls.exch_done)
  435. @classmethod
  436. def get_overview(cls, uid):
  437. # Build a Dic with all exchange to save database access
  438. DicResult= {}
  439. for extype in ['F','C','H','M']:
  440. DicResult[extype] = {}
  441. for exstate in ['Ask','Proposal','Missing','Agree']:
  442. DicResult[extype][exstate]=[]
  443. DicResult[extype]['Counters']={'AllAsk':0, 'AllProp':0, 'AllAgree':0}
  444. Query = DBSession.query(cls)\
  445. .filter(cls.for_year==2015)\
  446. .order_by(cls.start_time).all()
  447. for item in Query:
  448. if item.exch_done:
  449. DicResult[item.exch_type]['Counters']['AllAgree']+=1
  450. if item.exch_state=='Ask':
  451. DicResult[item.exch_type]['Counters']['AllAsk']+=1
  452. if item.exch_state=='Proposal':
  453. DicResult[item.exch_type]['Counters']['AllProp']+=1
  454. if item.asker_id==uid or item.provider_id==uid:
  455. if item.asker_id==uid and item.exch_state=='Ask':
  456. DicResult[item.exch_type]['Ask'].append(item)
  457. if item.provider_id==uid and item.exch_state=='Ask':
  458. DicResult[item.exch_type]['Proposal'].append(item)
  459. if item.asker_id==uid and item.exch_state=='Proposal':
  460. DicResult[item.exch_type]['Ask'].append(item)
  461. if item.provider_id==uid and item.exch_state=='Proposal':
  462. DicResult[item.exch_type]['Proposal'].append(item)
  463. if item.exch_done:
  464. DicResult[item.exch_type]['Agree'].append(item)
  465. else:
  466. DicResult[item.exch_type]['Missing'].append(item)
  467. return DicResult
  468. @classmethod
  469. def get_pub_list(cls, exch_type):
  470. return DBSession.query(cls).filter(cls.for_year==2015 and cls.exch_state in ['Ask','Proposal'])\
  471. .filter(cls.exch_type=='%s' % exch_type)\
  472. .filter(cls.exch_done==False)\
  473. .all()
  474. @classmethod
  475. def get_my_list(cls, uid, exch_type):
  476. DicResult = {}
  477. DicResult['Ask']=DBSession.query(cls)\
  478. .filter(cls.for_year==2015)\
  479. .filter( or_(cls.asker_id==uid, cls.provider_id==uid) )\
  480. .filter(cls.exch_type=='%s' % exch_type)\
  481. .filter(cls.exch_state=='Ask')\
  482. .order_by(cls.start_time).all()
  483. DicResult['Proposal']=DBSession.query(cls)\
  484. .filter(cls.for_year==2015)\
  485. .filter( or_(cls.asker_id==uid, cls.provider_id==uid) )\
  486. .filter(cls.exch_type=='%s' % exch_type)\
  487. .filter(cls.exch_state=='Proposal')\
  488. .order_by(cls.start_time).all()
  489. return DicResult
  490. class Sejour(Base):
  491. __tablename__ = 'sejour'
  492. sej_id = Column(Integer, primary_key=True)
  493. user_id = Column(Integer, ForeignKey('users.uid')) # User link
  494. for_year = Column(Integer, ForeignKey('jm2l_year.year_uid')) # link JM2L_Year
  495. arrival_time = Column(DateTime)
  496. arrival_place = Column(Integer, ForeignKey('place.place_id')) # Place link
  497. arrival_check = Column(Integer, default=0)
  498. arrival_text = Column(Unicode(100))
  499. depart_time = Column(DateTime)
  500. depart_place = Column(Integer, ForeignKey('place.place_id')) # Place link
  501. depart_check = Column(Integer, default=0)
  502. depart_text = Column(Unicode(100))
  503. repas = Column(Integer)
  504. repas_allerg = Column(Unicode(100))
  505. repas_contr = Column(Unicode(100))
  506. orga_part = Column(Integer, default=0)
  507. travel_detail = Column(UnicodeText)
  508. created = Column(DateTime, default=datetime.datetime.now)
  509. last_change = Column(DateTime, default=datetime.datetime.now)
  510. @classmethod
  511. def by_user(cls, uid):
  512. return DBSession.query(cls).filter(cls.user_id == uid).first()
  513. class Event(Base):
  514. __tablename__ = 'events'
  515. uid = Column(Integer, primary_key=True)
  516. salle_uid = Column(Integer, ForeignKey('salle.salle_id'))
  517. event_uid = Column(Integer)
  518. for_year = Column(Integer, ForeignKey('jm2l_year.year_uid')) # link JM2L_Year
  519. name = Column(Unicode(100), nullable=False)
  520. slug = Column(Unicode(100))
  521. event_type = Column(Enum('Conference', 'Stand', 'Atelier', 'Table ronde', 'MAO', 'Repas', 'Autres'))
  522. start_time = Column(DateTime, default=datetime.datetime.now)
  523. end_time = Column(DateTime, default=datetime.datetime.now)
  524. description = Column(UnicodeText)
  525. created = Column(DateTime, default=datetime.datetime.now)
  526. last_change = Column(DateTime, default=datetime.datetime.now)
  527. intervenants = relationship(User,
  528. secondary='user_event_link',
  529. backref=backref('participate', uselist=False),
  530. lazy='dynamic')
  531. interventions = relationship(User_Event, backref="matching_events")
  532. Salle = relationship(Salles, backref='allevents')
  533. @classmethod
  534. def by_id(cls, uid):
  535. return DBSession.query(cls)\
  536. .filter(cls.uid == uid).first()
  537. @classmethod
  538. def by_slug(cls, slug, year=None):
  539. if not year is None:
  540. return DBSession.query(cls)\
  541. .filter(cls.for_year==year)\
  542. .filter(cls.slug == slug).first()
  543. else:
  544. return DBSession.query(cls)\
  545. .filter(cls.slug == slug).first()
  546. def get_linked_tiers(self):
  547. ListLink = DBSession.query(Role_Tiers.tiers_uid) \
  548. .filter(Role_Tiers.year_uid==self.for_year) \
  549. .filter(Role_Tiers.tiers_role=="Exposant") \
  550. .filter(Role_Tiers.event_uid==self.uid)
  551. return DBSession.query(Tiers).filter( Tiers.uid.in_( ListLink ) )
  552. @property
  553. def video(self):
  554. return DBSession.query(Media) \
  555. .filter(Media.media_table == 'event') \
  556. .filter(Media.media_type == 'Video') \
  557. .filter(Media.link_id == self.uid)
  558. @property
  559. def presentation(self):
  560. return DBSession.query(Media) \
  561. .filter(Media.media_table == 'event') \
  562. .filter(Media.media_type == 'Pres') \
  563. .filter(Media.link_id == self.uid)
  564. @property
  565. def created_in_words(self):
  566. return time_ago_in_words(self.created)
  567. class Entry(Base):
  568. __tablename__ = 'entries'
  569. id = Column(Integer, primary_key=True)
  570. active = Column(Integer, default=True)
  571. title = Column(Unicode(255), unique=True, nullable=False)
  572. body = Column(UnicodeText, default=u'')
  573. created = Column(DateTime, default=datetime.datetime.now)
  574. edited = Column(DateTime, default=datetime.datetime.now)
  575. @classmethod
  576. def all(cls):
  577. return DBSession.query(Entry).order_by(sa.desc(Entry.created))
  578. @classmethod
  579. def by_id(cls, uid):
  580. return DBSession.query(Entry).filter(Entry.id == uid).first()
  581. @property
  582. def slug(self):
  583. return urlify(self.title)
  584. @property
  585. def created_in_words(self):
  586. return time_ago_in_words(self.created)
  587. @classmethod
  588. def get_paginator(cls, request, page=1):
  589. page_url = PageURL_WebOb(request)
  590. return Page(Entry.all(), page, url=page_url, items_per_page=5)
  591. #class Seances(Base):
  592. # __tablename__ = 'seances'
  593. def get_user(request):
  594. # the below line is just an example, use your own method of
  595. # accessing a database connection here (this could even be another
  596. # request property such as request.db, implemented using this same
  597. # pattern).
  598. userid = unauthenticated_userid(request)
  599. if userid is not None:
  600. # this should return None if the user doesn't exist
  601. # in the database
  602. return DBSession.query(User).filter(User.uid==userid).first()
  603. def get_sponsors(request, Year):
  604. if Year:
  605. return DBSession.query(Tiers)\
  606. .join(Role_Tiers, Role_Tiers.tiers_uid == Tiers.uid )\
  607. .filter( Role_Tiers.tiers_role == 'Sponsor')\
  608. .filter( Role_Tiers.year_uid == Year)
  609. else:
  610. return DBSession.query(Tiers)\
  611. .join(Role_Tiers, Role_Tiers.tiers_uid == Tiers.uid )\
  612. .filter( Role_Tiers.tiers_role == 'Sponsor')
  613. def get_exposants(request, Year):
  614. if Year:
  615. return DBSession.query(Tiers)\
  616. .join(Role_Tiers, Role_Tiers.tiers_uid == Tiers.uid )\
  617. .filter( Role_Tiers.tiers_role == 'Exposant')\
  618. .filter( Role_Tiers.year_uid == Year)
  619. else:
  620. return DBSession.query(Tiers)\
  621. .join(Role_Tiers, Role_Tiers.tiers_uid == Tiers.uid )\
  622. .filter( Role_Tiers.tiers_role == 'Exposant')