Milimetric has submitted this change and it was merged.

Change subject: cohort upload fixes
......................................................................


cohort upload fixes

Change-Id: I5316e32476a105022d96d1ca36764618ca80b3b3
---
M tests/cohort_csvs/crazy_names.csv
M wikimetrics/controllers/cohorts.py
M wikimetrics/templates/index.html
3 files changed, 17 insertions(+), 18 deletions(-)

Approvals:
  Milimetric: Verified; Looks good to me, approved



diff --git a/tests/cohort_csvs/crazy_names.csv 
b/tests/cohort_csvs/crazy_names.csv
index bca2653..b7e1014 100644
--- a/tests/cohort_csvs/crazy_names.csv
+++ b/tests/cohort_csvs/crazy_names.csv
@@ -5,3 +5,4 @@
 Khalsa250,000,commonswiki
 Xudognik,,999,commonswiki
 André Costa (WMSE),commonswiki
+Agamitsudo,commonswiki
diff --git a/wikimetrics/controllers/cohorts.py 
b/wikimetrics/controllers/cohorts.py
index 83d99d6..b3a7b8c 100644
--- a/wikimetrics/controllers/cohorts.py
+++ b/wikimetrics/controllers/cohorts.py
@@ -154,7 +154,7 @@
                 description=description,
             )
         except Exception, e:
-            logging.exception(str(e))
+            app.logger.exception(str(e))
             flash(
                 'The file you uploaded was not in a valid format, could not be 
validated,'
                 'or the project you specified is not configured on this 
instance of Wiki Metrics.'
@@ -175,24 +175,21 @@
         if get_cohort_by_name(name):
             raise Exception('Cohort name {0} is already used'.format(name))
         
-        # TODO: re-enable validation when either
-        # 1. the site is used by external, potentially untrusted users
-        # 2. the performance of validation is improved
-        #(valid, invalid) = validate_records(users)
-        #if invalid:
-            #raise Exception('Cohort changed since last validation')
-        # save the cohort
+        # NOTE: Without re-validating here, the user might have changed the 
cohort client-side
+        # since the last validation.  This will produce weird results but we 
sort of don't care.
+        
+        # Save the cohort
         valid = users
         
         if not project:
             if all([user['project'] == users[0]['project'] for user in users]):
                 project = users[0]['project']
-        logging.debug('adding cohort: {0}, with project: {1}'.format(name, 
project))
+        app.logger.info('adding cohort: {0}, with project: {1}'.format(name, 
project))
         create_cohort(name, description, project, valid)
         return json_redirect(url_for('cohorts_index'))
         
     except Exception, e:
-        logging.exception(str(e))
+        app.logger.exception(str(e))
         flash('There was a problem finishing the upload.  The cohort was not 
saved.', 'error')
         return '<<error>>'
 
@@ -261,7 +258,7 @@
 def parse_records(records, default_project):
     # NOTE: the reason for the crazy -1 and comma joins
     # is that some users can have commas in their name
-    # TODO: This makes it impossible to add fields to the csv in the future,
+    # NOTE: This makes it impossible to add fields to the csv in the future,
     # so maybe require the project to be the first field and the username to 
be the last
     # or maybe change to a tsv format
     parsed = []
@@ -275,14 +272,15 @@
                 project = default_project
             
             parsed.append({
+                'raw_username': username,
                 'username': parse_username(username),
                 'project': project,
             })
     return parsed
 
 
-def parse_username(raw_name):
-    stripped = str(raw_name).decode('utf8').strip()
+def parse_username(raw_username):
+    stripped = str(raw_username).decode('utf8').strip()
     # unfortunately .title() or .capitalize() don't work
     # because 'miliMetric'.capitalize() == 'Milimetric'
     return stripped[0].upper() + stripped[1:]
@@ -376,16 +374,16 @@
             record['reason_invalid'] = 'invalid project: %s' % 
record['project']
             invalid.append(record)
             continue
-        normalized_user = normalize_user(record['user_str'], 
normalized_project)
+        normalized_user = normalize_user(record['raw_username'], 
normalized_project)
         # make a link to the potential user page even if user doesn't exist
         # this gives a chance to see any misspelling etc.
         if normalized_user is None:
-            logging.debug('invalid: %s', record['user_str'])
+            app.logger.info('invalid user: %s', record['user_str'])
             record['reason_invalid'] = 'invalid user_name / user_id: %s' % 
record['user_str']
             invalid.append(record)
             continue
         # set the normalized values and append to valid
-        logging.debug('found a valid user_str: %s', record['user_str'])
+        app.logger.info('found a valid user_str: %s', record['user_str'])
         record['project'] = normalized_project
         record['user_id'], record['username'] = normalized_user
         valid.append(record)
diff --git a/wikimetrics/templates/index.html b/wikimetrics/templates/index.html
index a0a2c01..a9527f6 100644
--- a/wikimetrics/templates/index.html
+++ b/wikimetrics/templates/index.html
@@ -8,11 +8,11 @@
         Welcome to the Wikimedia Foundation's Wikimetrics homepage.
         This API allows you to select a set of users, also known as a "cohort"
         <span class="muted">
-            (for example, <a href="{{url_for('cohort_detail', 
name_or_id='e3_donor_referral_thank_you_b')}}">all users who signed up via the 
Thank You campaign</a>)
+            (for example, <strong>all users who signed up via the Thank You 
campaign</strong>)
         </span>,
         select a metric to be computed for each of these users
         <span class="muted">
-            (for example, their <a href="{{ url_for('metrics_index') + 
'#RevertRate'}}">revert rate</a>)
+            (for example, how many <a href="{{ url_for('metrics_index') + 
'#BytesAdded'}}">bytes they've added</a>)
         </span>
         with optional parameters
         <span class="muted">

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5316e32476a105022d96d1ca36764618ca80b3b3
Gerrit-PatchSet: 1
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: Milimetric <[email protected]>
Gerrit-Reviewer: Milimetric <[email protected]>

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

Reply via email to