try: feed = FeedController(current_user.id).get(id=data["feed_id"]) except NotFound: raise ProcessingException(description='No such feed.', code=404) self.is_authorized(current_user, feed) data["category_id"] = feed.category_id def delete_preprocessor(self, instance_id=None, **kw): try: article = ArticleController(current_user.id).get(id=instance_id) except NotFound: raise ProcessingException(description='No such article.', code=404) self.is_authorized(current_user, article) article_processor = ArticleProcessor() blueprint_article = manager.create_api_blueprint( models.Article, url_prefix=url_prefix, methods=['GET', 'POST', 'PUT', 'DELETE'], preprocessors=dict( GET_SINGLE=[auth_func, article_processor.get_single_preprocessor], GET_MANY=[auth_func, article_processor.get_many_preprocessor], POST=[auth_func, article_processor.post_preprocessor], PUT_SINGLE=[auth_func, article_processor.put_single_preprocessor], PUT_MANY=[auth_func, article_processor.put_many_preprocessor], DELETE=[auth_func, article_processor.delete_preprocessor])) application.register_blueprint(blueprint_article)
raise ProcessingException(description='No such feed.', code=404) self.is_authorized(current_user, feed) data["category_id"] = feed.category_id def delete_preprocessor(self, instance_id=None, **kw): try: article = ArticleController(current_user.id).get(id=instance_id) except NotFound: raise ProcessingException(description='No such article.', code=404) self.is_authorized(current_user, article) article_processor = ArticleProcessor() blueprint_article = manager.create_api_blueprint(models.Article, url_prefix=url_prefix, methods=['GET', 'POST', 'PUT', 'DELETE'], preprocessors=dict(GET_SINGLE=[auth_func, article_processor.get_single_preprocessor], GET_MANY=[auth_func, article_processor.get_many_preprocessor], POST=[auth_func, article_processor.post_preprocessor], PUT_SINGLE=[auth_func, article_processor.put_single_preprocessor], PUT_MANY=[auth_func, article_processor.put_many_preprocessor], DELETE=[auth_func, article_processor.delete_preprocessor])) application.register_blueprint(blueprint_article)
@babel.timezoneselector def get_timezone(): try: return conf.TIME_ZONE[get_locale()] except: return conf.TIME_ZONE["en"] # Jinja filters application.jinja_env.filters['month_name'] = lambda n: calendar.month_name[n] application.jinja_env.globals['conf'] = conf # Views with application.app_context(): from web import views application.register_blueprint(views.articles_bp) application.register_blueprint(views.article_bp) application.register_blueprint(views.feeds_bp) application.register_blueprint(views.feed_bp) application.register_blueprint(views.categories_bp) application.register_blueprint(views.category_bp) application.register_blueprint(views.icon_bp) application.register_blueprint(views.admin_bp) application.register_blueprint(views.users_bp) application.register_blueprint(views.user_bp) if __name__ == '__main__': # pragma: no cover application.run(host=conf.WEBSERVER_HOST, port=conf.WEBSERVER_PORT, debug=True)
application.jinja_env.filters['month_name'] = month_name application.jinja_env.filters['datetime'] = format_datetime application.jinja_env.globals['conf'] = conf # Views from flask_restful import Api from flask import g with application.app_context(): populate_g() g.api = Api(application, prefix='/api/v2.0') g.babel = babel from web import views application.register_blueprint(views.articles_bp) application.register_blueprint(views.article_bp) application.register_blueprint(views.feeds_bp) application.register_blueprint(views.feed_bp) application.register_blueprint(views.categories_bp) application.register_blueprint(views.category_bp) application.register_blueprint(views.icon_bp) application.register_blueprint(views.admin_bp) application.register_blueprint(views.users_bp) application.register_blueprint(views.user_bp) application.register_blueprint(views.bookmarks_bp) application.register_blueprint(views.bookmark_bp) if __name__ == '__main__': application.run(host=conf.WEBSERVER_HOST, port=conf.WEBSERVER_PORT,
#! /usr/bin/env python # -*- coding: utf-8 -*- from bootstrap import application, populate_g with application.app_context(): populate_g() from web import views # API v1 application.register_blueprint(views.api.v1.api_bp) if __name__ == '__main__': application.run(host=application.config['HOST'], port=application.config['PORT'])
from flask_login import current_user from web import models from bootstrap import application, manager from web.controllers import FeedController from web.views.api.v3.common import AbstractProcessor from web.views.api.v3.common import url_prefix, auth_func class FeedProcessor(AbstractProcessor): """Concrete processors for the Feed Web service. """ def get_single_preprocessor(self, instance_id=None, **kw): # Check if the user is authorized to modify the specified # instance of the model. feed = FeedController(current_user.id).get(id=instance_id) self.is_authorized(current_user, feed) feed_processor = FeedProcessor() blueprint_feed = manager.create_api_blueprint(models.Feed, url_prefix=url_prefix, methods=['GET', 'POST', 'PUT', 'DELETE'], preprocessors=dict(GET_SINGLE=[auth_func, feed_processor.get_single_preprocessor], GET_MANY=[auth_func, feed_processor.get_many_preprocessor], PUT_SINGLE=[auth_func], POST=[auth_func], DELETE=[auth_func])) application.register_blueprint(blueprint_feed)
#! /usr/bin/env python # -*- coding: utf-8 -*- from bootstrap import application, populate_g with application.app_context(): populate_g() from web import views application.register_blueprint(views.admin_bp) application.register_blueprint(views.users_bp) application.register_blueprint(views.user_bp) application.register_blueprint(views.project_bp) application.register_blueprint(views.projects_bp) application.register_blueprint(views.organization_bp) application.register_blueprint(views.organizations_bp) application.register_blueprint(views.service_bp) application.register_blueprint(views.services_bp) # API v1 application.register_blueprint(views.api.v1.blueprint_organization) application.register_blueprint(views.api.v1.blueprint_project) application.register_blueprint(views.api.v1.blueprint_tag) application.register_blueprint(views.api.v1.blueprint_user) application.register_blueprint(views.api.v1.blueprint_release) application.register_blueprint(views.api.v1.blueprint_cve) application.register_blueprint(views.api.v1.blueprint_request) if __name__ == '__main__': application.run(host=application.config['HOST'],
from web import models from bootstrap import application, manager from web.controllers import FeedController from web.views.api.v3.common import AbstractProcessor from web.views.api.v3.common import url_prefix, auth_func class FeedProcessor(AbstractProcessor): """Concrete processors for the Feed Web service. """ def get_single_preprocessor(self, instance_id=None, **kw): # Check if the user is authorized to modify the specified # instance of the model. feed = FeedController(current_user.id).get(id=instance_id) self.is_authorized(current_user, feed) feed_processor = FeedProcessor() blueprint_feed = manager.create_api_blueprint( models.Feed, url_prefix=url_prefix, methods=['GET', 'POST', 'PUT', 'DELETE'], preprocessors=dict( GET_SINGLE=[auth_func, feed_processor.get_single_preprocessor], GET_MANY=[auth_func, feed_processor.get_many_preprocessor], PUT_SINGLE=[auth_func], POST=[auth_func], DELETE=[auth_func])) application.register_blueprint(blueprint_feed)
#! /usr/bin/env python # -*- coding: utf-8 -*- from bootstrap import application, populate_g with application.app_context(): populate_g() from web import views application.register_blueprint(views.admin_bp) application.register_blueprint(views.user_bp) application.register_blueprint(views.stats_bp) # API v1 application.register_blueprint(views.api.v1.blueprint_log) if __name__ == '__main__': application.run(host=application.config['HOST'], port=application.config['PORT'])