Beispiel #1
0
def new_event(request):
    ''' Create a new Event.
    Error if any of the fields are blank.
    Error if event_time and end_time aren't valid timestamps.
    Error if end_time <= event_time.
    '''
    
    context = RequestContext(request)
    profile = UserProfile.objects.get(user_id=request.user.id)  
    
    if request.method == 'POST':
        form = EventForm(request.POST)

        if form.is_valid():
            note = form.save(commit=False)
            note.created_by = profile
            note.save()
            note.owners.add(profile)
            note.save()
            profile.events.add(Event.objects.get(id=note.id))
            profile.save()
            return index(request)
        else:
            print form.errors
    else:
        form = EventForm()
        
    return render_to_response('app/new_event.html', {'form': form}, context)
    def update(self, request, event):
        form = EventForm(request.user, data=request.POST, instance=event)

        if form.is_valid():
            form.save(request)
            messages.success(request, _("Inschrijflijst bijgewerkt!"))
            return redirect('event-edit', event.pk)
        else:
            return self.edit(request, event.pk, form=form)
    def store(self, request):
        form = EventForm(request.user, data=request.POST)

        if form.is_valid():
            event = form.save(request)

            messages.success(request, _("Inschrijflijst aangemaakt!"))
            return redirect('event-detail', event.pk)
        else:
            return self.create(request, form=form)
Beispiel #4
0
def event_form(request,pk):
    user = get_object_or_404(User,pk=pk)
    if request.method == 'POST':
        form = EventForm(request.POST,request.FILES)
        if form.is_valid():
            eventform=form.save(commit=False)
            eventform.user = user
            eventform.save()
            return redirect('app:event_detail', pk=user.pk)
    else:
        form = EventForm()


    return render(request,'app/user_event_form.html',{'form':form,
                                                        'user':user,})
Beispiel #5
0
def add_event(request):
    """Renders the page to add event"""
    assert isinstance(request, HttpRequest)
    _create_session(request)
    form = EventForm()
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            form.cleaned_data['session_key'] = Session.objects.get(
                session_key=request.session.session_key)
            form.save()
            messages.success(request, 'Event has been added.')
            return HttpResponseRedirect('/')
        elif any(coordinate in form.errors
                 for coordinate in ['latitude', 'longitude']):
            messages.error(request, 'The Geolocation service is required.')
    return render(request, 'app/add_event.html', {'form': form})
Beispiel #6
0
def edit_event(request, eid=None):
    instance = Event() if not eid else get_object_or_404(Event, pk=eid)
    form = EventForm(request.POST or None, instance=instance)
    form.fields['patient'].queryset = Patient.objects.newest(request.user)
    form.fields['procedures'].queryset = Procedure.objects.newest(request.user)

    if 'term' in request.GET:
        pattern = request.GET.get('term')
        medications = Event.objects.medication_list(pattern, request.user)
        return JsonResponse(medications, safe=False)

    if request.POST:
        if 'delete' in request.POST:
            Event.objects.delete(eid)
            return HttpResponseRedirect(reverse('calendar'))
        elif 'save' in request.POST and form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('calendar'))
    return render(request, 'edit_form.html', {'form': form})
Beispiel #7
0
def add_event(request):
	# A HTTP POST?
	if request.method == 'POST':
		form = EventForm(request.POST)

		if form.is_valid():
			# Save the new event to the database.
			form.save(commit=True)
			# Now call the index() view.
			# The user will be shown the homepage.
			return index(request)
		else:
			# The supplied form contained errors - just print them to the terminal.
			print form.errors
	else:
		# If the request was not a POST, display the form to enter details.
		form = EventForm()
	# Bad form (or form details), no form supplied...
	# Render the form with error messages (if any).
	return render(request, 'app/add_event.html', {'form': form})
Beispiel #8
0
def book(request, booking):
    """Allows a user to create an event. The event is not confirmed and will only display on the book page. The customer is created along with the booking."""
    bookingType = booking
    data = dict()
    assert isinstance(request, HttpRequest)

    if request.method == 'POST':

        form = EventForm(venue=Venue.VENUE_TYPE_MAP[booking],
                         data=request.POST)
        customerForm = CustomerForm(request.POST)
        if all([form.is_valid(), customerForm.is_valid()]):
            customer = customerForm.save()
            event = form.save(commit=False)
            event.customer = customer
            event.created = timezone.now()
            event.save()
            #contact venue with the event details
            contact_venue_on_booking(event, customer, request)
            contact_customer_on_booking(event, customer)
            data['form_is_valid'] = True
        else:
            data['form_is_valid'] = False
    else:
        form = EventForm(venue=Venue.VENUE_TYPE_MAP[booking])
        customerForm = CustomerForm()

    allEvents = []
    allVenues = []
    allColors = []
    #filter dates today or later
    today = timezone.now()
    venues = Venue.objects.filter(venue_type=Venue.VENUE_TYPE_MAP[booking])
    for currentVenue in venues:
        #get all events for each venue type
        #annotate will rename 'venue__color' to 'color
        packages = Event.objects.annotate(
            color=F('venue__color'),
            editable=F('confirmed'),
            type=F('event_type')).filter(venue=currentVenue.id).filter(
                start__gte=today).all().values('id', 'title', 'start',
                                               'venue__name',
                                               'venue__venue_type', 'type',
                                               'color', 'editable')
        if packages.exists():
            eventGroup = []
            for package in packages:
                package['editable'] = not package['editable']  #flip the value
                package['type'] = Event.EVENT_TYPES[package['type'] - 1][
                    1]  #event type for details popup
                package['start'] = normalize(
                    package['start'])  #convert UTC time to eastern
                if package['editable'] == True:
                    package['borderColor'] = "red"
                    package['title'] = "Tentative"
                eventGroup.append(package)
                #store list of all distinct venues for choicespartial
                if (currentVenue.id, package['venue__name']) not in allVenues:
                    allVenues.append((currentVenue.id, package['venue__name']))
                    allColors.append(currentVenue.color)
            json_obj = dict(events=eventGroup)
            allEvents.append(json_obj)
    zipData = zip(
        allVenues,
        allColors)  #zip the event types and colors together for template
    if request.method == 'GET':
        return render(
            request, 'app/book.html', {
                'form': EventForm(venue=Venue.VENUE_TYPE_MAP[booking]),
                'customerForm': CustomerForm(),
                'editDateForm': EditDateForm(),
                'events': json.dumps(allEvents, default=str),
                'title': 'Book',
                'year': datetime.now().year,
                'booking': bookingType,
                'extra_context': zipData
            })
    elif request.method == 'POST':
        context = {'form': form, 'customerForm': customerForm}
        data['html_form'] = render_to_string('app/partial_book_create.html',
                                             context,
                                             request=request)
        data['updated_events'] = json.dumps(allEvents, default=str)
        return JsonResponse(data)