

@csrf_exempt
def update_draft(request, draft_pk):
    'Updates current draft to save admin comments\n\n    :param draft_pk: Unique id for current draft\n    :return: DraftRegistration obj\n    '
    data = json.loads(request.body)
    draft = get_draft_or_error(draft_pk)
    if ('admin_settings' in data):
        form = DraftRegistrationForm(data=data['admin_settings'])
        if (not form.is_valid()):
            return HttpResponseBadRequest('Invalid form data')
        admin_settings = form.cleaned_data
        draft.notes = admin_settings.get('notes', draft.notes)
        del admin_settings['notes']
        draft.flags = admin_settings
        draft.save()
    else:
        schema_data = data.get('schema_data', {
            
        })
        log_message = list()
        for (key, value) in schema_data.iteritems():
            comments = schema_data.get(key, {
                
            }).get('comments', [])
            for comment in comments:
                log_message.append('{}: {}'.format(key, comment['value']))
        try:
            draft.update_metadata(schema_data)
            draft.save()
            update_admin_log(user_id=request.user.id, object_id=draft._id, object_repr='Draft Registration', message='Comments: <p>{}</p>'.format('</p><p>'.join(log_message)), action_flag=COMMENT_PREREG)
        except NodeStateError:
            raise HTTPError(http.BAD_REQUEST)
    return JsonResponse(serializers.serialize_draft_registration(draft))

dataset/ETHPy150Open CenterForOpenScience/osf.io/admin/pre_reg/views.py update_draft/original