Milimetric has uploaded a new change for review.
https://gerrit.wikimedia.org/r/93081
Change subject: Bringing the UI up to speed with async validation
......................................................................
Bringing the UI up to speed with async validation
Change-Id: Ia9a27ded971b632531b03d63b91ba65a1a17b29b
Card: analytics 1245
Card: analytics 1246
---
A wikimetrics/controllers/forms/__init__.py
A wikimetrics/controllers/forms/secure_form.py
M wikimetrics/metrics/metric.py
3 files changed, 33 insertions(+), 24 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics
refs/changes/81/93081/1
diff --git a/wikimetrics/controllers/forms/__init__.py
b/wikimetrics/controllers/forms/__init__.py
new file mode 100644
index 0000000..45b08b4
--- /dev/null
+++ b/wikimetrics/controllers/forms/__init__.py
@@ -0,0 +1,5 @@
+from secure_form import *
+
+# ignore flake8 because of F403 violation
+# flake8: noqa
+
diff --git a/wikimetrics/controllers/forms/secure_form.py
b/wikimetrics/controllers/forms/secure_form.py
new file mode 100644
index 0000000..3367d1f
--- /dev/null
+++ b/wikimetrics/controllers/forms/secure_form.py
@@ -0,0 +1,26 @@
+from wikimetrics.configurables import app
+from wtforms.ext.csrf.session import SessionSecureForm
+
+
+class WikimetricsSecureForm(SessionSecureForm):
+ """
+ WTForms' SessionSecureform initialized for wikimetrics usage
+ """
+
+ def __init__(self, *args, **kwargs):
+ """
+ Initialize the things required by SessionSecureForm to do its duty
+ This __init__ handles the problem with calling
SessionSecureForm.__init__()
+ outside of a flask request context.
+ """
+ self.SECRET_KEY = 'not really secret, this will only happen in a
testing context'
+ csrf_context = {}
+
+ if app:
+ # TODO: need to set csrf_context to something? (the flask session
maybe?)
+ self.SECRET_KEY = app.config['SECRET_KEY']
+
+ SessionSecureForm.__init__(self, csrf_context=csrf_context, *args,
**kwargs)
+
+ def fake_csrf(self):
+ self.csrf_token.data = self.generate_csrf_token({})
diff --git a/wikimetrics/metrics/metric.py b/wikimetrics/metrics/metric.py
index 5d4aa6a..f3a9648 100644
--- a/wikimetrics/metrics/metric.py
+++ b/wikimetrics/metrics/metric.py
@@ -1,11 +1,7 @@
-from wtforms.ext.csrf.session import SessionSecureForm
-from wikimetrics.configurables import app
+from wikimetrics.controllers.forms.secure_form import WikimetricsSecureForm
-__all__ = ['Metric']
-
-
-class Metric(SessionSecureForm):
+class Metric(WikimetricsSecureForm):
"""
This class is the parent of all Metric implementations.
Child implementations should be callable and should take in users
@@ -34,21 +30,3 @@
dictionary from user ids to the metric results.
"""
return {user: None for user in user_ids}
-
- def __init__(self, *args, **kwargs):
- """
- Initialize the things required by SessionSecureForm to do its duty
- This __init__ handles the problem with calling
SessionSecureForm.__init__()
- outside of a flask request context.
- """
- self.SECRET_KEY = 'not really secret, this will only happen in a
testing context'
- csrf_context = {}
-
- if app:
- # TODO: need to set csrf_context to something? (the flask session
maybe?)
- self.SECRET_KEY = app.config['SECRET_KEY']
-
- SessionSecureForm.__init__(self, csrf_context=csrf_context, *args,
**kwargs)
-
- def fake_csrf(self):
- self.csrf_token.data = self.generate_csrf_token({})
--
To view, visit https://gerrit.wikimedia.org/r/93081
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia9a27ded971b632531b03d63b91ba65a1a17b29b
Gerrit-PatchSet: 1
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: Milimetric <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits