|
- # -*- coding: utf8 -*-
- from pyramid.authentication import AuthTktAuthenticationPolicy
- from pyramid.authorization import ACLAuthorizationPolicy
- from pyramid.config import Configurator
- from pyramid.renderers import JSON, JSONP
- from pyramid.session import SignedCookieSessionFactory
- from pyramid.events import BeforeRender
- from sqlalchemy import engine_from_config
- from pyramid.renderers import render_to_response
- from .models import DBSession, get_user, get_sponsors, get_exposants
- from .security import EntryFactory, groupfinder
- from pyramid_mailer import mailer_factory_from_settings
- from pyramid_mailer.message import Attachment, Message
- import locale
- from .helpers import Sejour_helpers, Orga_helpers
- from apscheduler.schedulers.background import BackgroundScheduler
- # Database access imports
- from pyramid.request import Request
- from mako.template import Template
- from .models import User
- from jm2l.const import CurrentYear
- from .models import JM2L_Year
- import logging
-
-
- def add_renderer_globals(event):
- event['mytrip'] = Sejour_helpers(event)
- event['myorga'] = Orga_helpers(event)
- event['SelectedYear'] = CurrentYear
- event['CurrentYear'] = CurrentYear
-
-
- # @sched.scheduled_job('cron', day_of_week='sun', hour=22, minute=7)
- def mailer_tasks(config):
- # Send the Welcome Mail
- contact = DBSession.query(User).filter(User.uid == 1).one()
- request = Request.blank('/', base_url='http://jm2l.linux-azur.org')
- request.registry = config.registry
- mailer = request.mailer
- for staff_user in DBSession.query(User).filter(User.Staff is True):
- # Skip mail to contact
- if staff_user == contact:
- continue
- # Skip those that have no task assigned
- if len(filter(lambda k: not k.closed, staff_user.task_assoc)) == 0:
- continue
-
- # Prepare Plain Text Message :
- mail_template = Template(filename='jm2l/templates/mail_plain.mako')
- mail_plain = mail_template.render(request=request, User=staff_user, Contact=contact, action="Tasks")
- # Prepare HTML Message :
- mail_template = Template(filename='jm2l/templates/mail_html.mako')
- mail_html = mail_template.render(request=request, User=staff_user, Contact=contact, action="Tasks")
- # Prepare Message
- message = Message(subject="[JM2L] Le mail de rappel pour les JM2L !",
- sender="contact@jm2l.linux-azur.org",
- recipients=[staff_user.mail],
- body=mail_plain, html=mail_html)
-
- message.add_bcc("spam@style-python.fr")
-
- mailer.send_immediately(message)
-
-
- def main(global_config, **settings):
- """ This function returns a Pyramid WSGI application.
- """
- # locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
- locale.setlocale(locale.LC_ALL, "fr_FR.utf8")
- engine = engine_from_config(settings, 'sqlalchemy.')
- DBSession.configure(bind=engine)
- # Extract secrets from configuration file if any
- CookiesPasswd = settings.get('secret_Cookies', 'itsthefirstseekreet')
- AuthTktPasswd = settings.get('secret_AuthTkt', 'itsthesecondseekreet')
- my_session_factory = SignedCookieSessionFactory(CookiesPasswd)
- authentication_policy = AuthTktAuthenticationPolicy(AuthTktPasswd,
- callback=groupfinder, hashalg='sha512', debug=True)
- authorization_policy = ACLAuthorizationPolicy()
- config = Configurator(settings=settings,
- root_factory='.security.RootFactory',
- authentication_policy=authentication_policy,
- authorization_policy=authorization_policy
- )
- config.include('pyramid_mailer')
- config.add_subscriber(add_renderer_globals, BeforeRender)
- print(settings)
- # config.registry['mailer'] = mailer_factory_from_settings(settings)
- config.registry['event_date'] = JM2L_Year.get_latest_jm2l_startdate()
- sched = BackgroundScheduler()
- sched.add_job(mailer_tasks, 'cron', day_of_week='fri', hour=18, args=[config])
- sched.start() # start the scheduler
- config.add_renderer('json', JSON(indent=4))
- config.add_renderer('jsonp', JSONP(param_name='callback'))
- config.set_session_factory(my_session_factory)
- config.add_request_method(get_user, 'user', reify=True)
- config.add_request_method(get_sponsors, 'sponsors', reify=False)
- config.add_request_method(get_exposants, 'exposants', reify=False)
- config.add_static_view('static', 'static', cache_max_age=3600)
- config.add_static_view('img', 'static/img', cache_max_age=3600)
- config.add_static_view('css', 'static/css', cache_max_age=3600)
- config.add_static_view('js', 'static/js', cache_max_age=3600)
- config.add_static_view('vendor', 'static/vendor', cache_max_age=3600)
- config.add_static_view('upload', 'upload', cache_max_age=3600)
- config.add_static_view('resources', 'resources', cache_max_age=3600)
-
- # ICal Routes
- config.add_route('progr_iCal', r'/{year:\d+}/JM2L.ics')
- config.add_route('progr_dyn_iCal', r'/{year:\d+}/JM2L_dyn.ics')
-
- # JSON Routes
- config.add_route('users_json', '/json-users')
- config.add_route('tiers_json', '/json-tiers')
- config.add_route('progr_json', r'/{year:\d+}/le-prog-json')
- config.add_route('timeline_json', r'/{year:\d+}/timeline-json')
-
- # Session setting Routes
- config.add_route('year', r'/year/{year:\d+}')
- config.add_route('vote_logo', r'/vote_logo/{num:\d+}')
-
- # HTML Routes - Staff
- config.add_route('Live', '/Live')
- config.add_route('list_expenses', r'/{year:\d+}/Staff/compta')
- config.add_route('list_task', r'/{year:\d+}/Staff')
- config.add_route('handle_pole', r'/{year:\d+}/Staff/poles{sep:/*}{pole_id:(\d+)?}')
- config.add_route('handle_task', r'/{year:\d+}/Staff/tasks{sep:/*}{task_id:(\d+)?}')
- config.add_route('action_task', r'/{year:\d+}/Staff/{action:(\w+)}/{task_id:(\d+)}')
- config.add_route('action_task_area', r'/{year:\d+}/Staff/pole/{action:(\w+)}/{pole_id:(\d+)}')
-
- config.add_route('list_salles', '/ListSalles')
- config.add_route('list_salles_phy', '/ListSallesPhy')
- config.add_route('handle_salle', r'/Salles{sep:/*}{salle_id:(\d+)?}')
- config.add_route('handle_salle_phy', r'/PhySalles{sep:/*}{salle_id:(\d+)?}')
- config.add_route('action_salle', r'/Salles/{action:(\w+)}/{salle_id:(\d+)}')
- config.add_route('pict_salle', r'/salle_picture/{salle_id:(\d+)}')
-
- config.add_route('list_users', r'/{year:\d+}/ListParticipant')
- config.add_route('list_users_csv', r'/{year:\d+}/ListParticipant.csv')
- config.add_route('list_orga', r'/{year:\d+}/ListOrga')
-
- # HTML Routes - Public
- config.add_route('home', r'/{year:(\d+/)?}')
- config.add_route('edit_index', r'/{year:\d+}/edit')
- config.add_route('presse', r'/{year:\d+}/dossier-de-presse')
- config.add_route('edit_presse', r'/{year:\d+}/dossier-de-presse/edit')
- config.add_route('programme', r'/{year:\d+}/le-programme')
- config.add_route('plan', 'nous-rejoindre')
- config.add_route('participer', 'participer-l-evenement')
- config.add_route('captcha', '/captcha')
-
- ## Events
- config.add_route('event', r'/event/{year:\d+}/{event_id:([\w-]+)?}')
- config.add_route('link_event_user', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_user')
- config.add_route('delete_link_u', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/delete_link_user')
- config.add_route('link_event_tiers', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_tiers')
- config.add_route('delete_link_t', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/delete_link_tiers')
- config.add_route('edit_event', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}{sep:/*}{event_id:([\w-]+)?}')
- config.add_route('delete_event', r'/MesJM2L/{year:\d+}/{intervention:[\s\w]+}{sep:/*}{event_id:([\w-]+)?}/delete')
-
- # Entities
- config.add_route('entities', '/entities') # {sep:/*}{Nature:\w+?}')
- config.add_route('add_entity', '/entity')
- config.add_route('delete_entity', r'/entity/{entity_id:(\d+)}/delete')
- config.add_route('show_entity', r'/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)?}')
- config.add_route('edit_entity', r'/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)}/edit')
- config.add_route('edit_entity_cat', '/categorie/entity')
-
- # Users
- config.add_route('pict_user', '/user_picture')
- config.add_route('show_user', r'/user/{user_slug:([\w-]+)?}')
- config.add_route('badge_user', r'/user/{user_slug:([\w-]+)?}/badge')
- config.add_route('all_badges', '/badges')
- config.add_route('place_print', '/place_print')
- config.add_route('stand_print', '/stand_print')
-
- # HTML Routes - Logged
- # config.add_route('profil', 'MesJM2L')
- config.add_route('jm2l', '/MesJM2L')
- config.add_route('drop_sejour', '/DropSejour')
- config.add_route('miam', '/MonMiam')
- config.add_route('sejour', '/MonSejour')
- config.add_route('orga', '/MonOrga')
- config.add_route('modal', r'/{year:\d+}/modal/{modtype:\w+}/{id:(\d+)}')
-
- # Handle exchanges
- config.add_route('exchange', r'/{year:\d+}/exchange/{modtype:\w+}/{id:(\d+)}/{action:\w+}')
-
- # Handle authentication
- config.add_route('register', '/register')
- config.add_route('auth', '/sign/{action}')
- config.add_route('bymail', '/sign/jm2l/{hash}')
-
- # Handle Multimedia and Uploads
- config.add_route('media_view', r'/image/{media_table:\w+}/{uid:\d+}/{name:.+}')
- config.add_route('media_upload', r'/uploader/{media_table:\w+}/{uid:\d+}/proceed{sep:/*}{name:.*}')
-
- config.scan()
- return config.make_wsgi_app()
|