示例#1
0
def ajax_edit_event(request, calendar_slug):
    try:
        id = request.REQUEST.get(
            'id')  # we got occurrence's encoded id or event id
        if id:
            kwargs = decode_occurrence(id)
            if kwargs:
                event_id = kwargs['event_id']
            else:
                event_id = id
            event = Event.objects.get(pk=event_id)
            # deleting an event
            if request.REQUEST.get('action') == 'cancel':
                # cancellation of a non-recurring event means deleting the event
                event.delete()
                # there is nothing more - we return empty json
                return HttpResponse(serialize_occurrences([], request.user))
            else:
                form = EventBackendForm(data=request.POST, instance=event)
                if form.is_valid():
                    event = form.save()
                    return HttpResponse(
                        serialize_occurrences(
                            event.get_occurrences(event.start, event.end),
                            request.user))
                return JSONError(form.errors)
        else:
            calendar = get_object_or_404(Calendar, slug=calendar_slug)
            # creation of an event
            form = EventBackendForm(data=request.POST)
            if form.is_valid():
                event = form.save(commit=False)
                event.creator = request.user
                event.calendar = calendar
                event.save()
                return HttpResponse(
                    serialize_occurrences(
                        event.get_occurrences(event.start, event.end),
                        request.user))
            return JSONError(form.errors)
    except Exception as e:
        # import traceback
        # traceback.print_exc()
        return JSONError(e)
示例#2
0
def ajax_edit_occurrence_by_code(request):
    try:
        id = request.REQUEST.get('id')
        kwargs = decode_occurrence(id)
        event_id = kwargs.pop('event_id')
        event, occurrence = get_occurrence(event_id, **kwargs)
        if request.REQUEST.get('action') == 'cancel':
            occurrence.cancel()
            return HttpResponse(serialize_occurrences([occurrence], request.user))
        form = OccurrenceBackendForm(data=request.POST or None, instance=occurrence)
        if form.is_valid():
            occurrence = form.save(commit=False)
            occurrence.event = event
            occurrence.save()
            return HttpResponse(serialize_occurrences([occurrence], request.user))
        return JSONError(form.errors)
    except Exception, e:
        import traceback
        traceback.print_exc()
        return JSONError(e)
示例#3
0
def ajax_edit_event(request, calendar_slug):
    print request.POST
    try:
        id = request.REQUEST.get('id')  # we got occurrence's encoded id or event id
        if id:
            kwargs = decode_occurrence(id)
            if kwargs:
                event_id = kwargs['event_id']
            else:
                event_id = id
            event = Event.objects.get(pk=event_id)
            # deleting an event
            if request.REQUEST.get('action') == 'cancel':
                # cancellation of a non-recurring event means deleting the event
                event.delete()
                # there is nothing more - we return empty json
                return HttpResponse(serialize_occurrences([], request.user))
            else:
                form = EventBackendForm(data=request.POST, instance=event)
                if form.is_valid():
                    event = form.save()
                    return HttpResponse(serialize_occurrences(event.get_occurrences(event.start, event.end), request.user))
                return JSONError(form.errors)
        else:
            calendar = get_object_or_404(Calendar, slug=calendar_slug)
            # creation of an event
            form = EventBackendForm(data=request.POST)
            if form.is_valid():
                event = form.save(commit=False)
                event.creator = request.user
                event.calendar = calendar
                event.save()
                return HttpResponse(serialize_occurrences(event.get_occurrences(event.start, event.end), request.user))
            return JSONError(form.errors)
    except Exception, e:
        import traceback
        traceback.print_exc()
        return JSONError(e)
示例#4
0
def ajax_edit_occurrence_by_code(request):
    try:
        id = request.REQUEST.get('id')
        kwargs = decode_occurrence(id)
        event_id = kwargs.pop('event_id')
        event, occurrence = get_occurrence(event_id, **kwargs)
        if request.REQUEST.get('action') == 'cancel':
            occurrence.cancel()
            return HttpResponse(
                serialize_occurrences([occurrence], request.user))
        form = OccurrenceBackendForm(data=request.POST or None,
                                     instance=occurrence)
        if form.is_valid():
            occurrence = form.save(commit=False)
            occurrence.event = event
            occurrence.save()
            return HttpResponse(
                serialize_occurrences([occurrence], request.user))
        return JSONError(form.errors)
    except Exception as e:
        # import traceback
        # traceback.print_exc()
        return JSONError(e)