aboutsummaryrefslogtreecommitdiffstats
path: root/.tx/config
diff options
context:
space:
mode:
authorMark Longair <mhl@pobox.com>2013-11-13 15:34:07 +0000
committerMark Longair <mhl@pobox.com>2013-11-14 12:50:15 +0000
commitc1ee22fe8df92b03573a03e13f6fd692c9074dd0 (patch)
tree56bde30622b9bedc7f77e1277d1585a8436b10ee /.tx/config
parent3a9c244e75d44a0a65b51eb1144a0b2d64911a75 (diff)
Reduce the memory used to serve /body/all-authorities.csv
On WDTK, /body/all-authorities was using lots of memory - this commit reduces that by (a) fetching the public bodies in batches, rather than keeping them all in memory at one time and (b) writing the CSV to a file and then returning it with X-Sendfile (or equivalent), rather than returning the whole file from memory with send_data. There's a FIXME to do with the layout of download directories; if that's changed, the example nginx config, etc. will need to be updated too. This commit also adds a basic test for reasonable CSV being returned and switches from FasterCSV to CSV in order to fix this NotImplementedError under Ruby 1.9: Please switch to Ruby 1.9's standard CSV library. It's FasterCSV plus support for Ruby 1.9's m17n encoding engine. (The CSV version seems to still work fine under 1.8.7.)
Diffstat (limited to '.tx/config')
0 files changed, 0 insertions, 0 deletions
*/ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
(function (FMS, Backbone, _, $) {
    _.extend( FMS, {
        SubmitView: FMS.FMSView.extend({
            template: 'submit',
            id: 'submit-page',
            prev: 'details',

            events: {
                'pagehide': 'destroy',
                'pagebeforeshow': 'beforeDisplay',
                'pageshow': 'afterDisplay',
                'vclick .ui-btn-left': 'onClickButtonPrev',
                'vclick .ui-btn-right': 'onClickButtonNext',
                'vclick #submit_signed_in': 'onClickSubmit',
                'vclick #submit_sign_in': 'onClickSubmit',
                'vclick #submit_register': 'onClickSubmit'
            },

            render: function(){
                if ( !this.template ) {
                    console.log('no template to render');
                    return;
                }
                template = _.template( tpl.get( this.template ) );
                if ( this.model ) {
                    this.$el.html(template({ model: this.model.toJSON(), user: FMS.currentUser.toJSON() }));
                } else {
                    this.$el.html(template());
                }
                this.afterRender();
                return this;
            },

            onClickSubmit: function(e) {
                // in case we are getting here from a form submission
                e.preventDefault();
                this.beforeSubmit();

                if ( this.validate() ) {
                    this.model.set('user', FMS.currentUser);
                    if ( FMS.isOffline ) {
                        this.navigate( 'save_offline' );
                    } else {
                        this.report = new FMS.Report( this.model.toJSON() );
                        this.listenTo( this.report, 'sync', this.onReportSync );
                        this.listenTo( this.report, 'invalid', this.onReportInvalid );
                        this.listenTo( this.report, 'error', this.onReportError );
                        this.report.save();
                    }
                }
            },

            onReportSync: function(model, resp, options) {
                this.stopListening();
                this.afterSubmit();
                if ( FMS.currentUser ) {
                    FMS.currentUser.save();
                }
                if (resp.report) {
                    this.report.set('site_id', resp.report);
                    this.report.set('site_url', CONFIG.FMS_URL + '/report/' + resp.report);
                } else {
                    this.report.set('email_confirm', 1);
                }
                var reset = FMS.removeDraft( model.id, true);
                var that = this;
                reset.done( function() { that.onRemoveDraft(); } );
                reset.fail( function() { that.onRemoveDraft(); } );
            },

            onRemoveDraft: function() {
                FMS.clearCurrentDraft();
                FMS.createdReport = this.report;
                this.navigate( 'sent' );
            },

            onReportInvalid: function(model, err, options) {
                var errors = err.errors;
                var errorList = '<ul><li class="plain">' + FMS.strings.invalid_report + '</li>';
                var validErrors = [ 'password', 'category', 'name' ];
                for ( var k in errors ) {
                    if ( validErrors.indexOf(k) >= 0 || errors[k].match(/required/) ) {
                        if ( k === 'password' ) {
                            error = FMS.strings.password_problem;
                        } else if ( k !== '') {
                            error = errors[k];
                        }
                        errorList += '<li>' + error + '</li>';
                    }
                }
                errorList += '</ul>';
                $('#errors').html(errorList).show();
            },

            onReportError: function(model, err, options) {
                alert( FMS.strings.sync_error + ': ' + err.errors);
            },

            beforeSubmit: function() {},
            afterSubmit: function() {},

            _destroy: function() {
                this.stopListening();
            }
        })
    });
})(FMS, Backbone, _, $);


(function (FMS, Backbone, _, $) {
    _.extend( FMS, {
        SubmitEmailView: FMS.SubmitView.extend({
            template: 'submit_email',
            id: 'submit-email-page',
            prev: 'details',

            events: {
                'pagehide': 'destroy',
                'pagebeforeshow': 'beforeDisplay',
                'pageshow': 'afterDisplay',
                'vclick .ui-btn-left': 'onClickButtonPrev',
                'vclick #have_password': 'onClickPassword',
                'vclick #email_confirm': 'onClickConfirm'
            },

            validate: function() {
                this.clearValidationErrors();
                var isValid = 1;

                var email = $('#form_email').val();
                if ( !email ) {
                    isValid = 0;
                    this.validationError('form_email', FMS.validationStrings.email.required);
                // regexp stolen from jquery validate module
                } else if ( ! /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(email) ) {
                    isValid = 0;
                    this.validationError('form_email', FMS.validationStrings.email.email);
                }

                return isValid;
            },

            onClickPassword: function(e) {
                e.preventDefault();
                if ( this.validate() ) {
                    FMS.currentUser.set('email', $('#form_email').val());
                    this.navigate( 'submit-password' );
                }
            },

            onClickConfirm: function(e) {
                e.preventDefault();
                if ( this.validate() ) {
                    FMS.currentUser.set('email', $('#form_email').val());
                    this.navigate( 'submit-name' );
                }
            },

            _destroy: function() {}
        })
    });
})(FMS, Backbone, _, $);

(function (FMS, Backbone, _, $) {
    _.extend( FMS, {
        SubmitNameView: FMS.SubmitView.extend({
            template: 'submit_name',
            id: 'submit-name-page',
            prev: 'submit-email',

            events: {
                'pagehide': 'destroy',
                'pagebeforeshow': 'beforeDisplay',
                'pageshow': 'afterDisplay',
                'vclick .ui-btn-left': 'onClickButtonPrev',
                'vclick #send_confirm': 'onClickSubmit',
                'vclick #set_password': 'onClickPassword'
            },

            initialize: function() {
                console.log('submit name initalize');
                this.listenTo(this.model, 'sync', this.onReportSync );
                this.listenTo( this.model, 'error', this.onReportError );
            },

            validate: function() {
                this.clearValidationErrors();
                var isValid = 1;

                var name = $('#form_name').val();
                if ( !name ) {
                    isValid = 0;
                    this.validationError('form_name', FMS.validationStrings.name.required );
                } else {
                    var validNamePat = /\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i;
                    if ( name.length < 6 || !name.match( /\S/ ) || name.match( validNamePat ) ) {
                        isValid = 0;
                        this.validationError('form_name', FMS.validationStrings.name.validName);
                    }
                }

                if ( this.model.get('title_list') && this.model.get('title_list').length > 0 ) {
                    if ( $('#form_title').val() === '' ) {
                        this.validationError('form_title', FMS.strings.required);
                        isValid = 0;
                    }
                }

                return isValid;
            },

            onClickPassword: function() {
                if ( this.validate() ) {
                    this.model.set('submit_clicked', 'submit_register');
                    FMS.currentUser.set('name', $('#form_name').val());
                    FMS.currentUser.set('phone', $('#form_phone').val());
                    if ( this.model.get('title_list') && this.model.get('title_list').length > 0 ) {
                        FMS.currentUser.set('title', $('#form_title').val());
                    }
                    this.navigate( 'submit-set-password' );
                }
            },

            beforeSubmit: function() {
                this.model.set('name', $('#form_name').val());
                this.model.set('phone', $('#form_phone').val());
                this.model.set('may_show_name', $('#form_may_show_name').val());
                if ( this.model.get('title_list') && this.model.get('title_list').length > 0 ) {
                    FMS.currentUser.set('title', $('#form_title').val());
                }
            }
        })
    });
})(FMS, Backbone, _, $);

(function (FMS, Backbone, _, $) {
    _.extend( FMS, {
        SubmitPasswordView: FMS.SubmitView.extend({
            template: 'submit_password',
            id: 'submit-password-page',
            prev: 'submit-email',

            events: {
                'pagehide': 'destroy',
                'pagebeforeshow': 'beforeDisplay',
                'pageshow': 'afterDisplay',
                'vclick .ui-btn-left': 'onClickButtonPrev',
                'vclick #report': 'onClickSubmit',
                'vclick #confirm_name': 'onClickSubmit',
                'submit #passwordForm': 'onClickSubmit'
            },

            initialize: function() {
                this.listenTo(this.model, 'sync', this.onReportSync );
                this.listenTo( this.model, 'error', this.onReportError );
            },

            validate: function() {
                var isValid = 1;

                if ( !$('#form_password').val() ) {
                    isValid = 0;
                    this.validationError('form_password', FMS.validationStrings.password );
                }

                return isValid;
            },

            beforeSubmit: function() {
                $('#report').focus();
                if ( $('#form_name').val() ) {
                    this.model.set('submit_clicked', 'submit_register');
                    this.model.set('phone', $('#form_phone').val());
                    this.model.set('name', $('#form_name').val());
                    this.model.set('may_show_name', $('#form_may_show_name').val());
                } else {
                    // if this is set then we are registering a password
                    if ( ! this.model.get('submit_clicked') ) {
                        this.model.set('submit_clicked', 'submit_sign_in');
                    }
                    FMS.currentUser.set('password', $('#form_password').val());
                }
            },

            afterSubmit: function() {
                FMS.isLoggedIn = 1;
            },

            onReportError: function(model, err, options) {
                if ( err.check_name ) {
                    $('#form_name').val(err.check_name);
                    $('#password_row').hide();
                    $('#check_name').show();
                    $('#confirm_name').focus();
                } else {
                    if ( err.errors && err.errors.password ) {
                        this.validationError('form_password', err.errors.password );
                    }
                    $('#report').focus();
                }
            }

        })
    });
})(FMS, Backbone, _, $);

(function (FMS, Backbone, _, $) {
    _.extend( FMS, {
        SubmitSetPasswordView: FMS.SubmitPasswordView.extend({
            template: 'submit_password',
            id: 'submit--set-password-page',
            prev: 'submit-name'
        })
    });
})(FMS, Backbone, _, $);

(function (FMS, Backbone, _, $) {
    _.extend( FMS, {
        SubmitConfirmView: FMS.SubmitView.extend({
            template: 'submit_confirm',
            id: 'submit-confirm-page',
            prev: 'details',

            events: {
                'pagehide': 'destroy',
                'pagebeforeshow': 'beforeDisplay',
                'pageshow': 'afterDisplay',
                'vclick .ui-btn-left': 'onClickButtonPrev',
                'vclick #report': 'onClickSubmit'
            },

            validate: function() {
                this.clearValidationErrors();
                var isValid = 1;

                var name = $('#form_name').val();
                if ( !name ) {
                    isValid = 0;
                    this.validationError('form_name', FMS.validationStrings.name.required );
                } else {
                    var validNamePat = /\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i;
                    if ( name.length < 6 || !name.match( /\S/ ) || name.match( validNamePat ) ) {
                        isValid = 0;
                        this.validationError('form_name', FMS.validationStrings.name.validName);
                    }
                }

                return isValid;
            },

            beforeSubmit: function() {
                this.model.set('name', $('#form_name').val());
                this.model.set('phone', $('#form_phone').val());
                this.model.set('may_show_name', $('#form_may_show_name').val());
                this.model.set('submit_clicked', 'submit_register');
            },

            onReportError: function(model, err, options) {
                // TODO: this is a temporary measure which should be replaced by a more
                // sensible login mechanism
                if ( err.check_name ) {
                    this.onClickSubmit();
                } else {
                    if ( err.errors && err.errors.password ) {
                        this.validationError('form_password', err.errors.password );
                    }
                }
            }
        })
    });
})(FMS, Backbone, _, $);