def validate_cohort_project_allowed(): """ Returns true if a valid project is provided. Remote call is set up in static/js/cohortUpload.js. """ project = request.args.get('project') valid = project in db.get_project_host_map() return json.dumps(valid)
def normalize_project(project): """ Decides whether the name of the project is a valid one There are differences in db names in local setup versus vagrant setup While local setup uses enwiki mediawiki vagrant uses wiki We let 'wiki' be an acceptable name in development by injecting it into the project_host_map returned by the database singleton, db """ project = project.strip().lower() if project in db.get_project_host_map(): return project else: # try adding wiki to end new_proj = project + 'wiki' if new_proj not in db.get_project_host_map(): return None else: return new_proj
def normalize_project(project): """ Decides whether the name of the project is a valid one There are differences in db names in local setup versus vagrant setup While local setup uses enwiki mediawiki vagrant uses wiki We let 'wiki' be an acceptable name in development by injecting it into the project_host_map returned by the database singleton, db """ project = project.strip().lower() if project in db.get_project_host_map(): return project else: # try adding wiki to end new_proj = project + 'wiki' if new_proj not in db.get_project_host_map(): return None else: return new_proj
def validate_cohort_project_allowed(): project = request.args.get('project') valid = project in db.get_project_host_map() return json.dumps(valid)
flash('That Cohort name is already taken.', 'warning') else: form.parse_records() vc = ValidateCohort.from_upload(form, current_user.id) vc.task.delay(vc) return redirect('{0}#{1}'.format( url_for('cohorts_index'), vc.cohort_id )) except Exception, e: app.logger.exception(str(e)) flash('Server error while processing your upload', 'error') return render_template( 'csv_upload.html', projects=json.dumps(sorted(db.get_project_host_map().keys())), form=form, ) def get_cohort_by_name(name): """ Gets a cohort by name, without checking access or worrying about duplicates """ try: db_session = db.get_session() return db_session.query(CohortStore).filter(CohortStore.name == name).first() finally: db_session.close()
else: form.parse_records() vc = ValidateCohort.from_upload(form, current_user.id) vc.task.delay(vc) return redirect('{0}#{1}'.format( url_for('cohorts_index'), vc.cohort_id )) except Exception, e: app.logger.exception(str(e)) flash('Server error while processing your upload', 'error') return render_template( 'csv_upload.html', projects=json.dumps(sorted(db.get_project_host_map().keys())), form=form, ) @app.route('/cohorts/validate/name') def validate_cohort_name_allowed(): """ Returns true if there are no other cohorts with this name. Remote call is set up in static/js/cohortUpload.js. """ name = request.args.get('name') session = db.get_session() available = g.cohort_service.get_cohort_by_name(session, name) is None return json.dumps(available)
def __call__(self, form, field): if field.data not in db.get_project_host_map(): raise ValidationError('That project does not exist.')