Esempio n. 1
0
def record(request):
    if request.method == 'POST':
        form = NoteForm(request.POST)
        if form.is_valid():
            data, tags, errors = getClassByName(settings.XGDS_NOTES_POPULATE_NOTE_DATA)(request, form)
            
            data = {str(k): v
                    for k, v in data.items()}

            note = createNoteFromData(data)
            linkTags(note, tags)
            jsonNote = broadcastNote(note)

            if not settings.XGDS_SSE:
                return HttpResponse(jsonNote,
                                    content_type='application/json')
            else:
                return HttpResponse(json.dumps({'success': 'true'}), content_type='application/json')

        else:
            return HttpResponse(str(form.errors), status=400)  # Bad Request
    else:
        raise Exception("Request method %s not supported." % request.method)
Esempio n. 2
0
def recordSimple(request):
    if request.method != 'POST':
        return HttpResponse(json.dumps({'error': {'code': -32099,
                                                  'message': 'You must post, cheater.'}
                                        }),
                            content_type='application/json')

    form = NoteForm(request.POST)
    if form.is_valid():
        data, tags, errors = getClassByName(settings.XGDS_NOTES_POPULATE_NOTE_DATA)(request, form)
        note = createNoteFromData(data, False, 'serverNow' in request.POST)
        linkTags(note, tags)
        json_data = broadcastNote(note)

        #return JsonResponse(json_data,
        #                    status=200)
        return HttpResponse(json_data,
                            content_type='application/json')
    else:
        return JsonResponse(json.dumps({'error': {'code': -32099,
                                                  'message': 'problem submitting note',
                                                  'data': form.errors}
                                        }),
                            status=406)
Esempio n. 3
0
def buildNoteForm(episodes, source, request, initial={}):
    moreInitial = callGetNoteExtras(episodes, source, request)
    initial.update(moreInitial)
    return NoteForm(initial=initial)