Beispiel #1
0
def create(request):
	"""
	Renders a new event form or creates an event and 
	redirects to it.

	Template: 'said_event/create.html'
	* event_form
		The event form.

	"""
	context = RequestContext(request)
	data = {}

	if request.method == 'POST':
		user = request.user if request.user.is_authenticated() else User.objects.get(pk=-1)
		form = CreateEventForm(user=user, data=request.POST, files=request.FILES)
		if form.is_valid():
			event = form.save()

			if request.user.is_authenticated():
				Attendee.objects.create(
					attendee_id = request.user.id,
					event_id = event.id
				)

			return HttpResponseRedirect(reverse('said_events:event', kwargs={'event_id': event.id}))
	else:

		form = CreateEventForm()

	data['event_form'] = form

	return render_to_response('said_events/create.html', data, context_instance=context)
Beispiel #2
0
def edit(request, event_id):
	"""
	Edit/update an event.

	Template: 'said_events/edit.html'
	* event_form
		Instance of CreateEventForm with populated
		with the event's values.
	* event
		The event matching event_id.

	"""

	context = RequestContext(request)
	data = {}

	event = Event.objects.get(id=event_id)

	if not event.owner_id == request.user.id:
		return HttpResponseRedirect(reverse('said_events:event', kwargs={'event_id': event.id}))

	if request.method == 'POST':

		if request.POST.has_key('delete'):
			event.delete()
			return HttpResponseRedirect(reverse('said_user:profile'))

		user = request.user
		form = CreateEventForm(user=user, data=request.POST, files=request.FILES)
		if form.is_valid():
			event = form.save()
			return HttpResponseRedirect(reverse('said_events:event', kwargs={'event_id': event.id}))
	else:

		tags = ', '.join([tag.name for tag in event.tags.all()])

		tz = timezone.get_default_timezone()
		start_date = tz.normalize(event.start_date).strftime('%m/%d/%Y %I:%M %p')
		end_date = tz.normalize(event.end_date).strftime('%m/%d/%Y %I:%M %p')

		form = CreateEventForm(initial={ 
			'title': event.title,
			'location': event.location,
			'start_date': start_date,
			'end_date': end_date,
			'description': event.description,
			'hash_tag': event.hash_tag,
			'tags': tags,
			'event_id': event.id,
		})

	data['event_form'] = form
	data['event'] = event

	return render_to_response('said_events/edit.html', data, context_instance=context)