Skip to content

Commit 92d7c74

Browse files
committed
Merge pull request #152 from Garito/master
Allow to configure the session TTL
2 parents 152013e + 6d17618 commit 92d7c74

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ that much better:
2727
* Peter D. Gray
2828
* Massimo Santini
2929
* Len Buckens - https://github.com/buckensl
30+
* Garito - https://github.com/garito

flask_mongoengine/sessions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class DBSession(db.Document):
5252
def get_expiration_time(self, app, session):
5353
if session.permanent:
5454
return app.permanent_session_lifetime
55+
if 'SESSION_TTL' in app.config:
56+
return datetime.timedelta(**app.config['SESSION_TTL'])
5557
return datetime.timedelta(days=1)
5658

5759
def open_session(self, app, request):

flask_mongoengine/wtf/orm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def convert(self, model, field, field_args):
7272
kwargs["coerce"] = self.coerce(ftype)
7373
if kwargs.pop('multiple', False):
7474
return f.SelectMultipleField(**kwargs)
75+
if kwargs.pop('radio', False):
76+
return f.RadioField(**kwargs)
7577
return f.SelectField(**kwargs)
7678

7779
ftype = type(field).__name__

tests/test_forms.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,23 @@ class DogOwner(db.Document):
287287
self.assertEqual(len(choices), 2)
288288
self.assertFalse(choices[0].checked)
289289
self.assertFalse(choices[1].checked)
290+
291+
def test_modelradiofield(self):
292+
with self.app.test_request_context('/'):
293+
db = self.db
294+
295+
choices = (('male', 'Male'), ('female', 'Female'), ('other', 'Other'))
296+
297+
class Poll(db.Document):
298+
answer = db.StringField(choices=choices)
299+
300+
PollForm = model_form(Poll, field_args={'answer': {'radio': True}})
301+
302+
form = PollForm(answer=None)
303+
self.assertTrue(form.validate())
304+
305+
self.assertEqual(form.answer.type, 'RadioField')
306+
self.assertEqual(form.answer.choices, choices)
290307

291308
def test_passwordfield(self):
292309
with self.app.test_request_context('/'):

0 commit comments

Comments
 (0)