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 view(request, key): """Show the presentation""" # get the presentation data based on its key p = Presentation.objects.get(key=key) if p.is_private: uspr = UserPresentation() if not uspr.is_allowed(request.user.id, p.id): raise Http404 # Load slides from MongoDB conn = pymongo.Connection(settings.MONGODB_URI) db = conn[settings.MONGODB_DATABASE] slides = db.slides.find({"presentation_id": p.id}) # show the presentation preview return render_to_response("view.html", { "presentation":p, "slides":slides, }, context_instance=RequestContext(request))