Пример #1
0
def results(request, poll, url_title):
	if poll.start_date > datetime.date.today():
		# poll is not open
		raise Http404

	if request.user.has_perm(Poll.get_vote_permission(), poll) \
				and not poll.participants.filter(id=request.user.pk).exists() \
				and poll.end_date >= datetime.date.today():
		return vote(request, poll, url_title)

	if not poll.show_results_immediately and poll.end_date >= datetime.date.today():
		messages.info(
			request,
			_("You can not see the results of this poll right now. You have to wait until {} to see the results of this poll.".format(poll.end_date.strftime("%d. %B %Y")))
		)
		return HttpResponseRedirect(reverse('polls:index'))

	md = markdown.Markdown(safe_mode='escape', extensions=[TocExtension(baselevel=2), InternalLinksMarkdownExtension(), 'markdown.extensions.abbr'])
	description = md.convert(poll.text + abbreviation_explanation_markdown())

	return render(
		request,
		'polls_results.html',
		{
			"document": poll,
			"description": description,
			'toc': md.toc,
			'active_page': 'view',
			'view_page': True,
			'attachments': poll.attachments.filter(no_direct_download=False).order_by('index'),
			'permission_warning': permission_warning(request.user, poll),
		}
	)
Пример #2
0
def render_text(request, title):
	if request.method != 'POST':
		raise SuspiciousOperation

	document = get_object_or_404(Document, url_title=title)
	if document.has_perms():
		check_permissions(document, request.user, [document.view_permission_name, document.edit_permission_name])

	text = request.POST['text']
	md = markdown.Markdown(safe_mode='escape', extensions=[TocExtension(baselevel=2), InternalLinksMarkdownExtension(), 'markdown.extensions.abbr'])
	text = md.convert(text + abbreviation_explanation_markdown())
	return HttpResponse(text, content_type='text/plain')
Пример #3
0
def vote(request, poll, url_title):
	if poll.start_date > datetime.date.today():
		# poll is not open
		raise Http404

	if poll.end_date < datetime.date.today() or poll.participants.filter(id=request.user.pk).exists():
		return results(request, poll, url_title)

	if request.method == 'POST':
		choices = request.POST.getlist('choice')
		if len(choices) == 0:
			messages.error(request, _("You must select one Choice at least!"))
			return HttpResponseRedirect(reverse(poll.get_view_url_name(), args=[url_title]))
		if len(choices) > poll.max_allowed_number_of_answers:
			messages.error(request, _("You can only select up to {} options!").format(poll.max_allowed_number_of_answers))
			return HttpResponseRedirect(reverse(poll.get_view_url_name(), args=[url_title]))

		for choice_id in choices:
			choice = poll.choices.filter(id=choice_id)
			choice.update(votes=F('votes') + 1)

		poll.participants.add(request.user)
		messages.success(request, _("We've received your vote!"))
		if not poll.show_results_immediately:
			messages.info(request, _("The results of this poll will be available as from {}".format((poll.end_date + datetime.timedelta(days=1)).strftime("%d. %B %Y"))))
			return HttpResponseRedirect(reverse('polls:index'))
		return HttpResponseRedirect(reverse(poll.get_view_url_name(), args=[url_title]))

	md = markdown.Markdown(safe_mode='escape', extensions=[TocExtension(baselevel=2), InternalLinksMarkdownExtension(), 'markdown.extensions.abbr'])
	description = md.convert(poll.text + abbreviation_explanation_markdown())

	return render(
		request,
		'polls_vote.html',
		{
			"document": poll,
			"description": description,
			'toc': md.toc,
			'active_page': 'view',
			'view_page': True,
			"widget": "checkbox" if poll.max_allowed_number_of_answers != 1 else "radio",
			'attachments': poll.attachments.filter(no_direct_download=False).order_by('index'),
			'permission_warning': permission_warning(request.user, poll),
		}
	)
Пример #4
0
def index(request):
	try:
		document = Document.objects.get(id=settings.MAIN_PAGE_ID)
		return HttpResponseRedirect(reverse('documents:view', args=[document.url_title]))

		md = markdown.Markdown(safe_mode='escape', extensions=[TocExtension(baselevel=2), 'markdown.extensions.abbr'])
		text = md.convert(document.text + abbreviation_explanation_markdown())

		template = 'information_pages_base.html' if document.polymorphic_ctype.model == 'informationdocument' else 'minutes_base.html'
		return render(request, template, {
			'document': document,
			'text': text,
			'toc': md.toc,
			'attachments': document.attachments.filter(no_direct_download=False).order_by('index'),
			'active_page': 'view',
			'permission_warning': permission_warning(request.user, document),
		})
	except ObjectDoesNotExist:
		# nobody created a mainpage yet -> show default main page
		return render(request, 'index.html')
Пример #5
0
def view(request, title):
	document = get_object_or_404(Document, url_title=title)
	content_type = ContentType.objects.get_for_model(document)
	check_permissions(document, request.user, [document.view_permission_name])

	try:
		function = get_model_function(content_type, 'view')
		return function(request, title)
	except (ImportError, AttributeError):
		pass

	md = markdown.Markdown(safe_mode='escape', extensions=[TocExtension(baselevel=2), InternalLinksMarkdownExtension(), 'markdown.extensions.abbr'])
	text = md.convert(document.text + abbreviation_explanation_markdown())

	return render(request, 'documents_base.html', {
		'document': document,
		'text': text,
		'toc': md.toc,
		'attachments': document.attachments.filter(no_direct_download=False).order_by('index'),
		'active_page': 'view',
		'permission_warning': permission_warning(request.user, document),
	})