def presentation(request, key): """Show the presentation page with info, mini preview, comments and other options """ # search the presentation based on its key p = Presentation.objects.filter(key=key).first() # if presentation exists if p is not None: if p.is_private: uspr = UserPresentation() if not uspr.is_allowed(request.user.id, p.id): raise Http404 rename_form = RenameForm({"name":p.name}) modify_description_form = ModifyDescriptionForm({"description":p.description}) # Load comments from presentation's ID from main.models import Comment c = Comment() comments = c.get_from_presentation(p.id) # generate comment form comment_form = CommentForm() # generate share form uspr = UserPresentation() share_formset = uspr.load_share_form(p.id, request.user.id) # set permissions is_owner = False can_edit = False # check if the user is logged if request.user.username: # check if the user is the owner of the presentation if UserPresentation.objects.filter(user_id=request.user.id, presentation_id=p.id, is_owner=True).exists(): is_owner = True # check if the user can edit the presentation if UserPresentation.objects.filter(user_id=request.user.id, presentation_id=p.id, can_edit=True).exists(): can_edit = True # show the presentation page return render_to_response("presentation.html", { "presentation": p, "rename_form": rename_form, "modify_description_form": modify_description_form, "share_formset": share_formset, "comment_form": comment_form, "comments": comments, "view_url": request.get_host() + reverse("main.views.presentations.view", args=[key]), "is_owner": is_owner, "can_edit": can_edit, }, context_instance=RequestContext(request)) else: # show error 404 page raise Http404
def edit(request, key=None): """Open the presentation editor screen""" template_data = {} if not key: template_data["is_anonymous"] = True else: try: p = Presentation.objects.get(key=key) # check if user is allowed to edit this presentation if UserPresentation.objects.filter(user_id=request.user.id, presentation_id=p.id, can_edit=1).exists(): # get user data user_data = { "username": request.user.username, "first_name": request.user.first_name, "last_name": request.user.last_name, } # generate share form uspr = UserPresentation() share_formset = uspr.load_share_form(p.id, request.user.id) template_data["presentation"] = p template_data["is_anonymous"] = False template_data["user_data"] = user_data template_data["share_formset"] = share_formset template_data["NODEJS_URL"] = settings.NODEJS_URL else: raise ObjectDoesNotExist except ObjectDoesNotExist: return HttpResponseRedirect("/") # show the editor page return render_to_response("edit.html", template_data, context_instance=RequestContext(request))