Esempio n. 1
0
    def testSaveFromForm(self):
        """Adds  a user with valid information"""

        f = EventForm(correct_data)
        if f.is_valid():
            event_data = f.save(commit=False)
            user = User.objects.get(username="******")
            event_data.save(editor=user, new=True)

        assert Event.objects.get(name="TestEvent1"), "couldnt add event"
Esempio n. 2
0
def update_event(request, new, object_id=None):
    if not request.POST or not request.user.is_authenticated():
        #return
        pass

    if not new:
        event = Event.all.get(id=object_id)
    else:
        event = Event()

    event_error_id = None

    event_valid = True

    if request.method == 'POST':
        event_form = EventForm(request.POST, instance=event)

        if event_form.is_valid():
            event_data = event_form.save(commit=False)
            event_data.save(request.user, new)
            event = Event.objects.get(id=event_data.id)
        else:
            event_valid = False
            event_error_id = event.id

    else:
        event_form = EventForm()

    response = render_to_response('cal/eventinfo_nf.inc', {
            'event_has_error': not event_valid,
            'event_form': event_form,
            'event': event,
            'new': not event.pk,
            }, context_instance=RequestContext(request))

    if not event_valid:
        response.status_code = 500

    return response