Пример #1
0
def resend_activation_key(request, user_id):
	user = get_object_or_404(User, pk=user_id)
	activation = get_object_or_None(ActivationKey, user=user)
	if not activation == None:
		# Cleaning database from unused objects
		activation.delete()
	if request.method == 'POST':
		form = ResendActivationKeyForm(request.POST)
		if not form.cleaned_data['email'] == user.email:
			messages.error(request, "E-mail address sent by you doesn't match \
			with address used to register this account.")
			return redirect(reverse('home'))
		if form.is_valid():
			t = loader.get_template('accounts/email/email_activation.html')
			ak = ActivationKey(user=user)
			ak.save()
			webmaster_email = get_config('WEBMASTER_EMAIL', '*****@*****.**')
			site_name = get_config('SITE_NAME', 'Trinitee application')
			c = Context({'new_user': user, 'activation_key': ak.key,
				'webmaster_email': webmaster_email, 'site_name': site_name,
				'server_name': request.get_host()})
			send_mail("E-mail activation at %s" % site_name, t.render(c),
				get_config('MAILER_ADDRESS', '*****@*****.**'),
				[email], fail_silently=False)
			messages.success(request, "An email has been sent \
			to the specified address with instructions on how to activate \
			your new account. If it doesn't arrive you can contact the forum \
			administrator at %s" % webmaster_email)
			return redirect(reverse('home'))
	else:
		form = ResendActivationKeyForm()
	return {'form': form}
Пример #2
0
def homepage(request):
	os, flavor = os_detect(request.META['HTTP_USER_AGENT'])
	flavor = '_' + flavor if flavor else ''
	latest_download = cache.get('homepage_latest_download_%s%s' % (os, flavor))
	if latest_download == None:
		latest_download = get_object_or_None(Release.objects.select_related(),
			platform__name='%s%s' % (os, flavor))
		cache.set('homepage_latest_download_%s%s' % (os, flavor),
			latest_download, 86400)
	news_forum_id = get_config('NEWS_FORUM', 1)
	news = cache.get('homepage_news')
	if news == None:
		news = list(Post.objects.filter(topic__forum=news_forum_id,
			topic__first_post__id=F('id')).order_by('-created_at'). \
				select_related()[:get_config('NEWS_ITEMS_ON_HOMEPAGE', 5)])
		cache.set('homepage_news', news)
	journal_forum_id = get_config('JOURNAL_FORUM', 2)
	journal = cache.get('homepage_journal')
	if journal == None:
		journal = list(Post.objects.filter(topic__forum=journal_forum_id,
			topic__first_post__id=F('id')).order_by('-created_at'). \
				select_related()[:get_config('JOURNAL_ITEMS_ON_HOMEPAGE', 5)])
		cache.set('homepage_journal', journal)
	return {'news': news, 'journal': journal, 'forum_id': news_forum_id,
		'latest_download': latest_download}
Пример #3
0
def post_vote(request, post_id, value):
	post = get_object_or_None(Post, pk=post_id)
	if post == None:
		return ("You tried to vote for unexisting post.", True)
	if post.author == request.user and not request.user.is_staff \
		and not not request.user.is_superuser:
		return ("You tried to vote for your own post.", False)
	karma, created = PostKarma.objects.get_or_create(post=post,
		user=request.user, defaults={'karma': value})
	""" refresh cache before incrementing karma counter """
	post.get_karma(force_refresh=True)
	if not created and not karma.karma == value:
		"""
			This actually works, so don't try to fix it.

			No really, don't.

			If you still don't believe me, the line below
			subtracts current karma value and adds new one.
		"""
		cache.incr('forums_karma_%s' % post_id, - karma.karma + value)
		karma.karma = value
		karma.save()
	return post