Ejemplo n.º 1
0
def changeStart(request):
    if request.method == "POST":
        eid = request.POST['id']
        event = Event.objects.get(id=findIdOfEvent(eid))
        if(event.repeat):
            startDate = datetime.strptime(request.POST['startTime'], dateString)

            startDate = startDate.replace(tzinfo=tz.gettz('UTC'))
            startDate = startDate.astimezone(tz.tzlocal())

            eventLength = event.end - event.start
            start = startDate
            end = startDate + eventLength

            createException(eid, event)

            e = Event(
                title=event.title,
                description=event.description,
                location=event.location,
                start=start,
                end=end,
                kind = event.kind,
                )

            e.save()
            e.notification.add(*list(event.notification.all()))
            e.events.add(*list(event.events.all()))
            e.creators.add(*list(event.creators.all()))
            comments = Comment.objects.filter(commentID=eid)
            e.event.add(*list(comments))
            unseen = Unseen.objects.filter(commentID=eid)

            for u in unseen:
                u.commentID = e.id
                u.save()

            e.unseen.add(*list(unseen))
            comments.update(commentID=e.id)
            return HttpResponse()

        startDate = datetime.strptime(request.POST['startTime'],
                                      dateString)

        startDate = startDate.replace(tzinfo=tz.gettz('UTC'))
        startDate = startDate.astimezone(tz.tzlocal())

        eventLength = event.end - event.start
        event.start = startDate
        event.end = startDate + eventLength

        event.save()
        return HttpResponse()
    else:
        return HttpResponseNotFound()
Ejemplo n.º 2
0
def createEvent(start, end, recurrence, usr = None, title = "No-Title", description = "", location = "", kind = "BUPR", repeat = False):
    if usr == None:
        return
    if end <= start:
        end = start + timedelta(minutes = 30)
    e = Event(
        title=title,
        description=description,
        location=location,
        start=start,
        end=end,
        kind = kind,
        recurrence = recurrence,
        repeat = repeat,
        )
    e.save()
    usr.creators.add(e)
    usr.events.add(e)

    return e
Ejemplo n.º 3
0
def gcal(request):

    events = json.loads(request.POST['responseJSON'])
    usr = UserProfile.objects.get(user=request.session['fbid'])
    if events.has_key('items') and events['items']:
        for event in events['items']:
            recurring = False;
            recurrence = '';


            if event.has_key('originalStartTime') and event.has_key('recurringEventId') :
                ev = usr.events.filter(gid=event['recurringEventId'])

                if len(ev) > 0 and ev[0].exceptions.filter(exceptionTime=(datetime.strptime(event['originalStartTime']['dateTime'][:-6], googleDateString)).replace(tzinfo=tz.gettz('UTC'))).count() == 0:
                    ex = ExceptionDate(exceptionTime=(datetime.strptime(event['originalStartTime']['dateTime'][:-6], googleDateString)).replace(tzinfo=tz.gettz('UTC')))
                    ex.save()
                    ev[0].exceptions.add(ex)
                    if not event.has_key('start'):
                        continue

            if event.has_key('id'):
                existentEvent = usr.events.filter(gid=event['id'])
                if(len(existentEvent) != 0):
                    continue
            if not event.has_key('summary'):
                event['summary'] = 'No-Title'
            if not event.has_key('description'):
                event['description'] = 'No-Description'
            if not event.has_key('location'):
                event['location'] = ''
            if not event.has_key('start'):
                continue
            if not event.has_key('end'):
                continue
            if not event.has_key('id'):
                event['id'] = 'googleEvent'
            if event['end'].has_key('date') and len(event['end']['date']) <=10 :
                continue

            startTime = datetime.strptime(event['start']['dateTime'][:-6], googleDateString)
            startTime = startTime.replace(tzinfo=tz.gettz('UTC'))
            endTime = datetime.strptime(event['end']['dateTime'][:-6], googleDateString)
            endTime = endTime.replace(tzinfo=tz.gettz('UTC'))


            if event.has_key('recurrence') and len(event['recurrence']) > 0:
                recurring = True;
                if not 'RRULE' in event['recurrence'][0] and len(event['recurrence']) > 1 and 'RRULE' in event['recurrence'][1]:
                    until = re.match(".*UNTIL=........", event['recurrence'][1]);
                    if until is not None:
                        recurrence = event['recurrence'][1].replace(until.group(0), until.group(0)+"T000000Z");
                else:
                    recurrence = event['recurrence'][0].replace("035959", "000000"); #.replace('u\'', '\'').replace("[\'", "").replace('\']', '')

            e = Event(title=event['summary'],
                      description=event['description'],
                      location=event['location'],
                      start=startTime,
                      end=endTime,
                      gid=event['id'],
                      repeat=recurring,
                      recurrence=recurrence,
                      kind = 'BUPU',
                      )
            e.save()
            usr.creators.add(e);
            usr.events.add(e)
    return HttpResponse()