Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion pybossa/view/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4054,7 +4054,7 @@ def delete_stats_for_changed_fields(project_id, new_config, old_config):
@login_required
@admin_or_subadmin_required
def answerfieldsconfig(short_name):
"""Returns Project Stats"""
"""Get/ Edit answer fields config"""
project, owner, ps = project_by_shortname(short_name)
pro = pro_features()
ensure_authorized_to('update', project)
Expand Down Expand Up @@ -4099,6 +4099,57 @@ def answerfieldsconfig(short_name):
return handle_content_type(response)


@blueprint.route('/<short_name>/schema-config', methods=['GET', 'POST'])
@login_required
@admin_or_subadmin_required
def schema_config(short_name):
"""Get/ edit project schemas"""
project, owner, ps = project_by_shortname(short_name)
pro = pro_features()
ensure_authorized_to('update', project)

task_info_schema_key = 'task_info_schema'
task_answer_schema_key = 'task_answer_schema'
strict_validation_key = 'strict_validation'
if request.method == 'POST':
try:
body = json.loads(request.data) or {}

task_info_schema = body.get(task_info_schema_key) or {}
task_answer_schema = body.get(task_answer_schema_key) or {}
strict_validation = body.get(strict_validation_key) or False

project.info[task_info_schema_key] = task_info_schema
project.info[task_answer_schema_key] = task_answer_schema
project.info[strict_validation_key] = strict_validation
project_repo.save(project)
auditlogger.log_event(project, current_user, 'update', 'project.' + task_info_schema_key,
'N/A', project.info[task_info_schema_key])
auditlogger.log_event(project, current_user, 'update', 'project.' + task_answer_schema_key,
'N/A', project.info[task_answer_schema_key])
auditlogger.log_event(project, current_user, 'update', 'project.' + strict_validation_key,
'N/A', project.info[strict_validation_key])
flash(gettext('Configuration updated successfully'), 'success')
except Exception:
flash(gettext('An error occurred.'), 'error')
project_sanitized, owner_sanitized = sanitize_project_owner(
project, owner, current_user, ps)

task_info_schema = project.info.get(task_info_schema_key , {})
task_answer_schema = project.info.get(task_answer_schema_key , {})
strict_validation = project.info.get(strict_validation_key , False)
response = {
'template': '/projects/schemaconfig.html',
'project': project_sanitized,
task_info_schema_key : json.dumps(task_info_schema),
task_answer_schema_key : json.dumps(task_answer_schema),
strict_validation_key: strict_validation,
'pro_features': pro,
'csrf': generate_csrf()
}
return handle_content_type(response)


@blueprint.route('/<short_name>/performancestats', methods=['GET', 'DELETE'])
@login_required
def show_performance_stats(short_name):
Expand Down
Loading
Loading