Esempio n. 1
0
def delete_post(request, post_id, topic_id):
	"""
	delete a post
	
	* post_id - ID of a Post entry
	* topic_id - Topic entry ID that contain the Post entry
	"""
	try:
		topic = Topic.objects.get(id=topic_id)
		request.forum_id = topic.forum.id
		perms = forumContext(request)
	except:
		return HttpResponseRedirect(reverse('diamandas.myghtyboard.views.category_list', kwargs={}))
	
	if perms['perms']['is_staff']:
		Post.objects.get(id=post_id).delete()
		topic.posts = topic.posts -1
		if topic.posts > 0:
			topic.save()
			return redirect_by_template(request, reverse('diamandas.myghtyboard.views.post_list', kwargs={'pagination_id': 1, 'topic_id': topic_id}), _('Post deleted succesfuly.'))
		else:
			fid = topic.forum.id
			topic.delete()
			return redirect_by_template(request, reverse('diamandas.myghtyboard.views.topic_list', kwargs={'forum_id': fid}), _('Topic deleted succesfuly.'))
	else:
		return render_to_response('bug.html', {'bug': _('You aren\'t a moderator')}, context_instance=RequestContext(request, forumContext(request)))
Esempio n. 2
0
def edit_post(request, post_id):
	"""
	edit post
	
	* post_id - id of a Post entry
	"""
	
	post = Post.objects.get(id=post_id)
	topic = Topic.objects.get(id=post.topic.id)
	forum = Forum.objects.get(id=topic.forum.id)
	request.forum_id = forum.id
	perm = permshelpers.cant_edit_post(request, topic.is_locked, post.author)
	if perm:
		return perm
	
	if request.POST and len(request.POST.copy()['text']) > 1:
		page_data = request.POST.copy()
		post.text = page_data['text']
		post.save()
		
		pmax = Post.objects.filter(topic=post.topic).count()/10
		pmaxten =  Post.objects.filter(topic=post.topic).count()%10
		if pmaxten != 0:
			pmax = pmax+1
		return redirect_by_template(request, reverse('diamandas.myghtyboard.views.post_list', kwargs={'pagination_id': pmax, 'topic_id': post.topic.id}), _('Post edited succesfuly.'))
	else:
		return render_to_response(
			'myghtyboard/edit_post.html',
			{'forum': forum, 'topic': topic, 'text': post.text, 'post_id': post_id},
			context_instance=RequestContext(request, forumContext(request)))
Esempio n. 3
0
def my_posttopic_list(request, show_user=False):
	"""
	list topics with my posts
	
	* show_user - if not set will show current user topics
	"""
	if not show_user:
		show_user = unicode(request.user)
	try:
		topics = Post.objects.order_by('-date').filter(author=show_user).values('topic').distinct()[:50]
		posts = []
		for i in topics:
			posts.append(int(i['topic']))
		topics = Topic.objects.order_by('-modification_date').filter(id__in=posts)
		for i in topics:
			pmax =  i.post_set.all().count()/10
			pmaxten =  i.post_set.all().count()%10
			if pmaxten != 0:
				i.pagination_max = pmax+1
			else:
				i.pagination_max = pmax
		name = _('User Posts in Latest Topics')
	except:
		return render_to_response('myghtyboard/mytopics_list.html', {}, context_instance=RequestContext(request, forumContext(request)))
	return render_to_response(
		'myghtyboard/mytopics_list.html',
		{'topics': topics, 'name': name},
		context_instance=RequestContext(request, forumContext(request)))
Esempio n. 4
0
def move_topic(request, topic_id, forum_id):
	"""
	move topic
	
	* topic_id - ID of a Topic entry
	* forum_id - ID of a Forum entry that contain the Topic entry
	"""
	request.forum_id = forum_id
	perms = forumContext(request)
	
	if perms['perms']['is_staff']:
		if request.POST and len(request.POST['forum']) > 0:
			topic = Topic.objects.get(id=topic_id)
			topic.forum=Forum.objects.get(id=request.POST['forum'])
			topic.save()
			t = Topic(
				forum=Forum.objects.get(id=forum_id),
				name = topic.name,
				author = topic.author,
				posts = 0,
				lastposter = _('Topic Moved'),
				is_locked = True)
			t.save()
			p = Post(
				topic = t,
				text = _('This topic has been moved to another forum. To see the topic follow')
					 + ' [url=' + reverse('diamandas.myghtyboard.views.post_list', kwargs={'pagination_id': 1, 'topic_id': topic_id}) + ']' + _('this link') + '[/url]',
				author = _('Forum Staff'),
				ip = str(request.META['REMOTE_ADDR']))
			p.save()
			return redirect_by_template(request, reverse('diamandas.myghtyboard.views.topic_list', kwargs={'forum_id': forum_id}), _('Topic moved succesfuly.'))
		else:
			forums = Forum.objects.exclude(id=forum_id)
			topic = Topic.objects.get(id=topic_id)
			return render_to_response(
				'myghtyboard/move_topic.html',
				{'forums': forums, 'topic': topic},
				context_instance=RequestContext(request, forumContext(request)))
	else:
		return render_to_response('bug.html',
			{'bug': _('You aren\'t a moderator')},
			context_instance=RequestContext(request, forumContext(request))
			)
Esempio n. 5
0
def unsolve_topic(request, topic_id, forum_id):
	"""
	marks topic as unsolved
	
	* topic_id - ID of a Topic entry
	* forum_id - ID of a Forum entry that contain the Topic entry
	"""
	topic = Topic.objects.get(id=topic_id)
	request.forum_id = forum_id
	perms = forumContext(request)
	
	if perms['perms']['is_staff'] or perms['perms']['is_authenticated'] and topic.author == str(request.user):
		topic.is_solved=False
		topic.save()
		return redirect_by_template(request, reverse('diamandas.myghtyboard.views.topic_list', kwargs={'forum_id': forum_id}), _('Topic unsolved.'))
	else:
		return render_to_response('bug.html',
			{'bug': _('You aren\'t a moderator or topic author and you aren\'t logged in')},
			context_instance=RequestContext(request, forumContext(request))
			)
Esempio n. 6
0
def open_topic(request, topic_id, forum_id):
	"""
	open topic
	
	* topic_id - ID of a Topic entry
	* forum_id - ID of a Forum entry that contain the Topic entry
	"""
	request.forum_id = forum_id
	perms = forumContext(request)
	
	if perms['perms']['is_staff']:
		topic = Topic.objects.get(id=topic_id)
		topic.is_locked=False
		topic.save()
		return redirect_by_template(request, reverse('diamandas.myghtyboard.views.topic_list', kwargs={'forum_id': forum_id}), _('Topic opened succesfuly.'))
	else:
		return render_to_response('bug.html',
			{'bug': _('You aren\'t a moderator and you aren\'t logged in')},
			context_instance=RequestContext(request, forumContext(request))
			)
Esempio n. 7
0
def cant_edit_post(request, topic_is_locked, post_author):
    perms = forumContext(request)
    if str(request.user) != post_author and not perms['perms']['is_staff']:
        return render_to_response('pages/bug.html',
                                  {'bug': _('You can\'t edit a post.')},
                                  context_instance=RequestContext(
                                      request, perms))
    if topic_is_locked:
        return render_to_response('pages/bug.html',
                                  {'bug': _('Topic is closed')},
                                  context_instance=RequestContext(
                                      request, perms))
    return False
Esempio n. 8
0
def cant_add_topic(request):
	perms = forumContext(request)
	if not perms['perms']['add_topic'] and not perms['perms']['is_spam']:
		return render_to_response('pages/bug.html',
			{'bug': _('You can\'t add a topic.')},
			context_instance=RequestContext(request, perms)
			)
	if not perms['perms']['add_topic'] and perms['perms']['is_spam']:
		return render_to_response('pages/bug.html',
			{'bug': _('To many anonymous posts. Login to post topics and new messages.')},
			context_instance=RequestContext(request, perms)
			)
	return False
Esempio n. 9
0
def cant_edit_post(request, topic_is_locked, post_author):
	perms = forumContext(request)
	if str(request.user) != post_author and not perms['perms']['is_staff']:
		return render_to_response('pages/bug.html',
			{'bug': _('You can\'t edit a post.')},
			context_instance=RequestContext(request, perms)
			)
	if topic_is_locked:
		return render_to_response('pages/bug.html',
			{'bug': _('Topic is closed')},
			context_instance=RequestContext(request, perms)
			)
	return False
Esempio n. 10
0
def my_topic_list(request, show_user=False):
	"""
	list my topics
	
	* show_user - if not set will show current user topics
	"""
	if not show_user:
		show_user = unicode(request.user)
	topics = Topic.objects.order_by('-modification_date').filter(author=show_user)[:50]
	name = _('User Topics')
	return render_to_response(
		'myghtyboard/mytopics_list.html',
		{'topics': topics, 'name': name},
		context_instance=RequestContext(request, forumContext(request)))
Esempio n. 11
0
def cant_add_topic(request):
    perms = forumContext(request)
    if not perms['perms']['add_topic'] and not perms['perms']['is_spam']:
        return render_to_response('pages/bug.html',
                                  {'bug': _('You can\'t add a topic.')},
                                  context_instance=RequestContext(
                                      request, perms))
    if not perms['perms']['add_topic'] and perms['perms']['is_spam']:
        return render_to_response('pages/bug.html', {
            'bug':
            _('To many anonymous posts. Login to post topics and new messages.'
              )
        },
                                  context_instance=RequestContext(
                                      request, perms))
    return False
Esempio n. 12
0
def last_topic_list(request):
	"""
	 list last active topics
	"""
	topics = Topic.objects.order_by('-modification_date')[:50]
	for i in topics:
		pmax =  i.post_set.all().count()/10
		pmaxten =  i.post_set.all().count()%10
		if pmaxten != 0:
			i.pagination_max = pmax+1
		else:
			i.pagination_max = pmax
	name = _('Last Active Topics')
	return render_to_response(
		'myghtyboard/mytopics_list.html',
		{'topics': topics, 'name': name},
		context_instance=RequestContext(request, forumContext(request)))
Esempio n. 13
0
def category_list(request):
	"""
	show all categories and their topics
	"""
	categories = Category.objects.all().order_by('order')
	for c in categories:
		#{% if forum.mods %}<u>{% trans "Moderators" %}</u>:
		#        {% for i in forum.mods %}
		#               {{ i.username }}{% if not forloop.last %},{% endif %} 
		#        {% endfor %}
		#{% endif %}
		#forum = c.forum_set.all().order_by('order')
		#forums = []
		#for f in forum:
		#	f.mods = f.moderators.all()
		#	forums.append(f)
		c.forums = c.forum_set.all().order_by('order')
	return render_to_response(
		'myghtyboard/category_list.html',
		{'categories': categories},
		context_instance=RequestContext(request, forumContext(request)))
Esempio n. 14
0
def delete_topic(request, topic_id, forum_id):
	"""
	delete a topic with all posts
	
	* topic_id - ID of a Topic entry
	* forum_id - ID of a Forum entry that contain the Topic entry
	"""
	request.forum_id = forum_id
	perms = forumContext(request)
	
	if perms['perms']['is_staff']:
		posts = Post.objects.filter(topic=topic_id).count()
		t = Topic.objects.get(id=topic_id)
		if t.forum.id != int(forum_id):
			return render_to_response('bug.html', {'bug': _('Invalid Forum/Topic')}, context_instance=RequestContext(request, forumContext(request)))
		t.delete()
		Post.objects.filter(topic=topic_id).delete()
		forum = Forum.objects.get(id=forum_id)
		forum.topics = forum.topics -1
		forum.posts = forum.posts - posts
		forum.save()
		return redirect_by_template(request, reverse('diamandas.myghtyboard.views.topic_list', kwargs={'forum_id': forum_id}), _('Topic deleted succesfuly.'))
	else:
		return render_to_response('bug.html', {'bug': _('You aren\'t a moderator')}, context_instance=RequestContext(request, forumContext(request)))
Esempio n. 15
0
def add_post(request, topic_id, post_id = False):
	"""
	add post
	
	* topic_id - id of a Topic entry
	* post_id - id of a Post entry to be quoted, optional
	"""
	try:
		topic = Topic.objects.get(id=topic_id)
		forum = Forum.objects.get(id=topic.forum.id)
	except:
		return HttpResponseRedirect(reverse('diamandas.myghtyboard.views.category_list', kwargs={}))
	
	request.forum_id = forum.id
	perm = permshelpers.cant_add_post(request, topic.is_locked)
	if perm:
		return perm
	
	try:
		# check who made the last post.
		lastpost = Post.objects.order_by('-date').filter(topic=topic_id)[:2]
		# if the last poster is the current one (login) and he isn't staff then we don't let him post after his post (third post)
		if unicode(lastpost[0].author) == unicode(request.user) and unicode(lastpost[1].author) == unicode(request.user) and not is_staff:
			return render_to_response('bug.html',
				{'bug': _('You can\'t post after your post')},
				context_instance=RequestContext(request, forumContext(request))
				)
	except:
		pass
	
	lastpost = Post.objects.filter(topic=topic_id).order_by('-id')[:10]
	if request.POST:
		stripper = Stripper()
		page_data = request.POST.copy()
		# block anonymous messages with multiple links
		perms = forumContext(request)
		if not perms['perms']['is_authenticated'] and page_data['text'].count('http') > 1:
			return render_to_response('bug.html',
				{'bug': _('To many links. Is this spam?.')},
				context_instance=RequestContext(request, perms)
				)
		if perms['perms']['is_authenticated']:
			page_data['author'] = unicode(request.user)
			author = unicode(request.user)
			page_data['author_system'] = request.user.id
		else:
			if 'nick' in page_data and unicode(stripper.strip(page_data['nick'])) > 2:
				author = stripper.strip(page_data['nick'])[0:14]
				page_data['author'] = author
				page_data['author_anonymous'] = 1
			else:
				page_data['author'] = _('Anonymous')
				author = _('Anonymous')
				page_data['author_anonymous'] = 1
		page_data['ip'] = request.META['REMOTE_ADDR']
		page_data['topic'] = topic_id
		page_data['date'] = datetime.now()
		
		
		if request.user.is_authenticated():
			chck = Post.objects.filter(author_system=request.user).count()
		else:
			chck = 0
		if chck < 5 and settings.FORUM_USE_RECAPTCHA:
			form = AddPostWithCaptchaForm(page_data)
		else:
			form = AddPostForm(page_data)
		
		if form.is_valid():
			form.save()
		
			posts = Post.objects.filter(topic=topic_id).count()
			
			pmax =  posts/10
			pmaxten =  posts%10
			if pmaxten != 0:
				pmax = pmax+1
				topic.last_pagination_page = pmax
			elif pmax > 0:
				topic.last_pagination_page = pmax
			else:
				pmax = 1
				topic.last_pagination_page = 1
			topic.posts = posts
			topic.lastposter = author
			topic.modification_date = datetime.now()
			topic.save()
			
			forum.posts = forum.posts +1
			forum.lastposter = author
			
			if len(topic.name) > 25:
				tname = topic.name[0:25] + '...'
			else:
				tname = topic.name
				
			forum.lasttopic = '<a href="' + reverse('diamandas.myghtyboard.views.post_list', kwargs={'pagination_id': pmax, 'topic_id': topic.id}) + '">' + tname + '</a>'
			forum.modification_date = datetime.now()
			forum.save()
			
			if settings.NOTIFY_ADMINS:
				mail_admins(
					_('Post Added'),
					_('Post Added') + settings.SITE_DOMAIN + reverse('diamandas.myghtyboard.views.post_list', kwargs={'pagination_id': pmax, 'topic_id': topic.id}),
					fail_silently=True
					)
			
			return redirect_by_template(request, reverse('diamandas.myghtyboard.views.post_list', kwargs={'pagination_id': pmax, 'topic_id': topic.id}), _('Post added succesfuly.'))
		else:
			return render_to_response(
				'myghtyboard/add_post.html',
				{'forum': forum, 'topic': topic, 'lastpost': lastpost, 'form':form},
				context_instance=RequestContext(request, forumContext(request)))
	else:
		if post_id:
			quote = Post.objects.get(id=post_id)
			quote_text = '[quote][b]' + quote.author + _(' wrote') + ':[/b]\n\r' + quote.text + '[/quote]\n\r'
		else:
			quote_text = ''
	
	
	
	if request.user.is_authenticated():
		chck = Post.objects.filter(author_system=request.user).count()
	else:
		chck = 0
	if chck < 5 and settings.FORUM_USE_RECAPTCHA:
		form = AddPostWithCaptchaForm()
	else:
		form = AddPostForm()
	
	return render_to_response(
		'myghtyboard/add_post.html',
		{'forum': forum, 'topic': topic, 'quote_text': quote_text, 'lastpost': lastpost, 'form':form},
		context_instance=RequestContext(request, forumContext(request)))
Esempio n. 16
0
def add_topic(request, forum_id):
	"""
	add topic
	
	* forum_id - ID of a Forum entry
	"""
	request.forum_id = forum_id
	perm = permshelpers.cant_add_topic(request)
	if perm:
		return perm
	
	forum = Forum.objects.get(id=forum_id)
	
	pr = False
	if forum.use_prefixes:
		p = Prefix.objects.filter(forums=forum)
		if len(p) > 0:
			pr = []
			for i in p:
				pr.append(i)
	
	if request.POST:
		stripper = Stripper()
		page_data = request.POST.copy()
		text = page_data['text']
		
		# block anonymous messages with multiple links
		perms = forumContext(request)
		if not perms['perms']['is_authenticated'] and text.count('http') > 1:
			return render_to_response('bug.html',
				{'bug': _('To many links. Is this spam?.')},
				context_instance=RequestContext(request, perms)
				)
		if 'prefix[]' in page_data:
			prefixes = page_data.getlist("prefix[]")
			pr = Prefix.objects.filter(id__in=prefixes)
			page_data['prefixes'] = ''
			for p in pr:
				page_data['prefixes'] = '%s[%s] ' % (page_data['prefixes'], p.name)
			
			del page_data['prefix[]']
		
		page_data['name'] = stripper.strip(page_data['name'])
		page_data['forum'] = forum_id
		page_data['posts'] = 1
		if perms['perms']['is_authenticated']:
			page_data['lastposter'] = unicode(request.user)
			page_data['author'] = unicode(request.user)
			author = unicode(request.user)
			page_data['author_system'] = request.user.id
		else:
			if 'nick' in page_data and len(stripper.strip(page_data['nick'])) > 2:
				author = stripper.strip(page_data['nick'])[0:14]
				page_data['lastposter'] = author
				page_data['author'] = author
				page_data['author_anonymous'] = 1
			else:
				page_data['lastposter'] = _('Anonymous')
				page_data['author'] = _('Anonymous')
				author = _('Anonymous')
				page_data['author_anonymous'] = 1
		page_data['last_pagination_page'] = 1
		page_data['modification_date'] = datetime.now()
		
		if request.user.is_authenticated():
			chck = Post.objects.filter(author_system=request.user).count()
		else:
			chck = 0
		if chck < 5 and settings.FORUM_USE_RECAPTCHA:
			form = AddTopicWithCaptchaForm(page_data)
		else:
			form = AddTopicForm(page_data)
		
		if form.is_valid():
			new_place = form.save()
			if 'prefixes' in page_data:
				tp = TopicPrefix(topic=new_place)
				tp.save()
				tp.prefix=pr
				tp.save()
			
			post = Post(topic = new_place, text = text, author = author, ip = request.META['REMOTE_ADDR'])
			if 'author_anonymous' in page_data:
				post.author_anonymous = True
			else:
				post.author_system = request.user
			post.save()
			
			forum.topics = forum.topics +1
			forum.posts = forum.posts +1
			forum.lastposter = author
			if len(new_place.name) > 25:
				tname = new_place.name[0:25] + '...'
			else:
				tname = new_place.name
			forum.lasttopic = '<a href="' + reverse('diamandas.myghtyboard.views.post_list', kwargs={'pagination_id': 1, 'topic_id': new_place.id}) + '/">' + tname + '</a>'
			forum.modification_date = datetime.now()
			forum.save()
			if settings.NOTIFY_ADMINS:
				mail_admins(_('Topic Added'), _('Topic added') + settings.SITE_DOMAIN + reverse('diamandas.myghtyboard.views.topic_list', kwargs={'forum_id': forum_id}), fail_silently=True)
			
			return redirect_by_template(request, reverse('diamandas.myghtyboard.views.topic_list', kwargs={'forum_id': forum_id}), _('Topic added succesfuly.'))
		else:
			return render_to_response(
				'myghtyboard/add_topic.html',
				{'form': form, 'forum': forum, 'pr': pr},
				context_instance=RequestContext(request, forumContext(request)))
	
	if request.user.is_authenticated():
		chck = Post.objects.filter(author_system=request.user).count()
	else:
		chck = 0
	if chck < 5 and settings.FORUM_USE_RECAPTCHA:
		form = AddTopicWithCaptchaForm()
	else:
		form = AddTopicForm()
	return render_to_response(
		'myghtyboard/add_topic.html',
		{'form': form, 'forum': forum, 'pr': pr},
		context_instance=RequestContext(request, forumContext(request)))
Esempio n. 17
0
def show(request, slug):
	"""
	show Content entry
	
	* slug - slug of a Content entry
	"""
	try:
		page = Content.objects.get(slug=slug)
	except Content.DoesNotExist:
		return render_to_response('pages/bug.html',
			{'bug': _('Page does not exist')},
			context_instance=RequestContext(request))
	
	add_topic = False
	if page.coment_forum:
		request.forum_id = page.coment_forum.id
		coment_forum_id = page.coment_forum.id
		perms = forumContext(request)
		if perms['perms']['add_topic']:
			add_topic = True
	elif page.place and page.place.coment_forum:
		request.forum_id = page.place.coment_forum.id
		coment_forum_id = page.place.coment_forum.id
		perms = forumContext(request)
		if perms['perms']['add_topic']:
			add_topic = True
	
	if add_topic and not page.coment_topic:
		form = diamandaModelwrappers.AddTopicForm()
	elif add_topic and page.coment_topic:
		form = diamandaModelwrappers.AddPostForm()
	else:
		form = False
	
	comments = False
	# check if user wants to add a comment - show the form if possible
	if 'c' in request.GET:
		show_comment = True
		if form and page.coment_topic:
			comments = page.coment_topic.post_set.all().order_by('-id')[:10]
	else:
		show_comment = False
	
	if request.POST and add_topic and not page.coment_topic:
		COMMENT_POST = _('This is a discussion about article') + ': [url=/w/p/%s/]%s[/url].' % (page.slug, page.title)
		REDIRECT = ("/w/p/" + slug +"/?c=ok", _('Comment added succesfuly.'))
		TITLE = _('Comments for: %s') % page.title
		return diamandaModelwrappers.add_topic(request, coment_forum_id, inject_post=COMMENT_POST, inject_title=TITLE, redirect_link=REDIRECT, content_obj=page)
	elif request.POST and add_topic and page.coment_topic:
		REDIRECT = ("/w/p/" + slug +"/?c=ok", _('Comment added succesfuly.'))
		return diamandaModelwrappers.add_post(request, page.coment_topic.id, redirect_link=REDIRECT, content_obj=page)
	
	if page.current_book:
		cb = page.current_book
	
	if page.content_type == 'news':
		return render_to_response(
			'pages/show_news.html',
			{'page': page, 'add_topic': add_topic, 'form': form, 'show_comment': show_comment, 'comments': comments},
			context_instance=RequestContext(request, {'current_book': cb}))
	return render_to_response(
		'pages/show.html',
		{'page': page, 'add_topic': add_topic, 'form': form, 'show_comment': show_comment, 'comments': comments},
		context_instance=RequestContext(request, {'current_book': cb}))