Exemplo n.º 1
0
def plan_comment_add(request, *args, **kwargs):
	goal = args[0]
	plan = args[1]
	
	comment = Comment(plan = plan)
	form = CommentForm(request.POST, instance = comment)
	
	if form.is_valid():
		comment = form.save(commit = False)
		comment.ip = request.META.get('REMOTE_ADDR')
		comment.user_agent = request.META.get('HTTP_USER_AGENT')
		comment.save()
		
		return HttpResponseRedirect(
			'%s?msg=%s' % (
				reverse(
					'user_plan_logbook', args = [goal.slug, plan.user.username]
				),
				'Your comment is awaiting approval.'
			)
		)
	
	return render_to_response(
		'plan/error.html',
		{
			'goal': goal,
			'user': plan.user,
			'plan': plan
		},
		RequestContext(request)
	)
Exemplo n.º 2
0
def plan_logbook(request, *args, **kwargs):
	goal = args[0]
	plan = args[1]
	
	forms = []
	extra_context = {}
	
	if request.user != plan.user:
		comment = Comment(plan = plan)
		if request.user.is_authenticated():
			comment.name = request.user.get_full_name() or request.user.username
			comment.email = request.user.email
			
			try:
				profile = request.user.get_profile()
				comment.website = profile.website
			except Profile.DoesNotExist:
				pass
		
		forms.append(CommentForm(instance = comment))
		action = reverse(
			'plan_comment_add', args = [
				goal.slug, plan.user.username
			]
		)
		
		extra_context['meta_title'] = (
			'%s\'s %s logbook' % (
				plan.user.username, goal.name
			)
		)
	
	elif request.user.is_authenticated():
		for form_class in (ActionEntryForm, LogEntryForm):
			forms.append(
				form_class(
					instance = form_class._meta.model(
						plan = plan
					)
				)
			)
		
		action = reverse('plan_logbook_add', args = [goal.slug])
		extra_context.update(
			{
				'actions_serialized': helpers.serialise_actions(plan),
				'measurements_serialized': helpers.serialise_measurements(),
				'greeting': helpers.get_greeting(request),
				'meta_title': (
					'%s\'s %s logbook' % (plan.user.username, goal.name)
				)
			}
		)
	else:
		return HttpResponseRedirect(
			reverse('start_plan', args = [goal])
		)
	
	if request.user != plan.user:
		entries = plan.log_entries.approved()
	else:
		entries = plan.log_entries.not_spam()
	
	entries = helpers.paginated(entries, request)
	
	if request.user != plan.user:
		try:
			profile = get_object_or_404(
				Profile, user = plan.user
			)
			
			if not profile.public:
				from django.conf import settings
				return HttpResponseRedirect(
					'%s?next=%s' % (
						getattr(settings, 'LOGIN_URL'), request.path
					)
				)
			
			user = profile.user
			if profile.gender == 'm':
				gender = 'he'
			elif profile.gender == 'f':
				gender = 'she'
			else:
				gender = 'they'
		except Profile.DoesNotExist:
			raise Http404()
		
		next_milestone = None
	else:
		from datetime import datetime
		gender = None
		
		milestones = plan.milestones.filter(
			deadline__gt = datetime.now(),
			reached__isnull = True
		)[:1]
		
		if milestones.count() > 0:
			next_milestone = milestones[0]
		else:
			next_milestone = None
	
	extra_context.update(
		{
			'goal': goal,
			'plan': plan,
			'forms': forms,
			'entries': entries,
			'user': plan.user,
			'gender': gender,
			'next_milestone': next_milestone,
			'action': action
		}
	)
	
	return render_to_response(
		'plan/logbook.html',
		extra_context,
		RequestContext(request)
	)