def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``static_files`` Whether this application serves its own static files; disable when another web server is responsible for serving them. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app, [400, 401, 403, 404, 410]) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 410, 500]) # Establish the Registry for this application app = RegistryManager(app) if asbool(static_files): # Serve static files static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) return app
def setup_app(command, conf, vars): """Place any commands to setup ordermanager here""" load_environment(conf.global_conf, conf.local_conf) # Create the tables if they don't already exist log.info(u"Удаление и создание таблиц...") meta.metadata.drop_all(bind=meta.engine) meta.metadata.create_all(bind=meta.engine) # Create initial configuration div = meta.Session.query(model.Division).get(1) if not div: log.info(u"Создание администрирующего подразделения...") div = model.Division() div.id = 1 div.title = u'Администраторская' meta.Session.add(div) meta.Session.commit() admin = meta.Session.query(model.Person).get(1) creating = not bool(admin) if creating: log.info(u"Добавление пользователя-администратора...") admin = model.Person() admin.id = 1 admin.name = u'Администратор' admin.surname = u'Администратор' admin.patronymic = u'Администратор' else: log.info(u"Исправление пользователя-администратора...") admin.login = u'admin' admin.password = md5(u"Random!").hexdigest() admin.div_id = 1 admin.admin = True admin.chief = True admin.responsible = True if creating: meta.Session.add(admin) meta.Session.commit() log.info(u"Логин администратора: %s ; пароль: %s ;" % (admin.login, u"Random!") ) log.info(u"Создание типов (надкатегорий)...") upcats = [ [1, u"IT", u"it"], [2, u"Электрика", u"electrics"] ] for u in upcats: uc = model.UpperCategory() uc.id, uc.title, uc.url_text = u meta.Session.add(uc) meta.Session.commit() log.info(u"Создание категорий работ...") categories = [ # id, title, url_text, upper_category [1, u"Не знаю - ничего не работает!", u"unknown", None], [2, u"Операционная система", u"os", 1 ], [3, u"Офисные программы", u"officesoft", 1 ], [4, u"Антивирус", u"antivirus", 1 ], [5, u"Вирусы", u"virus", 1 ], [6, u"Другое программное обеспечение", u"othersoft", 1 ], [7, u"Системный блок", u"systemunit", 1 ], [8, u"Монитор", u"monitor", 1 ], [9, u"Клавиатура и мышь", u"inputdevices", 1 ], [10, u"Принтер/сканер и др. периферия", u"peripherals", 1 ], [11, u"Ксерокс (копир)", u"copier", 1 ], [12, u"Картридж", u"cartridge", 1 ], [13, u"Веб-сайт АмГУ", u"website", 1 ], [14, u"Сеть, Почта, Интернет", u"networking", 1 ], [15, u"Телефон", u"phone", 1 ], [16, u"Другое", u"other", None], [17, u"Диспетчер заявок", u"ordermanager", 1 ], [18, u"Проводка (также щиты, розетки)", u"wiring", 2 ], [19, u"Лампы, освещение", u"lamps", 2 ], [20, u"Электрооборудование", u"electricsystems", 2 ] ] for category in categories: cat = model.Category() cat.id, cat.title, cat.url_text, cat.upcat_id = category meta.Session.add(cat) meta.Session.commit() log.info(u"Создание видов работ...") works = [ [u"Неисправность", u"repair" ], [u"Настройка", u"customize" ], [u"Установка", u"install" ], [u"Приобретение (нужна служебка)", u"purchase" ], [u"Дефектовать", u"defect" ], [u"Информация", u"inform" ], [u"Другая работа", u"other" ] ] for i,item in enumerate(works): work = model.Work() work.id = i+1 work.title, work.url_text = item meta.Session.add(work) meta.Session.commit() log.info(u"Создание статусов...") slist = [ [1, u"Заявка свободна", 1, None], [2, u"Принято", 2, None], [3, u"Заявлено о выполнении", 3, 1], [4, u"Выполнено", 4, None], [5, u"Отказано", 1, 30], [6, u"Подана претензия", 6, None], [7, u"Передано другому исполнителю", 2, 10], [8, u"Ожидание заказчика", 8, 20], [9, u"Ожидание отдела закупок", 9, 21], [10,u"Ожидание ремонта по гарантии", 10, 22], [11,u"Заявка создана", 1, None], [12,u"Заявка создана оператором", 1, None], [13,u"Ожидание ремонта в сервисном центре", 13, 23], [15,u"Заявка отозвана", 15, None], [16,u"Пояснение", None, 5] ] for item in slist: status = model.Status() status.id = item[0] status.title = item[1] status.redirects = item[2] status.gui_priority = item[3] meta.Session.add(status) meta.Session.commit() log.info(u"Успешно установлено.")