Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions flask_mongoengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ def _include_mongoengine(obj):
"""
# TODO why do we need this? What's wrong with importing from the
# original modules?
for module in (mongoengine, mongoengine.fields):
for attr_name in module.__all__:
if not hasattr(obj, attr_name):
setattr(obj, attr_name, getattr(module, attr_name))
for attr_name in mongoengine.__all__:
if not hasattr(obj, attr_name):
setattr(obj, attr_name, getattr(mongoengine, attr_name))

# patch BaseField if available
_patch_base_field(obj, attr_name)
# patch BaseField if available
_patch_base_field(obj, attr_name)


def current_mongoengine_instance():
Expand Down
17 changes: 8 additions & 9 deletions flask_mongoengine/sessions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import datetime
from datetime import timedelta, datetime
import uuid

from bson.tz_util import utc
Expand Down Expand Up @@ -49,12 +49,11 @@ class DBSession(db.Document):

self.cls = DBSession

def get_expiration_time(self, app, session):
def get_expiration_time(self, app, session) -> timedelta:
if session.permanent:
return app.permanent_session_lifetime
if "SESSION_TTL" in app.config:
return datetime.timedelta(**app.config["SESSION_TTL"])
return datetime.timedelta(days=1)
# Fallback to 1 day session ttl, if SESSION_TTL not set.
return timedelta(**app.config.get("SESSION_TTL", {"days": 1}))

def open_session(self, app, request):
sid = request.cookies.get(app.session_cookie_name)
Expand All @@ -67,7 +66,7 @@ def open_session(self, app, request):
if not expiration.tzinfo:
expiration = expiration.replace(tzinfo=utc)

if expiration > datetime.datetime.utcnow().replace(tzinfo=utc):
if expiration > datetime.utcnow().replace(tzinfo=utc):
return MongoEngineSession(
initial=stored_session.data, sid=stored_session.sid
)
Expand All @@ -85,9 +84,9 @@ def save_session(self, app, session, response):
response.delete_cookie(app.session_cookie_name, domain=domain)
return

expiration = datetime.datetime.utcnow().replace(
tzinfo=utc
) + self.get_expiration_time(app, session)
expiration = datetime.utcnow().replace(tzinfo=utc) + self.get_expiration_time(
app, session
)

if session.modified:
self.cls(sid=session.sid, data=session, expiration=expiration).save()
Expand Down
6 changes: 3 additions & 3 deletions flask_mongoengine/wtf/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def convert(self, model, field, field_args):
kwargs.update(field_args)

if kwargs["validators"]:
# Create a copy of the list since we will be modifying it.
# Create a copy of the list since we will be modifying it, and if
# validators set as shared list between fields - duplicates/conflicts may
# be created.
kwargs["validators"] = list(kwargs["validators"])

if field.required:
Expand All @@ -79,8 +81,6 @@ def convert(self, model, field, field_args):
return f.RadioField(**kwargs)
return f.SelectField(**kwargs)

ftype = type(field).__name__

if hasattr(field, "to_form_field"):
return field.to_form_field(model, kwargs)

Expand Down