Exemple #1
0
def calendar_update_event_dates(request):
    id = request.POST.get('id', None)
    start = request.POST.get('start', None)
    end = request.POST.get('end', None)
    id = request.REQUEST.get('id', None)
    try:
        all_day = JSONDecoder().decode(request.POST.get('allDay', 'null'))
    except ValueError:
        all_day = None

    start = datetime.datetime.fromtimestamp(float(start) / 1000)
    end = datetime.datetime.fromtimestamp(float(end) / 1000)

    if id:
        kwargs = decode_occurrence(id)
        event_id = kwargs.pop('event_id')
        instance_event, occurrence = get_occurrence(event_id, **kwargs)
        calendars = get_user_calendars(request.user, ['manager', 'creator'])
        if instance_event.calendar.pk not in [
                c.calendar_id for c in calendars
        ]:
            return HttpResponse("error",
                                mimetype="text/javascript",
                                status=403)

        if all_day:
            ostart = start.strftime('%Y-%m-%d 00:00:00')
            oend = end.strftime('%Y-%m-%d 23:59:59')
        else:
            ostart = start.strftime('%Y-%m-%d %H:%M:%S')
            oend = end.strftime('%Y-%m-%d %H:%M:%S')

        if occurrence.pk:
            occurrence.start = ostart
            occurrence.end = oend
            occurrence.save()
        else:
            occurrence.title = instance_event.title
            occurrence.description = instance_event.description
            occurrence.start = ostart
            occurrence.end = oend
            occurrence.save()
            ied = EventDetails.objects.get_eventdetails_for_object(
                instance_event)
            EventDetails.objects.create_details(
                occurrence,
                location=ied.location,
                free_busy=ied.free_busy,
                privacy=ied.privacy,
                bgcolor=ied.bgcolor,
                category=ied.category,
            )
        return HttpResponse("success", mimetype="text/javascript")
    else:
        return HttpResponse("error", mimetype="text/javascript", status=400)
def ajax_move_or_resize_by_code(request):
    id = request.REQUEST.get('id')
    kwargs = decode_occurrence(id)
    event_id = kwargs.pop('event_id')
    event, occurrence = get_occurrence(event_id, **kwargs)

    dayDelta = int(request.REQUEST.get('dayDelta'))
    minuteDelta = int(request.REQUEST.get('minuteDelta'))
    dt = timedelta(days=dayDelta, minutes=minuteDelta)

    resize = bool(request.REQUEST.get('resize', False))
    resp = {}
    if occurrence.event.rule:
        if occurrence.id:
            #Direct move/resize occurrence
            new_start = occurrence.start
            if not resize:
                new_start += dt
            occurrence.move(new_start, occurrence.end + dt)
            resp['status'] = "OK"
        else:
            #Either move/resize event or occurrences. Need to ask to the user
            if 'target' in request.REQUEST:
                target = request.REQUEST.get('target')
                if target == 'this':
                    new_start = occurrence.start
                    if not resize:
                        new_start += dt
                    occurrence.move(new_start, occurrence.end + dt)
                    resp['status'] = "OK"
                elif target == 'all':
                    if not resize:
                        event.start += dt
                    event.end = event.end + dt
                    event.save()
                    resp['status'] = "OK"
            else:
                resp['status'] = "FUZZY"
                resp[
                    'move_or_resize_url'] = "%s?id=%s&dayDelta=%s&minuteDelta=%s" % (
                        reverse("ajax_move_or_resize"), id, dayDelta,
                        minuteDelta)
                if resize:
                    resp['move_or_resize_url'] += "&resize=1"
    else:
        #Direct move/resize event
        if not resize:
            event.start += dt
        event.end = event.end + dt
        event.save()
        resp['status'] = "OK"

    return HttpResponse(simplejson.dumps(resp))
Exemple #3
0
def calendar_update_event_dates(request):
    id = request.POST.get('id', None)
    start = request.POST.get('start', None)
    end = request.POST.get('end', None)
    id = request.REQUEST.get('id', None)
    try:
        all_day = JSONDecoder().decode(request.POST.get('allDay', 'null'))
    except ValueError:
        all_day = None

    start = datetime.datetime.fromtimestamp(float(start) / 1000)
    end = datetime.datetime.fromtimestamp(float(end) / 1000)

    if id:
        kwargs = decode_occurrence(id)
        event_id = kwargs.pop('event_id')
        instance_event, occurrence = get_occurrence(event_id, **kwargs)
        calendars = get_user_calendars(request.user, ['manager', 'creator'])
        if instance_event.calendar.pk not in [c.calendar_id for c in calendars]:
            return HttpResponse("error", mimetype="text/javascript", status=403)

        if all_day:
            ostart = start.strftime('%Y-%m-%d 00:00:00')
            oend = end.strftime('%Y-%m-%d 23:59:59')
        else:
            ostart = start.strftime('%Y-%m-%d %H:%M:%S')
            oend = end.strftime('%Y-%m-%d %H:%M:%S')

        if occurrence.pk:
            occurrence.start = ostart
            occurrence.end = oend
            occurrence.save()
        else:
            occurrence.title = instance_event.title
            occurrence.description = instance_event.description
            occurrence.start = ostart
            occurrence.end = oend
            occurrence.save()
            ied = EventDetails.objects.get_eventdetails_for_object(
                instance_event)
            EventDetails.objects.create_details(
                occurrence,
                location=ied.location,
                free_busy=ied.free_busy,
                privacy=ied.privacy,
                bgcolor=ied.bgcolor,
                category=ied.category,
            )
        return HttpResponse("success", mimetype="text/javascript")
    else:
        return HttpResponse("error", mimetype="text/javascript", status=400)
Exemple #4
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, [], request.user))
            else:
                form = EventBackendForm(data=request.POST, instance=event)
                if form.is_valid():
                    event = form.save()
                    return HttpResponse(
                        serialize_occurrences(
                            request,
                            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(
                        request, event.get_occurrences(event.start, event.end),
                        request.user))
            return JSONError(form.errors)
    except Exception, e:
        import traceback
        traceback.print_exc()
        return JSONError(e)
Exemple #5
0
def edit_calendar_event(request):

    id = request.REQUEST.get('id', None)
    if id:
        kwargs = decode_occurrence(id)
        event_id = kwargs.pop('event_id')
        instance_event, occurrence = get_occurrence(event_id, **kwargs)
    else:
        return HttpResponseRedirect('/')

    if occurrence.pk:
        return edit_calendar_occurrence(request, event_id, instance_event, occurrence)
    else:
        if instance_event.rule is None:
            return edit_calendar_simple_event(request, event_id, instance_event, occurrence)
        else:
            return edit_calendar_reccurrent_event(request, event_id, instance_event, occurrence)
Exemple #6
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)
Exemple #7
0
def edit_calendar_event(request):

    id = request.REQUEST.get('id', None)
    if id:
        kwargs = decode_occurrence(id)
        event_id = kwargs.pop('event_id')
        instance_event, occurrence = get_occurrence(event_id, **kwargs)
    else:
        return HttpResponseRedirect('/')

    if occurrence.pk:
        return edit_calendar_occurrence(request, event_id, instance_event,
                                        occurrence)
    else:
        if instance_event.rule is None:
            return edit_calendar_simple_event(request, event_id,
                                              instance_event, occurrence)
        else:
            return edit_calendar_reccurrent_event(request, event_id,
                                                  instance_event, occurrence)
Exemple #8
0
def ajax_edit_event(request, calendar_slug):
    #print "event jax_edit_event called!!!"

    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)
Exemple #9
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(request, [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(request, [occurrence], request.user))
        return JSONError(form.errors)
    except Exception, e:
        import traceback
        traceback.print_exc()
        return JSONError(e)