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.
 
 
 
 
 

82 lines
2.4 KiB

  1. # -*- coding: utf8 -*-
  2. import os
  3. import sys
  4. import transaction
  5. import time
  6. import lxml.etree as ET
  7. from sqlalchemy import engine_from_config
  8. from sqlalchemy import create_engine
  9. import unicodedata
  10. import urllib
  11. # Usefull tools
  12. from slugify import slugify
  13. from sqlite3 import dbapi2 as sqlite
  14. from os import path
  15. from pyramid.paster import (
  16. get_appsettings,
  17. setup_logging,
  18. )
  19. from string import printable
  20. from random import choice
  21. from jm2l.models import *
  22. from datetime import datetime
  23. def usage(argv):
  24. cmd = os.path.basename(argv[0])
  25. print('usage: %s <config_uri>\n'
  26. '(example: "%s development.ini")' % (cmd, cmd))
  27. sys.exit(1)
  28. def main(argv=sys.argv):
  29. if len(argv) != 2:
  30. usage(argv)
  31. config_uri = argv[1]
  32. setup_logging(config_uri)
  33. settings = get_appsettings(config_uri)
  34. engine = engine_from_config(settings, 'sqlalchemy.')
  35. DBSession.configure(bind=engine)
  36. Base.metadata.create_all(engine)
  37. if 0:
  38. with transaction.manager:
  39. admin = User(nom=u'jm2l', prenom='contact',
  40. slug='contact jm2l', password=u'jm2l',
  41. mail=u'contact@jm2l.linux-azur.org',
  42. Staff=1
  43. )
  44. DBSession.add(admin)
  45. # Create 2015 year event
  46. jm2l = JM2L_Year(year_uid=2015,
  47. state="Ongoing",
  48. description=u"%d, %dème édition des JM2L." % ( 2015, 9 ),
  49. start_time=datetime.strptime("28-11-2015 10:00","%d-%m-%Y %H:%M"),
  50. end_time=datetime.strptime("28-11-2015 19:00","%d-%m-%Y %H:%M")
  51. )
  52. DBSession.add(jm2l)
  53. # Create 2015 Physic room event
  54. phy_salle = SallePhy( name=u"Polytech salle 211",
  55. description=u"Salle informatique, présence de postes de travail",)
  56. DBSession.add(phy_salle)
  57. DBSession.flush()
  58. # Create matching room place (Name could change each year)
  59. salle = Salles(name=u"Mystère", description=u"Salle Mystère",
  60. phy_salle_id = phy_salle.uid,
  61. year_uid = jm2l.year_uid)
  62. DBSession.add(salle)
  63. with transaction.manager:
  64. # Re-Generate passwords
  65. for u in DBSession.query(User).filter(User.Staff==None):
  66. # Fix empty fields
  67. password = ''.join(choice(printable[:-6]) for _ in range(12))
  68. u.password = password
  69. u.Staff = 0
  70. DBSession.merge(u)
  71. print u.nom, u.prenom, u.Staff