Ejemplo n.º 1
0
def add_repeat(request):
    if request.method == 'POST':
        # get new event data
        user = request.user
        title = request.POST['title']
        start = strToDateTime(request.POST['start'])
        end = strToDateTime(request.POST['end'])
        allDay = True if (request.POST['allDay'] == 'true') else False
        rrule = int(request.POST['rrule'])
        endRepeat = strToDateTime(request.POST['endRepeat'])
        print request.POST['endRepeat']
        print endRepeat

        # make new RepeatEvent and save
        event = RepeatEvent(user=user,
                            title=title,
                            start=start,
                            end=end,
                            allDay=allDay,
                            endRepeat=endRepeat,
                            rrule=rrule)
        event.save()

        # return the id of the new event
        return HttpResponse(str(event.id))
    else:
        return HttpResponseRedirect('/')
Ejemplo n.º 2
0
def add_repeat(request):
    if request.method == 'POST':
        # get new event data
        user = request.user
        title = request.POST['title']
        start = strToDateTime(request.POST['start'])
        end = strToDateTime(request.POST['end'])
        allDay = True if (request.POST['allDay'] == 'true') else False
        rrule = int(request.POST['rrule'])
        endRepeat = strToDateTime(request.POST['endRepeat'])
        print request.POST['endRepeat']
        print endRepeat

        # make new RepeatEvent and save
        event = RepeatEvent(
            user = user,
            title=title,
            start=start,
            end=end,
            allDay=allDay,
            endRepeat = endRepeat,
            rrule = rrule
        )
        event.save()

        # return the id of the new event
        return HttpResponse(str(event.id))
    else:
        return HttpResponseRedirect('/')
Ejemplo n.º 3
0
def add_repeat(request):
    # get new event data
    user = request.user
    title = request.POST['title']
    start = strToDateTime(request.POST['start'])
    end = strToDateTime(request.POST['end'])
    allDay = True if (request.POST['allDay'] == 'true') else False

    # make new RepeatEvent and save
    event = RepeatEvent(
        user = user,
        title=title,
        start=start,
        end=end,
        allDay=allDay
    )
    event.save()

    # return the id of the new event
    return HttpResponse(str(event.id))
Ejemplo n.º 4
0
def share_event(request):

    if request.method == 'POST':
        # unload the sent data
        to_user = request.POST["user"]
        title = request.POST["title"]
        start = strToDateTime(request.POST["start"])
        end = strToDateTime(request.POST["end"])
        allDay = True if (request.POST["allDay"] == "true") else False
        type = request.POST["type"]
        rrule = request.POST["rrule"]
        endRepeat = strToDateTime(request.POST["endRepeat"])

        # convert 'null' to None where needed

        # get the actual user
        user = User.objects.filter(username=to_user)[0]

        # handle if non-repeating event
        if type == "event":
            shared_event = Event(user=user,
                                 title=title,
                                 start=start,
                                 end=end,
                                 allDay=allDay)

        # handle if repeating event
        else:
            shared_event = RepeatEvent(user=user,
                                       title=title,
                                       start=start,
                                       end=end,
                                       allDay=allDay,
                                       rrule=rrule,
                                       endRepeat=endRepeat)

        # save the shared event
        shared_event.save()

        # leave a message for whoever we shared with
        slash_date = str(start.month) + "/" + str(start.day) + "/" + str(
            start.year)[2] + str(start.year)[3]
        repeat_message = "an" if (type == "event") else "a repeating"
        start_message = "" if (type == "event") else "starting "
        message = request.user.username + " added " + repeat_message + " event to your calendar " + start_message + "on " + slash_date
        note = Note(user=user, message=message)
        note.save()

        return HttpResponse("event shared")
    else:
        return HttpResponseRedirect('/')
Ejemplo n.º 5
0
def edit_repeat(request):
    if request.method == 'POST':
        # get passed in data
        user = request.user
        id = request.POST['sid']
        oldStart = strToDateTime(request.POST['oldStart'])
        newStart = strToDateTime(request.POST['start'])
        newEnd = strToDateTime(request.POST['end'])
        type = request.POST['type']
        endRepeat = request.POST['endRepeat']

        # handle datatype conversions
        if endRepeat == 'null':
            endRepeat = None

        # get old RepeatEvent object
        repeat = user.repeatevent_set.get(pk = id)
        breaks = repeat.breaks.all()
        oldEndRepeat = repeat.endRepeat

        # get break events to move to new repeatevent
        breaks_new = []
        for br in breaks:
            if br.date > oldStart:
                # remove from old repeat
                repeat.breaks.remove(br)
                # add to breaks_new array
                breaks_new.append(br)

        # container to hold httpresponse of ids
        ids = ''

        # check whether oldStart is the head
        if oldStart == repeat.start:
            # delete old RepeatEvent
            repeat.delete()

        # check if you are one past the head
        elif oneBack(oldStart, repeat) == repeat.start:
            # make the head of the old RepeatEvent into a new Event object
            event = Event(
                user = user,
                title=repeat.title,
                start=repeat.start,
                end=repeat.end,
                allDay=repeat.allDay
            )
            event.save()

            # add id to container
            ids = str(event.id) + ','

            # delete old RepeatEvent
            repeat.delete()

        # otherwise
        else:
            # set end date of old RepeatEvent to one instance back of the passed in date
            end = oneBack(oldStart,repeat)
            # update old RepeatEvent and save
            repeat.endRepeat = end
            repeat.save()


        # create new Event object if you edited the last in the chain
        # could be editing last in chain and making it a new rrule
        if type == 'event':
            tail = Event(
                user = user,
                title=request.POST['title'],
                start=newStart,
                end=newEnd,
                allDay=request.POST['allDay']
            )
            tail.save()

            # add id to container
            ids += str(tail.id)

        # create new RepeatEvent object otherwise
        else:
            new_repeat = RepeatEvent(
                user = user,
                title=request.POST['title'],
                start=newStart,
                end=newEnd,
                allDay=request.POST['allDay'],
                rrule = int(request.POST['rrule']),
                endRepeat = endRepeat
            )
            new_repeat.save()

            # add id to container
            ids += str(new_repeat.id)

            # move breaks and endRepeat to new chain by delta
            delta = newStart - oldStart
            for br in breaks_new:
                br.date += delta
                br.save()
                new_repeat.breaks.add(br)
            if (oldEndRepeat):
                new_repeat.endRepeat = oldEndRepeat + delta
                new_repeat.save()

        # '3' OR '1,3' where first number is the event id for the head and second is id of new RepeatEvent / Event (if last moved is tail)
        return HttpResponse(ids)
    else:
        return HttpResponseRedirect('/')
Ejemplo n.º 6
0
def edit_repeat(request):
    user = request.user
    id = request.POST['sid']
    oldStart = strToDateTime(request.POST['oldStart'])
    newStart = strToDateTime(request.POST['start'])
    newEnd = strToDateTime(request.POST['end'])

    # get old RepeatEvent object
    repeat = user.repeatevent_set.get(pk = id)
    breaks = repeat.breaks.all()

    # get break events to move to new repeatevent
    breaks_new = []
    for br in breaks:
        if br.date > oldStart:
            # remove from old repeat
            repeat.breaks.remove(br)
            # save to breaks_new array
            breaks_new.append(br)

    # container to hold httpresponse of ids
    ids = ''

    # check whether oldStart is the head
    if oldStart == repeat.start:
        # delete RepeatEvent
        repeat.delete()
    # check if you are one past the head
    elif oneBack(oldStart, 'rrule') == repeat.start:
        # make the head into a new Event object
        event = Event(
            user = user,
            title=repeat.title,
            start=repeat.start,
            end=repeat.end,
            allDay=repeat.allDay
        )
        event.save()
        # add id to container
        ids = str(event.id) + ','
        # delete RepeatEvent
        repeat.delete()
    # otherwise
    else:
        # set end date to one instance back of the passed in date
        end = oneBack(oldStart,'rrule')
        # update repeat and save
        repeat.endRepeat = end
        repeat.save()

    # create new RepeatEvent object based on new datetimes
    new_repeat = RepeatEvent(
        user = user,
        title=request.POST['title'],
        start=newStart,
        end=newEnd,
        allDay=request.POST['allDay']
    )
    new_repeat.save()

    # add id to container
    ids += str(new_repeat.id)

    # move breaks to new chain by delta
    delta = newStart - oldStart
    for br in breaks_new:
        br.date += delta
        br.save()
        new_repeat.breaks.add(br)

    # '3' OR '1,3' where first number is the event id for the head and second is id of new RepeatEvent
    return HttpResponse(ids)
Ejemplo n.º 7
0
def edit_repeat(request):
    if request.method == 'POST':
        # get passed in data
        user = request.user
        id = request.POST['sid']
        oldStart = strToDateTime(request.POST['oldStart'])
        newStart = strToDateTime(request.POST['start'])
        newEnd = strToDateTime(request.POST['end'])
        type = request.POST['type']
        endRepeat = request.POST['endRepeat']

        # handle datatype conversions
        if endRepeat == 'null':
            endRepeat = None

        # get old RepeatEvent object
        repeat = user.repeatevent_set.get(pk=id)
        breaks = repeat.breaks.all()
        oldEndRepeat = repeat.endRepeat

        # get break events to move to new repeatevent
        breaks_new = []
        for br in breaks:
            if br.date > oldStart:
                # remove from old repeat
                repeat.breaks.remove(br)
                # add to breaks_new array
                breaks_new.append(br)

        # container to hold httpresponse of ids
        ids = ''

        # check whether oldStart is the head
        if oldStart == repeat.start:
            # delete old RepeatEvent
            repeat.delete()

        # check if you are one past the head
        elif oneBack(oldStart, repeat) == repeat.start:
            # make the head of the old RepeatEvent into a new Event object
            event = Event(user=user,
                          title=repeat.title,
                          start=repeat.start,
                          end=repeat.end,
                          allDay=repeat.allDay)
            event.save()

            # add id to container
            ids = str(event.id) + ','

            # delete old RepeatEvent
            repeat.delete()

        # otherwise
        else:
            # set end date of old RepeatEvent to one instance back of the passed in date
            end = oneBack(oldStart, repeat)
            # update old RepeatEvent and save
            repeat.endRepeat = end
            repeat.save()

        # create new Event object if you edited the last in the chain
        # could be editing last in chain and making it a new rrule
        if type == 'event':
            tail = Event(user=user,
                         title=request.POST['title'],
                         start=newStart,
                         end=newEnd,
                         allDay=request.POST['allDay'])
            tail.save()

            # add id to container
            ids += str(tail.id)

        # create new RepeatEvent object otherwise
        else:
            new_repeat = RepeatEvent(user=user,
                                     title=request.POST['title'],
                                     start=newStart,
                                     end=newEnd,
                                     allDay=request.POST['allDay'],
                                     rrule=int(request.POST['rrule']),
                                     endRepeat=endRepeat)
            new_repeat.save()

            # add id to container
            ids += str(new_repeat.id)

            # move breaks and endRepeat to new chain by delta
            delta = newStart - oldStart
            for br in breaks_new:
                br.date += delta
                br.save()
                new_repeat.breaks.add(br)
            if (oldEndRepeat):
                new_repeat.endRepeat = oldEndRepeat + delta
                new_repeat.save()

        # '3' OR '1,3' where first number is the event id for the head and second is id of new RepeatEvent / Event (if last moved is tail)
        return HttpResponse(ids)
    else:
        return HttpResponseRedirect('/')