Пример #1
0
 def setUp(self):
     self.app = create_app(TestConfig)
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
Пример #2
0
import sys
import time
import json
from flask import render_template
from rq import get_current_job
from blog_app import create_app
from blog_app.models import Task, User, Post
from blog_app import db
from blog_app.email import send_mail

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)
        _set_task_progress(0)
Пример #3
0
def main():
    app = create_app()
    app.run(debug=True)
Пример #4
0
 def setUp(self):  # 测试前执行
     self.app = create_app(TestConfig)
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()  # 因为设置了上下文,db能够用current_app.config来获取设置
Пример #5
0
import os
import click
from flask_migrate import Migrate
from blog_app.models import Members, Post, Admins
from blog_app import db, create_app

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
migrate = Migrate(app, db)


#Shell context processor function for database
@app.shell_context_processor
def make_shell_context():
    return dict(db=db, Members=Members, Post=Post, Admins=Admins)