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. with transaction.manager:
  38. admin = User(nom=u'jm2l', prenom=u'contact',
  39. slug=u'contact jm2l', password=u'jm2l',
  40. mail=u'contact@jm2l.linux-azur.org',
  41. Staff=1
  42. )
  43. DBSession.add(admin)
  44. # Create 2015 year event
  45. jm2l = JM2L_Year(year_uid=2015,
  46. state="Ongoing",
  47. description=u"%d, %dème édition des JM2L." % ( 2015, 9 ),
  48. start_time=datetime.strptime("28-11-2015 10:00","%d-%m-%Y %H:%M"),
  49. end_time=datetime.strptime("28-11-2015 19:00","%d-%m-%Y %H:%M")
  50. )
  51. DBSession.add(jm2l)
  52. # Create 2015 Physic room event
  53. phy_salle = SallePhy( name=u"Polytech salle 211",
  54. description=u"Salle informatique, présence de postes de travail",)
  55. DBSession.add(phy_salle)
  56. DBSession.flush()
  57. # Create matching room place (Name could change each year)
  58. salle = Salles(name=u"Mystère", description=u"Salle Mystère",
  59. phy_salle_id = phy_salle.uid,
  60. year_uid = jm2l.year_uid)
  61. DBSession.add(salle)
  62. with transaction.manager:
  63. # Re-Generate passwords
  64. for u in DBSession.query(User).filter(User.Staff==None):
  65. # Fix empty fields
  66. password = ''.join(choice(printable[:-6]) for _ in range(12))
  67. u.password = password
  68. u.Staff = 0
  69. DBSession.merge(u)
  70. print u.nom, u.prenom, u.Staff