Skip to content

Commit

Permalink
Merge pull request #152 from Garito/master
Browse files Browse the repository at this point in the history
Allow to configure the session TTL
  • Loading branch information
losintikfos committed Jan 9, 2016
2 parents 152013e + 6d17618 commit 92d7c74
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ that much better:
* Peter D. Gray
* Massimo Santini
* Len Buckens - https://github.com/buckensl
* Garito - https://github.com/garito
2 changes: 2 additions & 0 deletions flask_mongoengine/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class DBSession(db.Document):
def get_expiration_time(self, app, session):
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)

def open_session(self, app, request):
Expand Down
2 changes: 2 additions & 0 deletions flask_mongoengine/wtf/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def convert(self, model, field, field_args):
kwargs["coerce"] = self.coerce(ftype)
if kwargs.pop('multiple', False):
return f.SelectMultipleField(**kwargs)
if kwargs.pop('radio', False):
return f.RadioField(**kwargs)
return f.SelectField(**kwargs)

ftype = type(field).__name__
Expand Down
17 changes: 17 additions & 0 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,23 @@ class DogOwner(db.Document):
self.assertEqual(len(choices), 2)
self.assertFalse(choices[0].checked)
self.assertFalse(choices[1].checked)

def test_modelradiofield(self):
with self.app.test_request_context('/'):
db = self.db

choices = (('male', 'Male'), ('female', 'Female'), ('other', 'Other'))

class Poll(db.Document):
answer = db.StringField(choices=choices)

PollForm = model_form(Poll, field_args={'answer': {'radio': True}})

form = PollForm(answer=None)
self.assertTrue(form.validate())

self.assertEqual(form.answer.type, 'RadioField')
self.assertEqual(form.answer.choices, choices)

def test_passwordfield(self):
with self.app.test_request_context('/'):
Expand Down

0 comments on commit 92d7c74

Please sign in to comment.