示例#1
0
def edit(request, key):
	"""Open the presentation editor screen
	Args:
		key (str): Presentation public key, default = None
	"""
	
	from main.views.themes import get_css

	try:
		presentation = Presentation.objects.get(key=key)
		
		# check if user is allowed to edit this presentation
		if presentation.can_edit(request.user):
			# get user data
			user_data = {
				"username": request.user.username,
				"first_name": request.user.first_name,
				"last_name": request.user.last_name,
			}
		else:
			raise ObjectDoesNotExist
	except ObjectDoesNotExist:
		return HttpResponseRedirect("/")

	return render_to_response("edit.html", {"theme_css": get_css(request, presentation.theme_id).content,
											"presentation": presentation,
											"user_data": user_data,
											"share_form": share(request, presentation.id).content if presentation.is_owner(request.user) else None,
											"form_change_options": ChangeOptionsForm(instance=presentation),
											"NODEJS_URL": settings.NODEJS_URL
										}, context_instance=RequestContext(request))
示例#2
0
def view(request, key):
	"""Shows the presentation"""

	# get the presentation based on its key
	presentation = Presentation.objects.get(key = key)

	if presentation.is_private:
		if not presentation.is_allowed(request.user):
			raise Http404
	
	from main.views.themes import get_css
	
	slides = presentation.get_slides()
	
	# Calculate the overview slide data
	overview_scale = 1
	overview_middle_point = {}
	num_slides = slides.count()
	if num_slides > 1:
		x_values = []
		y_values = []
		for i in slides:
			x_values.append(int(i["pos_x"]))
			y_values.append(int(i["pos_y"]))
		presentation_width = max(x_values) - min(x_values)
		presentation_height = max(y_values) - min(y_values)
		overview_middle_point = {"x": presentation_width/2, "y": presentation_height/2}
		overview_scale = presentation_width / 768
		slides.rewind()
	
	# show the presentation preview
	return render_to_response("view.html", {
		"presentation": presentation,
		"theme_css" : get_css(request, presentation.theme.id).content,
		"slides": slides,
		"overview_middle_point": overview_middle_point,
		"overview_scale": overview_scale,
		"num_slides": num_slides
		}, context_instance=RequestContext(request))