當前位置: 首頁>>代碼示例>>Python>>正文


Python session.modified方法代碼示例

本文整理匯總了Python中flask.session.modified方法的典型用法代碼示例。如果您正苦於以下問題:Python session.modified方法的具體用法?Python session.modified怎麽用?Python session.modified使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask.session的用法示例。


在下文中一共展示了session.modified方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: before_request

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def before_request():
    # Check if user is anonymous
    g.user = current_user
    login_manager.anonymous_user = Anonymous

    # Check site is in maintenance mode
    maintenance = Setting().get('maintenance')
    if maintenance and current_user.is_authenticated and current_user.role.name not in [
            'Administrator', 'Operator'
    ]:
        return render_template('maintenance.html')

    # Manage session timeout
    session.permanent = True
    current_app.permanent_session_lifetime = datetime.timedelta(
        minutes=int(Setting().get('session_timeout')))
    session.modified = True 
開發者ID:ngoduykhanh,項目名稱:PowerDNS-Admin,代碼行數:19,代碼來源:dashboard.py

示例2: update_session

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def update_session(i, uid=None, encrypted=None, key_logged=None, chatstatus=None):
    if 'sessions' not in session:
        session['sessions'] = dict()
    if i not in session['sessions'] or uid is not None:
        if uid is None:
            raise Exception("update_session: cannot create new session without a uid")
        if encrypted is None:
            encrypted = True
        if key_logged is None:
            key_logged = False
        if chatstatus is None:
            chatstatus = 'off'
        session['sessions'][i] = dict(uid=uid, encrypted=encrypted, key_logged=key_logged, chatstatus=chatstatus)
    else:
        if uid is not None:
            session['sessions'][i]['uid'] = uid
        if encrypted is not None:
            session['sessions'][i]['encrypted'] = encrypted
        if key_logged is not None:
            session['sessions'][i]['key_logged'] = key_logged
        if chatstatus is not None:
            session['sessions'][i]['chatstatus'] = chatstatus
    session.modified = True
    return session['sessions'][i] 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:26,代碼來源:backend.py

示例3: set_locale

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def set_locale():
    locale = request.json.get('locale')

    if locale is not None:
        session['locale'] = locale
        session.modified = True
    return jsonify({'locale': locale}) 
開發者ID:openspending,項目名稱:spendb,代碼行數:9,代碼來源:home.py

示例4: set_cache_headers

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def set_cache_headers(f):
    """
    Returns HTTP headers suitable for caching.
    """

    @wraps(f)
    def wrapper(*args, **kwargs):
        # Set TTL to 1 year by default
        ttl = 31536000
        expires = datetime.fromtimestamp(int(time()) + ttl)
        expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
        headers = {
            "Cache-Control": "public, max-age={0}".format(ttl),
            "Expires": expires,
            "Last-Modified": "Thu, 01 Jan 1970 00:00:00 GMT",
        }
        if "If-Modified-Since" in request.headers:
            response = make_response("Not modified", 304)
            response.headers.extend(headers)
            return response
        kwargs["headers"] = headers
        # Prevent the Cookie to be sent when the object is cacheable
        session.modified = False
        return f(*args, **kwargs)

    return wrapper 
開發者ID:quay,項目名稱:quay,代碼行數:28,代碼來源:registry.py

示例5: _persist_data

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def _persist_data(**kwargs):
    """Save data in session."""
    if _session_key not in session:
        session[_session_key] = dict()
    session[_session_key].update(**kwargs)
    session.modified = True 
開發者ID:metabrainz,項目名稱:listenbrainz-server,代碼行數:8,代碼來源:provider.py

示例6: signin

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def signin():
    json = request.get_json()
    if "username" not in json or "password" not in json:
        raise InvalidUsage("Must supply username or password.")
    user = User.query.filter(User.username == json["username"]).first()
    if user is not None:
        current_app.logger.debug(
            "Login attempt", username=user.username, user_id=user.id
        )
        if user.is_correct_password(json["password"]):
            two_factor = user.two_factor_auth
            if two_factor is not None and two_factor.enabled:
                if "two_factor_code" not in json or json["two_factor_code"] == "":
                    raise InvalidUsage(
                        "Must supply a two-factor authentication code.",
                        payload={"need_two_factor": True},
                    )
                try:
                    two_factor.validate(json["two_factor_code"])
                except (Unauthorized, binascii.Error):
                    two_factor.validate_backup_code(json["two_factor_code"])
            login_user(user, remember=False)
            identity_changed.send(
                current_app._get_current_object(), identity=Identity(user.id)
            )
            session.modified = True
            return jsonify(
                {
                    "logged_in": True,
                    "is_admin": user.is_admin,
                    "require_two_factor_setup": current_user.two_factor_setup_required,
                }
            )
    current_app.logger.debug("Failed login attempt", username=json["username"])
    raise Unauthorized("Incorrect username or password.") 
開發者ID:Flowminder,項目名稱:FlowKit,代碼行數:37,代碼來源:login.py

示例7: signout

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def signout():
    logout_user()
    for key in ("identity.name", "identity.auth_type"):
        session.pop(key, None)
    session.modified = True
    # Tell Flask-Principal the user is anonymous
    identity_changed.send(
        current_app._get_current_object(), identity=AnonymousIdentity()
    )
    return jsonify({"logged_in": False}) 
開發者ID:Flowminder,項目名稱:FlowKit,代碼行數:12,代碼來源:login.py

示例8: before_request

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def before_request():
    # Manage session timeout
    session.permanent = True
    current_app.permanent_session_lifetime = datetime.timedelta(
        minutes=int(Setting().get('session_timeout')))
    session.modified = True 
開發者ID:ngoduykhanh,項目名稱:PowerDNS-Admin,代碼行數:8,代碼來源:admin.py

示例9: configure_app

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def configure_app(app, config_object):
    """General application configuration:

    - register the app's config
    - register Jinja extensions
    - register functions to run on before/after request
    """
    # automatically configure a migrations folder for each bundle
    config_object.ALEMBIC['version_locations'] = [
        (bundle._name, os.path.join(PROJECT_ROOT,
                                    bundle.module_name.replace('.', os.sep),
                                    'migrations'))
        for bundle in app.bundles if bundle.has_models
    ]
    app.config.from_object(config_object)

    app.jinja_env.add_extension('jinja2_time.TimeExtension')

    @app.before_request
    def enable_session_timeout():
        session.permanent = True  # set session to use PERMANENT_SESSION_LIFETIME
        session.modified = True   # reset the session timer on every request

    @app.after_request
    def set_csrf_cookie(response):
        if response:
            response.set_cookie('csrf_token', generate_csrf())
        return response 
開發者ID:briancappello,項目名稱:flask-react-spa,代碼行數:30,代碼來源:app.py

示例10: _add_to_compare_basket

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def _add_to_compare_basket(self, uid):
        compare_uid_list = get_comparison_uid_list_from_session()
        compare_uid_list.append(uid)
        session.modified = True
        return redirect(url_for('analysis/<uid>', uid=uid)) 
開發者ID:fkie-cad,項目名稱:FACT_core,代碼行數:7,代碼來源:compare_routes.py

示例11: _remove_from_compare_basket

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def _remove_from_compare_basket(self, analysis_uid, compare_uid):
        compare_uid_list = get_comparison_uid_list_from_session()
        if compare_uid in compare_uid_list:
            session['uids_for_comparison'].remove(compare_uid)
            session.modified = True
        return redirect(url_for('analysis/<uid>', uid=analysis_uid)) 
開發者ID:fkie-cad,項目名稱:FACT_core,代碼行數:8,代碼來源:compare_routes.py

示例12: _remove_all_from_compare_basket

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def _remove_all_from_compare_basket(self, analysis_uid):
        compare_uid_list = get_comparison_uid_list_from_session()
        compare_uid_list.clear()
        session.modified = True
        return redirect(url_for('analysis/<uid>', uid=analysis_uid)) 
開發者ID:fkie-cad,項目名稱:FACT_core,代碼行數:7,代碼來源:compare_routes.py

示例13: test_remove_from_compare_basket

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def test_remove_from_compare_basket(self):
        with self.frontend.app.test_request_context():
            session['uids_for_comparison'] = [TEST_FW.uid, TEST_FW_2.uid]
            session.modified = True
            assert 'uids_for_comparison' in session
            assert TEST_FW.uid in session['uids_for_comparison']
            assert TEST_FW_2.uid in session['uids_for_comparison']

            CompareRoutes._remove_from_compare_basket(self.frontend, 'some_uid', TEST_FW.uid)
            assert TEST_FW.uid not in session['uids_for_comparison']
            assert TEST_FW_2.uid in session['uids_for_comparison'] 
開發者ID:fkie-cad,項目名稱:FACT_core,代碼行數:13,代碼來源:test_app_compare.py

示例14: test_remove_all_from_compare_basket

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def test_remove_all_from_compare_basket(self):
        with self.frontend.app.test_request_context():
            session['uids_for_comparison'] = [TEST_FW.uid, TEST_FW_2.uid]
            session.modified = True
            assert 'uids_for_comparison' in session
            assert TEST_FW.uid in session['uids_for_comparison']
            assert TEST_FW_2.uid in session['uids_for_comparison']

            CompareRoutes._remove_all_from_compare_basket(self.frontend, 'some_uid')
            assert TEST_FW.uid not in session['uids_for_comparison']
            assert TEST_FW_2.uid not in session['uids_for_comparison'] 
開發者ID:fkie-cad,項目名稱:FACT_core,代碼行數:13,代碼來源:test_app_compare.py

示例15: fetch

# 需要導入模塊: from flask import session [as 別名]
# 或者: from flask.session import modified [as 別名]
def fetch():
    guild_id = request.args.get("guild_id")
    channel_id = request.args.get('channel_id')
    after_snowflake = request.args.get('after', 0, type=int)
    if user_unauthenticated():
        key = session['user_keys'][guild_id]
    else:
        key = None
    status = update_user_status(guild_id, session['username'], key)
    messages = {}
    if status['banned'] or status['revoked']:
        status_code = 403
        if user_unauthenticated():
            session['user_keys'].pop(guild_id, None)
            session.modified = True
    else:
        chan = filter_guild_channel(guild_id, channel_id)
        if not chan:
            abort(404)
        if not chan.get("read") or chan["channel"]["type"] != "text":
            status_code = 401
        else:
            messages = redisqueue.get_channel_messages(guild_id, channel_id, after_snowflake)
            status_code = 200
    response = jsonify(messages=messages, status=status)
    response.status_code = status_code
    return response 
開發者ID:TitanEmbeds,項目名稱:Titan,代碼行數:29,代碼來源:api.py


注:本文中的flask.session.modified方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。