Exemplo n.º 1
0
def event_adjecents(request, start_date, start_time, end_date, end_time, event=None, locations=None):
    """Returns the events which take place adjacent to the to-be-planned event."""

    start = datetime.strptime("%s %s" % (start_date, start_time), "%d-%m-%Y %H:%M") - timedelta(minutes=15)
    end = datetime.strptime("%s %s" % (end_date, end_time), "%d-%m-%Y %H:%M") + timedelta(minutes=15)
    realstart = datetime.strptime("%s %s" % (start_date, start_time), "%d-%m-%Y %H:%M")
    realend = datetime.strptime("%s %s" % (end_date, end_time), "%d-%m-%Y %H:%M")

    # Haal alle conflicting events op met een kwartier speling aan beide
    # einden. Haal vervolgens de de echte conflicting events eruit, zodat de
    # adjacent events overblijven.
    if locations:
        locations = Location.objects.filter(pk__in=locations)
        events = Event.objects.none()
        adjevents = Event.objects.none()
        for location in locations:
            events |= Event.conflicting_events(realstart, realend, location)
            adjevents |= Event.conflicting_events(start, end, location)
    else:
        events = Event.conflicting_events(realstart, realend)
        adjevents = Event.conflicting_events(start, end)

    if event:
        events = events.exclude(pk=event)

    result = []
    for event in adjevents:
        if event not in events:
            result.append(model_to_dict(event))

    return result
Exemplo n.º 2
0
def event_adjecents(request, start_date, start_time, end_date, end_time, event=None, locations=None):
    """Returns the events which take place adjacent to the to-be-planned event."""

    start = datetime.strptime("%s %s" % (start_date, start_time), "%d-%m-%Y %H:%M") - timedelta(minutes=15)
    end = datetime.strptime("%s %s" % (end_date, end_time), "%d-%m-%Y %H:%M") + timedelta(minutes=15)
    realstart = datetime.strptime("%s %s" % (start_date, start_time), "%d-%m-%Y %H:%M")
    realend = datetime.strptime("%s %s" % (end_date, end_time), "%d-%m-%Y %H:%M")

    # Haal alle conflicting events op met een kwartier speling aan beide
    # einden. Haal vervolgens de de echte conflicting events eruit, zodat de
    # adjacent events overblijven.
    if locations:
        locations = Location.objects.filter(pk__in=locations)
        events = Event.objects.none()
        adjevents = Event.objects.none()
        for location in locations:
            events |= Event.conflicting_events(realstart, realend, location)
            adjevents |= Event.conflicting_events(start, end, location)
    else:
        events = Event.conflicting_events(realstart, realend)
        adjevents = Event.conflicting_events(start, end)

    if event:
        events = events.exclude(pk=event)

    result = []
    for event in adjevents:
        if event not in events:
            result.append(model_to_dict(event))

    return result
Exemplo n.º 3
0
def event_conflicts(request, start_date, start_time, end_date, end_time, event_id=None, locations=None):
    """Returns the events which take place at the same time as the to-be-planned event."""

    start = datetime.strptime("%s %s" % (start_date, start_time), "%d-%m-%Y %H:%M")
    end = datetime.strptime("%s %s" % (end_date, end_time), "%d-%m-%Y %H:%M")

    if locations:
        locations = Location.objects.filter(pk__in=locations.split(','))
        events = Event.objects.none()
        for location in locations:
            events |= Event.conflicting_events(start, end, location)
    else:
        events = Event.conflicting_events(start, end)

    if event_id:
        events = events.exclude(pk=event_id)

    result = []
    for event in events:
        result.append(model_to_dict(event))

    return result
Exemplo n.º 4
0
def event_conflicts(request, start_date, start_time, end_date, end_time, event_id=None, locations=None):
    """Returns the events which take place at the same time as the to-be-planned event."""

    start = datetime.strptime("%s %s" % (start_date, start_time), "%d-%m-%Y %H:%M")
    end = datetime.strptime("%s %s" % (end_date, end_time), "%d-%m-%Y %H:%M")

    if locations:
        locations = Location.objects.filter(pk__in=locations.split(','))
        events = Event.objects.none()
        for location in locations:
            events |= Event.conflicting_events(start, end, location)
    else:
        events = Event.conflicting_events(start, end)

    if event_id:
        events = events.exclude(pk=event_id)

    result = []
    for event in events:
        result.append(model_to_dict(event))

    return result
Exemplo n.º 5
0
    def clean(self):
        cleaned_data = super(EventForm, self).clean()
        starts_at = cleaned_data.get('starts_at')
        ends_at = cleaned_data.get('ends_at')
        locations = cleaned_data.get('location')

        if starts_at and ends_at and starts_at > ends_at:
            raise ValidationError(_("The start time is earlier than the end time!"))

        if starts_at and ends_at and locations:
            for location in locations:
                if location.prevent_conflicting_events:
                    conf_events = Event.conflicting_events(starts_at, ends_at, location)
                    if self.instance:
                        conf_events = conf_events.exclude(pk=self.instance.pk)
                    if conf_events.exists():
                        raise ValidationError(
                            _("There is an event in %(location)s already!") % {'location': location.name}
                        )

        return cleaned_data
Exemplo n.º 6
0
    def clean(self):
        cleaned_data = super(EventForm, self).clean()
        starts_at = cleaned_data.get('starts_at')
        ends_at = cleaned_data.get('ends_at')
        locations = cleaned_data.get('location')

        if starts_at and ends_at and starts_at > ends_at:
            raise ValidationError(
                _("The start time is earlier than the end time!"))

        if starts_at and ends_at and locations:
            for location in locations:
                if location.prevent_conflicting_events:
                    conf_events = Event.conflicting_events(
                        starts_at, ends_at, location)
                    if self.instance:
                        conf_events = conf_events.exclude(pk=self.instance.pk)
                    if conf_events.exists():
                        raise ValidationError(
                            _("There is an event in %(location)s already!") %
                            {'location': location.name})

        return cleaned_data