Milimetric has submitted this change and it was merged.

Change subject: Move get_cohort_by_name() to CohortService
......................................................................


Move get_cohort_by_name() to CohortService

Move wikimetrics.controllers.cohorts.get_cohort_by_name() to
wikimetrics.api.cohorts.CohortService.

Change-Id: I3c0b89bf3a702e43bacc9884d2baaf608cea1e0b
---
M wikimetrics/api/cohorts.py
M wikimetrics/controllers/cohorts.py
2 files changed, 12 insertions(+), 10 deletions(-)

Approvals:
  Milimetric: Looks good to me, approved



diff --git a/wikimetrics/api/cohorts.py b/wikimetrics/api/cohorts.py
index bf360f2..e2522e2 100644
--- a/wikimetrics/api/cohorts.py
+++ b/wikimetrics/api/cohorts.py
@@ -71,6 +71,12 @@
         db_session = db.get_session()
         return db_session.query(CohortStore).get(cohort.id)
 
+    def get_cohort_by_name(self, db_session, name):
+        """
+        Gets a cohort by name, without worrying about access, ownership or 
duplicates.
+        """
+        return db_session.query(CohortStore).filter(CohortStore.name == 
name).first()
+
     def get(self, db_session, user_id, **kargs):
         """Same as _get but checks validity of the cohort"""
         cohort = self._get(db_session, user_id, **kargs)
diff --git a/wikimetrics/controllers/cohorts.py 
b/wikimetrics/controllers/cohorts.py
index 8906963..fadce3f 100644
--- a/wikimetrics/controllers/cohorts.py
+++ b/wikimetrics/controllers/cohorts.py
@@ -178,8 +178,11 @@
         try:
             if not form.validate():
                 flash('Please fix validation problems.', 'warning')
-            elif get_cohort_by_name(form.name.data):
+
+            # NOTE: The following two lines will be removed in validation 
refactor
+            elif g.cohort_service.get_cohort_by_name(db.get_session(), 
form.name.data):
                 flash('That Cohort name is already taken.', 'warning')
+
             else:
                 form.parse_records()
                 vc = ValidateCohort.from_upload(form, current_user.id)
@@ -199,18 +202,11 @@
     )
 
 
-def get_cohort_by_name(name):
-    """
-    Gets a cohort by name, without checking access or worrying about duplicates
-    """
-    db_session = db.get_session()
-    return db_session.query(CohortStore).filter(CohortStore.name == 
name).first()
-
-
 @app.route('/cohorts/validate/name')
 def validate_cohort_name_allowed():
     name = request.args.get('name')
-    available = get_cohort_by_name(name) is None
+    session = db.get_session()
+    available = g.cohort_service.get_cohort_by_name(session, name) is None
     return json.dumps(available)
 
 

-- 
To view, visit https://gerrit.wikimedia.org/r/154479
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3c0b89bf3a702e43bacc9884d2baaf608cea1e0b
Gerrit-PatchSet: 2
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Milimetric <[email protected]>
Gerrit-Reviewer: Ragesoss <[email protected]>
Gerrit-Reviewer: Swalling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to