def start_jobs_from_db():
    sql_config = get_sqlalchemy_config()
    app = Flask(__name__)
    app.config[SQL_URI_KEY] = sql_config[0]
    app.config[SQL_TRACK_KEY] = sql_config[1]
    with app.app_context():
        db.init_app(app)
        channels = db.session.query(Channel).all()
        for ch in channels:
            configure_job(ch.id, ch.archival_frequency, ch.archival_date)
Ejemplo n.º 2
0
def create_app(testing = False):
    app = Flask(__name__)
    app.config.from_json("config.json")

    # Register blueprints
    app.register_blueprint(authentication_page)
    app.register_blueprint(authorizations_page)
    app.register_blueprint(search_page)
    app.register_blueprint(channels_page)
    app.register_blueprint(posts_page)
    app.register_blueprint(pub_page)
    app.register_blueprint(feed_page)
    app.register_blueprint(archival_page)

    app.register_blueprint(delete_page)
    app.register_blueprint(facebook_plugin)
    print(app.config["SQLALCHEMY_DATABASE_URI"])

    if testing:
        app.config['TESTING'] = True
    # Init dbs
    db.init_app(app)

    # List available channels in config
    app.config["PLUGINS"] = {
        name: importlib.import_module(name)
        for finder, name, ispkg
        in pkgutil.iter_modules(superform.plugins.__path__, superform.plugins.__name__ + ".")
    }

    @app.route('/')
    def index():
        user = User.query.get(session.get("user_id", "")) if session.get("logged_in", False) else None
        posts = []
        flattened_list_pubs = []
        if user is not None:
            setattr(user, 'is_mod', is_moderator(user))
            posts = db.session.query(Post).filter(Post.user_id == session.get("user_id", ""))
            chans = get_moderate_channels_for_user(user)
            pubs_per_chan = (
            db.session.query(Publishing).filter((Publishing.channel_id == c.id) & (Publishing.state == 0)) for c in
            chans)
            flattened_list_pubs = [y for x in pubs_per_chan for y in x]

        return render_template("index.html", user=user, posts=posts, publishings=flattened_list_pubs)

    @app.errorhandler(403)
    def forbidden(error):
        return render_template('403.html'), 403

    @app.errorhandler(404)
    def notfound(error):
        return render_template('404.html'), 404
    return app
def db(app, request):
    """Session-wide test database."""
    if os.path.exists(TESTDB_PATH):
        os.unlink(TESTDB_PATH)

    def teardown():
        _db.drop_all()
        os.unlink(TESTDB_PATH)

    _db.init_app(app)
    _db.create_all()

    request.addfinalizer(teardown)
    return _db
def archival_job(ch_id):
    sql_config = get_sqlalchemy_config()
    app = Flask(__name__)
    app.config[SQL_URI_KEY] = sql_config[0]
    app.config[SQL_TRACK_KEY] = sql_config[1]
    with app.app_context():
        db.init_app(app)
        if ch_id == -1:
            toArchive = db.session.query(Publishing)\
                .filter(Publishing.date_until < datetime.now(), Publishing.state == 1)\
                .all()
        else:
            toArchive = db.session.query(Publishing) \
                .filter(Publishing.date_until < datetime.now(), Publishing.state == 1, Publishing.channel_id == ch_id) \
                .all()

        for pub in toArchive:
            pub.state = 2

        db.session.commit()
def download_records(ch_ids):
    sql_config = get_sqlalchemy_config()
    app = Flask(__name__)
    app.config[SQL_URI_KEY] = sql_config[0]
    app.config[SQL_TRACK_KEY] = sql_config[1]
    with app.app_context():
        db.init_app(app)

        if ch_ids is not None and len(ch_ids) > 0:
            channels_objects = db.session.query(Channel).filter(
                Channel.id.in_(ch_ids)).all()
            archived_p = db.session.query(Publishing).filter(
                Publishing.state == 2,
                Publishing.channel_id.in_(ch_ids)).all()
        elif ch_ids is None:
            channels_objects = db.session.query(Channel).all()
            archived_p = db.session.query(Publishing).filter(
                Publishing.state == 2).all()
        else:
            channels_objects = []
            archived_p = []

        records = []
        channels = []
        for p in archived_p:
            records.append(p.to_dict())
        for c in channels_objects:
            channels.append(c.to_dict())

        json_content = {'CHANNELS': channels, 'RECORDS': records}
        json_content = json.dumps(json_content,
                                  ensure_ascii=False,
                                  cls=DateTimeEncoder)

        return Response(json_content,
                        mimetype='application/json',
                        headers={
                            'Content-Disposition':
                            'attachment;filename=records.json'
                        })
Ejemplo n.º 6
0
app = Flask(__name__)
app.config.from_json("config.json")

# Register blueprints
app.register_blueprint(authentication_page)
app.register_blueprint(authorizations_page)
app.register_blueprint(channels_page)
app.register_blueprint(posts_page)
app.register_blueprint(pub_page)
app.register_blueprint(rss_explorer_page)
app.register_blueprint(stats_page)
app.register_blueprint(search_page)

# Init dbs
db.init_app(app)

# List available channels in config
app.config["PLUGINS"] = {
    name: importlib.import_module(name)
    for finder, name, ispkg in pkgutil.iter_modules(
        superform.plugins.__path__, superform.plugins.__name__ + ".")
}


@app.route('/', methods=['GET', 'POST'])
def index():
    # Team06: Export to PDF feature
    if request.method == "POST":
        action = request.form.get('@action', '')
        if action == "export":