def setUp(self): self.app = create_app(TestConfig) self.app_context = self.app.app_context() # Flask uses two context: # (1) application context (current_app, g) # (2) request context (request, session as well as Flask-Login's current_user) # It is activated right before a request is handled. self.app_context.push( ) # push 'app_context' - brings 'current app' and 'g' to life. # When the 'request' is complete, the 'context' is removed, # along with these variables. db.create_all() # Creates all the database tables.
import json import sys import time from flask import render_template from rq import get_current_job from microblog import create_app, db from microblog.models import User, Post, Task from microblog.email import send_email app = create_app() app.app_context().push() def _set_task_progress(progress): job = get_current_job() if job: job.meta['progress'] = progress job.save_meta() task = Task.query.get(job.get_id()) task.user.add_notification('task_progress', { 'task_id': job.get_id(), 'progress': progress }) if progress >= 100: task.complete = True db.session.commit() def export_posts(user_id): try: user = User.query.get(user_id)
# -*- coding: utf-8 -*- from __future__ import unicode_literals import subprocess import datetime import shutil import os from zipfile import ZipFile from flask.ext.script import Manager, Server from flask.ext.migrate import MigrateCommand from microblog import create_app, config from microblog.extensions import db app = create_app(config.LocalDevelopmentConfig) manager = Manager(app) manager.add_command('db', MigrateCommand) # manager.add_command('debug', Server(host='127.0.0.1', port=8080, debug=True)) @manager.command def debug(): """Start Server in debug mode""" app.run(host='0.0.0.0', port=5000, debug=True, processes=3) @manager.command def init(): # 创建数据库 create_db_sql = 'CREATE DATABASE IF NOT EXISTS {0} DEFAULT CHARACTER SET utf8'.format(
def setUp(self): self.app = create_app(TestConfig) self.app_context = self.app.app_context() self.app_context.push() db.create_all()
# -*- coding: utf-8 -*- from __future__ import unicode_literals import subprocess import datetime import shutil import os from zipfile import ZipFile from flask.ext.script import Manager, Server from flask.ext.migrate import MigrateCommand from microblog import create_app, config from microblog.extensions import db app = create_app(config.LocalDevelopmentConfig) manager = Manager(app) manager.add_command('db', MigrateCommand) # manager.add_command('debug', Server(host='127.0.0.1', port=8080, debug=True)) @manager.command def debug(): """Start Server in debug mode""" app.run(host='0.0.0.0', port=5000, debug=True, processes=3) @manager.command def init(): # 创建数据库 create_db_sql = 'CREATE DATABASE IF NOT EXISTS {0} DEFAULT CHARACTER SET utf8'.format(config.Config.DB_DATABASE)