Milimetric has uploaded a new change for review.
https://gerrit.wikimedia.org/r/62165
Change subject: exception fix
......................................................................
exception fix
Change-Id: Ifb4950d16e90285bf935da5e38bf834e45c062de
---
A user_metrics/api/static/css/site.css
M user_metrics/api/templates/csv_upload.html
M user_metrics/api/templates/csv_upload_form.html
M user_metrics/api/templates/layout.html
M user_metrics/api/views.py
5 files changed, 43 insertions(+), 33 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/analytics/user-metrics
refs/changes/65/62165/1
diff --git a/user_metrics/api/static/css/site.css
b/user_metrics/api/static/css/site.css
new file mode 100644
index 0000000..061d81f
--- /dev/null
+++ b/user_metrics/api/static/css/site.css
@@ -0,0 +1,6 @@
+body { padding-top: 60px; padding-bottom: 60px; }
+.nav { width: 70%; }
+.nav li:last-child { color: #cacaca; float: right !important; }
+.nav li:last-child a { color: #0088cc; display: inline-block; }
+label.error { color: #af3333; }
+div.flash { margin: 4px 0 20px 0; }
diff --git a/user_metrics/api/templates/csv_upload.html
b/user_metrics/api/templates/csv_upload.html
index ab487e6..10c4ffe 100644
--- a/user_metrics/api/templates/csv_upload.html
+++ b/user_metrics/api/templates/csv_upload.html
@@ -3,7 +3,7 @@
{% include "csv_upload_form.html" %}
<div>
<h6>File Format</h6>
- <p>User Metrics expects a CSV file with the following format </p>
+ <p>User Metrics expects a CSV file with the following format (the
username, project header row is not required)</p>
<pre><code>username,project
Evan (WMF),en</code></pre>
<ul>
diff --git a/user_metrics/api/templates/csv_upload_form.html
b/user_metrics/api/templates/csv_upload_form.html
index 3486e47..0c44dfd 100644
--- a/user_metrics/api/templates/csv_upload_form.html
+++ b/user_metrics/api/templates/csv_upload_form.html
@@ -1,13 +1,12 @@
-<form enctype="multipart/form-data" action="/uploads/cohort" method="POST"
class="form-horizontal">
+<form enctype="multipart/form-data" action="/uploads/cohort" method="POST"
class="upload-cohort form-horizontal">
<div class="control-group">
<label for="cohort_name" class="control-label">Cohort Name</label>
<div class="controls">
- <input type="text" name="cohort_name" id="cohort_name" required
value="{% if cohort_name %}{{cohort_name}}{% endif %}"/>
- <a class="btn validate_cohort_name"
href="/validate/cohort/allowed">Is Available?</a>
+ <input type="text" name="cohort_name" id="cohort_name" value="{%
if cohort_name %}{{cohort_name}}{% endif %}"/>
+ <label for="cohort_name">(automatically checks
availability)</label>
</div>
</div>
- <div class="control-group">
- <label for="cohort_project" class="control-label">Wiki Project</label>
+ <div class="control-group"> <label for="cohort_project"
class="control-label">Wiki Project</label>
<div class="controls">
<select name="cohort_project" id="cohort_project">
<option value="">(select one or specify in file)</option>
@@ -20,31 +19,37 @@
<div class="control-group">
<label for="csv_cohort" class="control-label">CSV File</label>
<div class="controls">
- <input type="file" name="csv_cohort" id="csv_cohort" required/>
+ <input type="file" name="csv_cohort" id="csv_cohort"/>
</div>
</div>
<div class="form-actions">
<input type="submit" class="btn btn-primary" value="Upload CSV"/>
</div>
</form>
-
+<script
src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script>
$(document).ready(function(){
-
- $('.validate_cohort_name').on('click', function(event){
- event.preventDefault();
- event.stopPropagation();
- a = $(this);
-
- $.get(a.attr('href'), {cohort_name: $('#cohort_name').val()},
function(response){
- if (JSON.parse(response)){
- alert('Available!');
- } else {
- alert('Cohort already exists.');
+
+ jQuery.validator.addMethod('cohortName', function(value, element) {
+ return /^[0-9_\-A-Za-z ]*$/.test(value);
+ }, 'Cohort names should only contain letters, numbers, spaces, dashes,
and underscores');
+
+ $('form.upload-cohort').validate({
+ messages: {
+ cohort_name: {
+ remote: 'This cohort name is taken.',
}
- }).fail(function(){
- alert('Server Error');
- });
- });
+ },
+ rules: {
+ cohort_name: {
+ required: true,
+ cohortName: true,
+ remote: '/validate/cohort/allowed'
+ },
+ csv_cohort: {
+ required: true
+ }
+ }
});
+ });
</script>
diff --git a/user_metrics/api/templates/layout.html
b/user_metrics/api/templates/layout.html
index e6c69ea..e46880f 100644
--- a/user_metrics/api/templates/layout.html
+++ b/user_metrics/api/templates/layout.html
@@ -3,12 +3,7 @@
<head>
<title>User Metrics API</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static',
filename='css/bootstrap.css') }}">
-<style>
- body { padding-top: 60px; padding-bottom: 60px; }
- .nav { width: 70%; }
- .nav li:last-child { color: #cacaca; float: right !important; }
- .nav li:last-child a { color: #0088cc; display: inline-block; }
-</style>
+<link rel="stylesheet" type="text/css" href="{{ url_for('static',
filename='css/site.css') }}">
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="{{ url_for('static', filename='js/bootstrap.js') }}"></script>
</head>
diff --git a/user_metrics/api/views.py b/user_metrics/api/views.py
index d1f5093..7a9edb0 100644
--- a/user_metrics/api/views.py
+++ b/user_metrics/api/views.py
@@ -172,6 +172,9 @@
cohort_file = request.files['csv_cohort']
cohort_name = request.form['cohort_name']
cohort_project = request.form['cohort_project']
+ if not cohort_file or not cohort_name or len(cohort_name) is 0:
+ flash('The form was invalid, please select a file and name the
cohort.')
+ return redirect('/uploads/cohort')
if not query_mod.is_valid_cohort_query(cohort_name):
flash('That Cohort name is already taken.')
@@ -191,8 +194,8 @@
wiki_projects=sorted(conf.PROJECT_DB_MAP.keys())
)
except Exception, e:
- logging.debug(str(e))
- flash('The file you uploaded was not in a valid format, or could
not be validated.')
+ logging.exception()
+ 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 User Metrics API.')
return redirect('/uploads/cohort')
def validate_cohort_name_allowed():
@@ -244,7 +247,7 @@
def link_to_user_page(username, project):
project = project_name_for_link(project)
- return 'https://%s.wikipedia.org/wiki/User:%s' % (project, username)
+ return 'https://%s.wikipedia.org/wiki/User:%s' % (project.decode('utf8'),
username.decode('utf8'))
def validate_records(records):
valid = []
@@ -293,10 +296,11 @@
owner_id = current_user.id
query_mod.create_cohort(cohort_name, project, owner=owner_id)
query_mod.add_cohort_users(cohort_name, valid)
+ flash('Upload successful, your cohort is in the list below.')
return url_for('cohort', cohort=cohort_name)
#return url_for('all_cohorts')
except Exception, e:
- logging.debug(str(e))
+ logging.exception()
flash('There was a problem finishing the upload. The cohort was not
saved.')
return redirect('/uploads/cohort')
--
To view, visit https://gerrit.wikimedia.org/r/62165
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb4950d16e90285bf935da5e38bf834e45c062de
Gerrit-PatchSet: 1
Gerrit-Project: analytics/user-metrics
Gerrit-Branch: master
Gerrit-Owner: Milimetric <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits