Beispiel #1
0
def add_event(request, project_slug=None, template='blagenda/add_event.html'):
    '''
    Add a new ``Event`` instance and 1 or more associated ``Occurrence``s.

    Context parameters:

    dtstart
        a datetime.datetime object representing the GET request value if present,
        otherwise None

    event_form
        a form object for updating the event

    recurrence_form
        a form object for adding occurrences

    '''
    dtstart = None
    event = None
    if project_slug:
        project = get_object_or_404(Project, slug=project_slug, members=request.user)
    else:
        project = None

    if request.method == 'POST':
        event_form = EventForm(project, request.user, request.POST)
        recurrence_form = SingleOccurrenceForm(event, request.POST)
        if event_form.is_valid() and recurrence_form.is_valid():
            event = event_form.save(request.user, project)
            occurrence = recurrence_form.save(event)

            # Notifications
            request.user.message_set.create(message=_("Event '%(event)s' has been created" % {'event': event.title }))
            event.create_activity(request.user, Activity.CREATE)

            if project:
                 return http.HttpResponseRedirect(reverse('agenda-monthly-view', kwargs = {'project_slug': project_slug, 'month': occurrence.start_time.month , 'year': occurrence.start_time.year }))
            else:
                return http.HttpResponseRedirect(reverse('agenda-monthly-view', kwargs = {'month': occurrence.start_time.month , 'year': occurrence.start_time.year }))

    else:
        if 'dtstart' in request.GET:
            try:
                dtstart = parser.parse(request.GET['dtstart'])
            except:
                # TODO A badly formatted date is passed to add_event
                dtstart = datetime.now()
        else: dtstart = datetime.now()

        event_form = EventForm(project, request.user)
        start_time = (dtstart - datetime.combine(dtstart.date(), time(0))).seconds

        recurrence_form = SingleOccurrenceForm(event, initial={'day': dtstart.date(),
                                                               'start_time_delta': start_time, })

    return render_to_response(
        template,
        dict(dtstart=dtstart, event_form=event_form, recurrence_form=recurrence_form, project=project),
        context_instance=RequestContext(request)
    )
Beispiel #2
0
def event_view(request, pk, project_slug=None, template='blagenda/event_detail.html'):
    '''
    View an ``Event`` instance and optionally update either the event or its
    occurrences.

    Context parameters:

    event
        the event keyed by ``pk``

    event_form
        a form object for updating the event

    recurrence_form
        a form object for adding occurrences
    '''
    event = get_object_or_404(Event, pk=pk)

    if project_slug:
        project = get_object_or_404(Project, slug=project_slug, members=request.user)
    else: project = None

    event_form = EventForm(project, request.user, instance=event)

    occurrence =  event.occurrence_set.all()[0]

    start_time = (occurrence.start_time - datetime.combine(occurrence.start_time.date(), time(0))).seconds

    recurrence_form = SingleOccurrenceForm(event, initial={'day': occurrence.start_time.date(),
                                                           'start_time_delta': start_time, })

    if request.method == 'POST':
        event_form = EventForm(project, request.user, request.POST, instance=event)
        recurrence_form = SingleOccurrenceForm(event, request.POST, instance=occurrence)
        if event_form.is_valid() and recurrence_form.is_valid():
            event = event_form.save(request.user, project)
            recurrence_form.save(event)

            # Notifications
            request.user.message_set.create(message=_("Event '%(event)s' has been updated" % {'event': event.title }))
            event.create_activity(request.user, Activity.UPDATE)

            if project_slug:
                return http.HttpResponseRedirect(reverse('agenda-monthly-view', kwargs = {'project_slug': project_slug, 'month': occurrence.start_time.month , 'year': occurrence.start_time.year }))
            else:
                return http.HttpResponseRedirect(reverse('agenda-monthly-view', kwargs = {'month': occurrence.start_time.month , 'year': occurrence.start_time.year }))

    return render_to_response(
        template,
        dict(project=project, event=event, event_form=event_form, recurrence_form=recurrence_form),
        context_instance=RequestContext(request)
    )
Beispiel #3
0
def event_view(request,
               pk,
               project_slug=None,
               template='blagenda/event_detail.html'):
    '''
    View an ``Event`` instance and optionally update either the event or its
    occurrences.

    Context parameters:

    event
        the event keyed by ``pk``

    event_form
        a form object for updating the event

    recurrence_form
        a form object for adding occurrences
    '''
    event = get_object_or_404(Event, pk=pk)

    if project_slug:
        project = get_object_or_404(Project,
                                    slug=project_slug,
                                    members=request.user)
    else:
        project = None

    event_form = EventForm(project, request.user, instance=event)

    occurrence = event.occurrence_set.all()[0]

    start_time = (
        occurrence.start_time -
        datetime.combine(occurrence.start_time.date(), time(0))).seconds

    recurrence_form = SingleOccurrenceForm(event,
                                           initial={
                                               'day':
                                               occurrence.start_time.date(),
                                               'start_time_delta': start_time,
                                           })

    if request.method == 'POST':
        event_form = EventForm(project,
                               request.user,
                               request.POST,
                               instance=event)
        recurrence_form = SingleOccurrenceForm(event,
                                               request.POST,
                                               instance=occurrence)
        if event_form.is_valid() and recurrence_form.is_valid():
            event = event_form.save(request.user, project)
            recurrence_form.save(event)

            # Notifications
            request.user.message_set.create(
                message=_("Event '%(event)s' has been updated" %
                          {'event': event.title}))
            event.create_activity(request.user, Activity.UPDATE)

            if project_slug:
                return http.HttpResponseRedirect(
                    reverse('agenda-monthly-view',
                            kwargs={
                                'project_slug': project_slug,
                                'month': occurrence.start_time.month,
                                'year': occurrence.start_time.year
                            }))
            else:
                return http.HttpResponseRedirect(
                    reverse('agenda-monthly-view',
                            kwargs={
                                'month': occurrence.start_time.month,
                                'year': occurrence.start_time.year
                            }))

    return render_to_response(template,
                              dict(project=project,
                                   event=event,
                                   event_form=event_form,
                                   recurrence_form=recurrence_form),
                              context_instance=RequestContext(request))
Beispiel #4
0
def add_event(request, project_slug=None, template='blagenda/add_event.html'):
    '''
    Add a new ``Event`` instance and 1 or more associated ``Occurrence``s.

    Context parameters:

    dtstart
        a datetime.datetime object representing the GET request value if present,
        otherwise None

    event_form
        a form object for updating the event

    recurrence_form
        a form object for adding occurrences

    '''
    dtstart = None
    event = None
    if project_slug:
        project = get_object_or_404(Project,
                                    slug=project_slug,
                                    members=request.user)
    else:
        project = None

    if request.method == 'POST':
        event_form = EventForm(project, request.user, request.POST)
        recurrence_form = SingleOccurrenceForm(event, request.POST)
        if event_form.is_valid() and recurrence_form.is_valid():
            event = event_form.save(request.user, project)
            occurrence = recurrence_form.save(event)

            # Notifications
            request.user.message_set.create(
                message=_("Event '%(event)s' has been created" %
                          {'event': event.title}))
            event.create_activity(request.user, Activity.CREATE)

            if project:
                return http.HttpResponseRedirect(
                    reverse('agenda-monthly-view',
                            kwargs={
                                'project_slug': project_slug,
                                'month': occurrence.start_time.month,
                                'year': occurrence.start_time.year
                            }))
            else:
                return http.HttpResponseRedirect(
                    reverse('agenda-monthly-view',
                            kwargs={
                                'month': occurrence.start_time.month,
                                'year': occurrence.start_time.year
                            }))

    else:
        if 'dtstart' in request.GET:
            try:
                dtstart = parser.parse(request.GET['dtstart'])
            except:
                # TODO A badly formatted date is passed to add_event
                dtstart = datetime.now()
        else:
            dtstart = datetime.now()

        event_form = EventForm(project, request.user)
        start_time = (dtstart -
                      datetime.combine(dtstart.date(), time(0))).seconds

        recurrence_form = SingleOccurrenceForm(event,
                                               initial={
                                                   'day': dtstart.date(),
                                                   'start_time_delta':
                                                   start_time,
                                               })

    return render_to_response(template,
                              dict(dtstart=dtstart,
                                   event_form=event_form,
                                   recurrence_form=recurrence_form,
                                   project=project),
                              context_instance=RequestContext(request))