예제 #1
0
def edit_plan(request, *args, **kwargs):
	goal = args[0]
	plan = args[1]
	next = reverse('plan_logbook', args = [goal.slug])
	
	if request.method == 'GET':
		form = PlanForm(instance = plan)
	else:
		form = PlanForm(request.POST, instance = plan)
		if form.is_valid():
			plan = form.save()
			request.user.message_set.create(
				message = 'Your plan has been updated.'
			)
			
			from django.conf import settings
			return HttpResponseRedirect(
				request.POST.get('next', next)
			)
	
	return render_to_response(
		'plan/edit.html',
		{
			'forms': [form],
			'goal': goal,
			'plan': plan,
			'next': next,
			'meta_title': ('Edit your %s plan' % goal.name,)
		},
		RequestContext(request)
	)
예제 #2
0
def start_plan(request, goal):
	if request.user.is_anonymous():
		if request.method == 'GET':
			signup_form = SignupForm(prefix = 'signup')
			return render_to_response(
				'start.html',
				{
					'forms': [signup_form],
					'goal': goal
				},
				RequestContext(request)
			)
		else:
			signup_form = SignupForm(request.POST, prefix = 'signup')
			
			if signup_form.is_valid():
				profile = signup_form.save()
				profile.user.message_set.create(
					message = 'Your account has been created.'
				)
				
				from django.contrib.auth import login
				login(request, profile.user)
			else:
				return render_to_response(
					'start.html',
					{
						'forms': [signup_form],
						'goal': goal
					},
					RequestContext(request)
				)
	
	if goal.plans.filter(user = request.user, live = True).count() > 0:
		if request.method == 'POST' and request.POST.get('next'):
			return HttpResponseRedirect(
				request.POST.get('next')
			)
		else:
			return HttpResponseRedirect(
				reverse('edit_plan', args = [goal.slug])
			)
	
	plan = Plan(
		goal = goal,
		user = request.user
	)
	
	try:
		plan.original = goal.original_plan()	
	except Plan.DoesNotExist:
		pass
	
	from datetime import date, timedelta
	if plan.original and plan.original.deadline:
		plan.deadline = date.today() + timedelta(
			(
				plan.original.deadline - plan.original.started.date()
			).days
		)
	
	if request.method == 'GET':
		form = PlanForm(instance = plan)
	else:
		form = PlanForm(request.POST, instance = plan)
		if form.is_valid():
			plan = form.save()
			request.user.message_set.create(
				message = 'Your plan has been created.'
			)
			
			return HttpResponseRedirect(
				request.POST.get('next')
			)
	
	return render_to_response(
		'plan/edit.html',
		{
			'forms': [form],
			'goal': goal,
			'plan': plan,
			'next': reverse(
				'actions_edit',
				args = [plan.goal.slug]
			),
			'meta_title': (goal.name,)
		},
		RequestContext(request)
	)