コード例 #1
0
def share(request, id):
	"""Share the presentation to other users"""

	presentation = Presentation.objects.get(pk = id)
	share_formset = formset_factory(SharePresentationForm)

	if request.method == "POST":
		formset = share_formset(request.POST)
		if formset.is_valid():
			for form in formset:
				user = User.objects.filter(email = form.cleaned_data["email"]).first()
				if user is not None:
					userpresentation = UserPresentation(
								presentation_id = presentation.id,
								user_id = user.id,
								can_edit = True if int(form.cleaned_data["permission"]) == 1 else False,
								is_owner = 0)
					userpresentation.save()

		# redirect to the same page
		return HttpResponseRedirect(request.META["HTTP_REFERER"])
	else:
		return render_to_response("share_form.html", {
			"presentation": presentation,
			"collaborators": presentation.userpresentation_set.exclude(user__id = request.user.id),
			"share_formset": share_formset
		}, context_instance=RequestContext(request))
コード例 #2
0
ファイル: presentations.py プロジェクト: Ryuno-Ki/dyapos
def share(request):
	"""Share the presentation to other users"""

	if request.method == "POST":

		presentation_id = request.POST["presentation_id"]

		formset = formset_factory(SharePresentationForm)
		formset = formset(request.POST)

		if formset.is_valid():
			# get the data from the form
			for form in formset:
				email = form.cleaned_data["email"]
				permission = int(form.cleaned_data["permission"])

				# get user info based on the email
				user = User.objects.filter(email=email).first()
				if user is not None:
					# create a UserPresentation object that associates a user to a presentation
					uspr = UserPresentation(user_id=user.id,
											presentation_id=presentation_id,
											is_owner=0,
											can_edit=permission
											)

					# save the association to the database
					uspr.save()

		# redirect to the same page
		return HttpResponseRedirect(request.META["HTTP_REFERER"])
コード例 #3
0
ファイル: presentations.py プロジェクト: Ryuno-Ki/dyapos
def create(request):
	"""Create a new presentation"""

	# if data are received from the view
	if request.method == "POST":
		# get data from the form
		form = NewPresentationForm(request.POST)
		if form.is_valid():
			name = form.cleaned_data["name"]
			description = form.cleaned_data["description"]

			# set default theme (id=1)
			theme_id = 1

			# set the number of views and likes to 0
			num_views = num_likes = 0

			# set status=1 (active)
			status = 1

			# set the presentation key based on a random SHA1 string
			key = hashlib.sha1(str(datetime.datetime.now())).hexdigest()[:10]

			# set public=1 (public is default)
			is_private = form.cleaned_data["is_private"]

			# create a Presentation object with its parameters
			presentation = Presentation(theme_id=theme_id,
										name=name,
										description=description,
										status=status,
										key=key,
										is_private=is_private,
										num_views=num_views,
										num_likes=num_likes
										)

			# save the presentation to the database
			presentation.save()

			# create a UserPresentation object to associate the user with the created presentation ID
			userpresentation = UserPresentation(user_id=request.user.id,
												presentation_id=presentation.id,
												is_owner=1,
												can_edit=1,
												)

			# save the association to the database
			userpresentation.save()

			# redirect to the edit page of the created presentation
			return HttpResponseRedirect("/edit/" + str(presentation.key))

	form = NewPresentationForm()
	# redirect to home page
	return render_to_response("home.html", {"form":form}, context_instance=RequestContext(request))
コード例 #4
0
ファイル: presentations.py プロジェクト: Ryuno-Ki/dyapos
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
コード例 #5
0
ファイル: presentations.py プロジェクト: Ryuno-Ki/dyapos
def copy(request, id):
	"""Copy a backup of the presentation"""

	# search the presentation data based on its ID
	p = Presentation.objects.get(pk=id)
	thumbnail_src = settings.MEDIA_THUMBNAILS_ROOT + "/img_" + p.key + ".png"

	'''delete its PK, so next time the save() method is executed,
	it'll save a new row to the database with a new ID'''
	p.pk = None

	# generate a presentation key, based on a random SHA1 string
	p.key = hashlib.sha1(str(datetime.datetime.now())).hexdigest()[:10]

	# generate a new name to the presentation
	p.name = _("text_copy_of") + " " + p.name

	# set the number of views and likes to 0
	p.num_views = p.num_likes = 0

	# save the new copied presentation to the database
	p.save()

	# Copy slides from MongoDB database
	conn = pymongo.Connection(settings.MONGODB_URI)
	db = conn[settings.MONGODB_DATABASE]
	slides = db.slides.find({"presentation_id": int(id)})
	for i in slides:
		#Replace the slide _id and its presentation_id
		i["_id"] = ObjectId()
		i["presentation_id"] = p.id

		#Replace the components' _id
		for j in i["components"]:
			j["_id"] = str(ObjectId())

		#Finally save the new slide
		db.slides.insert(i)

	# associate to userpresentation table
	us_pr = UserPresentation(user_id=request.user.id,
							presentation_id=p.id,
							is_owner=1,
							can_edit=1)

	# save the association
	us_pr.save()

	# copy the thumbnail
# 	thumbnail_dst = settings.MEDIA_THUMBNAILS_ROOT + "/img_" + p.key + ".png"
# 	shutil.copy(thumbnail_src, thumbnail_dst)


	# redirect to home page
	return HttpResponseRedirect("/home")
コード例 #6
0
ファイル: presentation.py プロジェクト: prodigeni/dyapos
    def associate_to_user(self, user, is_owner, can_edit):
        """Associates a presentation to a user
		Args:
			user (User): the user to associate
			is_owner (bool): True if the user is owner of the presentation, otherwise False
			can_edit (bool): True if the user can edit the presentation, otherwise False
		"""

        userpresentation = UserPresentation(
            user_id=user.id, presentation_id=self.id, is_owner=is_owner, can_edit=can_edit
        )
        userpresentation.save()
コード例 #7
0
ファイル: presentation.py プロジェクト: smarquezs/dyapos
	def associate_to_user(self, user, is_owner, can_edit):
		"""Associates a presentation to a user
		Args:
			user (User): the user to associate
			is_owner (bool): True if the user is owner of the presentation, otherwise False
			can_edit (bool): True if the user can edit the presentation, otherwise False
		"""
				
		userpresentation = UserPresentation(user_id = user.id,
										presentation_id = self.id,
										is_owner = is_owner,
										can_edit = can_edit)
		userpresentation.save()
コード例 #8
0
ファイル: presentations.py プロジェクト: prodigeni/dyapos
def share(request, id):
	"""Share the presentation to other users"""

	if request.method == "POST":

		presentation = Presentation.objects.get(pk = id)
		share_formset = formset_factory(SharePresentationForm)
		formset = share_formset(request.POST)
		if formset.is_valid():
			for form in formset:
				user = User.objects.filter(email = form.cleaned_data["email"]).first()
				if user is not None:
					userpresentation = UserPresentation(
								presentation_id = presentation.id,
								user_id = user.id,
								can_edit = True if int(form.cleaned_data["permission"]) == 1 else False,
								is_owner = 0)
					userpresentation.save()

		# redirect to the same page
		return HttpResponseRedirect(request.META["HTTP_REFERER"])
コード例 #9
0
ファイル: presentations.py プロジェクト: Ryuno-Ki/dyapos
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))
コード例 #10
0
ファイル: presentations.py プロジェクト: smarquezs/dyapos
def share(request, id):
    """Share the presentation to other users"""

    if request.method == "POST":

        presentation = Presentation.objects.get(pk=id)
        share_formset = formset_factory(SharePresentationForm)
        formset = share_formset(request.POST)
        if formset.is_valid():
            for form in formset:
                user = User.objects.filter(
                    email=form.cleaned_data["email"]).first()
                if user is not None:
                    userpresentation = UserPresentation(
                        presentation_id=presentation.id,
                        user_id=user.id,
                        can_edit=True if int(
                            form.cleaned_data["permission"]) == 1 else False,
                        is_owner=0)
                    userpresentation.save()

        # redirect to the same page
        return HttpResponseRedirect(request.META["HTTP_REFERER"])
コード例 #11
0
ファイル: presentations.py プロジェクト: Ryuno-Ki/dyapos
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))