Beispiel #1
0
def edit(request, title, new_autosaved_pages=None, initial=None):
	document = Document.objects.get(url_title=title)
	content_type = ContentType.objects.get_for_model(document)
	check_permissions(document, request.user, [document.edit_permission_name])

	# if the edit form has a formset we will initialize it here
	formset_factory = document.Form.get_formset_factory()
	formset = formset_factory(request.POST or None, instance=document) if formset_factory is not None else None

	if formset is not None:
		template_name = "{app}_edit.html".format(app=content_type.app_label)
	else:
		template_name = "documents_edit.html"

	success, form = handle_edit(request, document, formset, initial)
	__, attachment_form, __ = handle_attachment(request, document)

	if success:
		messages.success(request, _("Successfully saved changes"))
		return HttpResponseRedirect(reverse('documents:view', args=[document.url_title]))
	else:
		return render(request, template_name, {
			'document': document,
			'form': form,
			'attachment_form': attachment_form,
			'active_page': 'edit',
			'creation': (len(revisions.get_for_object(document)) == 0),
			'new_autosaved_pages': new_autosaved_pages,
			'permission_warning': permission_warning(request.user, content_type, document),
			'supported_image_types': settings.SUPPORTED_IMAGE_TYPES,
			'formset': formset,
		})
Beispiel #2
0
def edit(request, title):
	document = get_object_or_error(MinutesDocument, request.user, ['minutes.change_minutesdocument'], url_title=title)
	success, form = handle_edit(request, document)
	if success:
		messages.success(request, _("Successfully saved changes"))
		return HttpResponseRedirect(reverse('minutes:edit', args=[document.url_title]))
	else:
		return render(request, "minutes_edit.html", {
			'document': document,
			'edit_url': reverse('minutes:edit', args=[document.url_title]),
			'form': form,
			'active_page': 'edit',
		})
Beispiel #3
0
def edit(request, title):
	document = get_object_or_404(Document, url_title=title, type='I')
	try:
		context = handle_edit(request, document)

		context['edit_url'] = reverse('information_pages:edit', args=[document.url_title])
		context['active_page'] = 'edit'

		return render_to_response("information_pages_edit.html", context_instance=context)

	except FormValidException:
		messages.success(request, _("Successfully saved changes"))
		return HttpResponseRedirect(reverse('information_pages:edit', args=[document.url_title]))
Beispiel #4
0
def edit(request, title, new_autosaved_pages=[]):
	document = get_object_or_error(InformationDocument, request.user, ['information_pages.change_informationdocument'], url_title=title)
	success, form = handle_edit(request, document)
	if success:
		messages.success(request, _("Successfully saved changes"))
		return HttpResponseRedirect(reverse('information_pages:view_information', args=[document.url_title]))
	else:
		return render(request, "information_pages_edit.html", {
			'document': document,
			'form': form,
			'active_page': 'edit',
			'creation': (len(reversion.get_for_object(document)) == 0),
			'new_autosaved_pages' : new_autosaved_pages,
		})
Beispiel #5
0
def edit(request, title, new_autosaved_pages=None, initial=None):
	document = get_object_or_404(Document, url_title=title)
	content_type = ContentType.objects.get_for_model(document)
	if document.has_perms():
		check_permissions(document, request.user, [document.edit_permission_name])
	elif new_autosaved_pages is None and initial is None:
		# page is not new and has no permissions set, it is likely that somebody tries to view an autosaved page
		# users are only allowed to view autosaved pages if they have the "add" permission for documents
		check_permissions(document, request.user, [document.add_permission_name])

		try:
			autosave = TemporaryDocumentText.objects.get(document=document)
			if autosave.author != request.user:
				raise PermissionDenied
		except ObjectDoesNotExist:
			# There is no autosave linked to this document, this means that the document can be treated as a new
			# document, hence everyone with add permissions may work with this document
			pass

	# if the edit form has a formset we will initialize it here
	formset_factory = document.Form.get_formset_factory()
	formset = formset_factory(request.POST or None, instance=document) if formset_factory is not None else None

	if formset is not None:
		template_name = "{app}_edit.html".format(app=content_type.app_label)
	else:
		template_name = "documents_edit.html"

	success, form = handle_edit(request, document, formset, initial)
	__, attachment_form, __ = handle_attachment(request, document)

	if success:
		messages.success(request, _("Successfully saved changes"))
		return HttpResponseRedirect(reverse(document.get_view_url_name(), args=[document.url_title]))
	else:
		return render(request, template_name, {
			'document': document,
			'form': form,
			'attachment_form': attachment_form,
			'active_page': 'edit',
			'creation': document.is_in_creation,
			'new_autosaved_pages': new_autosaved_pages,
			'permission_warning': permission_warning(request.user, document),
			'supported_image_types': settings.SUPPORTED_IMAGE_TYPES,
			'formset': formset,
		})
Beispiel #6
0
def edit(request, title):
    document = get_object_or_error(MinutesDocument,
                                   request.user,
                                   ['minutes.change_minutesdocument'],
                                   url_title=title)
    success, form = handle_edit(request, document)
    if success:
        messages.success(request, _("Successfully saved changes"))
        return HttpResponseRedirect(
            reverse('minutes:view', args=[document.url_title]))
    else:
        return render(
            request, "minutes_edit.html", {
                'document': document,
                'edit_url': reverse('minutes:edit', args=[document.url_title]),
                'form': form,
                'active_page': 'edit',
            })
Beispiel #7
0
def edit(request, title, new_autosaved_pages=None, initial=None):
	document = get_object_or_404(Document, url_title=title)
	content_type = ContentType.objects.get_for_model(document)
	if document.has_perms():
		check_permissions(document, request.user, [document.edit_permission_name])
	elif new_autosaved_pages is None and initial is None:
		# page is not new and has no permissions set, it is likely that somebody tries to view an autosaved page
		# users are only allowed to view autosaved pages if they have the "add" permission for documents
		check_permissions(document, request.user, [document.add_permission_name])

	# if the edit form has a formset we will initialize it here
	formset_factory = document.Form.get_formset_factory()
	formset = formset_factory(request.POST or None, instance=document) if formset_factory is not None else None

	if formset is not None:
		template_name = "{app}_edit.html".format(app=content_type.app_label)
	else:
		template_name = "documents_edit.html"

	try:
		creation_group = request.user.groups.get(id=request.GET.get('group', False))
	except Group.DoesNotExist:
		creation_group = None

	success, form = handle_edit(request, document, formset, initial, creation_group=creation_group)
	__, attachment_form, __ = handle_attachment(request, document)

	if success:
		messages.success(request, _("Successfully saved changes"))
		return HttpResponseRedirect(reverse(document.get_view_url_name(), args=[document.url_title]))
	else:
		return render(request, template_name, {
			'document': document,
			'form': form,
			'attachment_form': attachment_form,
			'active_page': 'edit',
			'creation': document.is_in_creation,
			'new_autosaved_pages': new_autosaved_pages,
			'permission_overview': document_permission_overview(request.user, document),
			'supported_image_types': settings.SUPPORTED_IMAGE_TYPES,
			'formset': formset,
		})
Beispiel #8
0
def edit(request, title, new_autosaved_pages=[]):
    document = get_object_or_error(
        InformationDocument,
        request.user, ['information_pages.change_informationdocument'],
        url_title=title)
    success, form = handle_edit(request, document)
    if success:
        messages.success(request, _("Successfully saved changes"))
        return HttpResponseRedirect(
            reverse('information_pages:view_information',
                    args=[document.url_title]))
    else:
        return render(
            request, "information_pages_edit.html", {
                'document': document,
                'form': form,
                'active_page': 'edit',
                'creation': (len(reversion.get_for_object(document)) == 0),
                'new_autosaved_pages': new_autosaved_pages,
            })
Beispiel #9
0
def edit(request, title, new_autosaved_pages=None, initial=None):
    document = get_object_or_404(Document, url_title=title)
    content_type = ContentType.objects.get_for_model(document)
    if document.has_perms():
        check_permissions(document, request.user,
                          [document.edit_permission_name])
    elif new_autosaved_pages is None and initial is None:
        # page is not new and has no permissions set, it is likely that somebody tries to view an autosaved page
        # users are only allowed to view autosaved pages if they have the "add" permission for documents
        check_permissions(document, request.user,
                          [document.add_permission_name])

    # if the edit form has a formset we will initialize it here
    formset_factory = document.Form.get_formset_factory()
    formset = formset_factory(
        request.POST or None,
        instance=document) if formset_factory is not None else None

    if formset is not None:
        template_name = "{app}_edit.html".format(app=content_type.app_label)
    else:
        template_name = "documents_edit.html"

    try:
        creation_group = request.user.groups.get(
            id=request.GET.get('group', False))
    except Group.DoesNotExist:
        creation_group = None

    success, form = handle_edit(request,
                                document,
                                formset,
                                initial,
                                creation_group=creation_group)
    __, attachment_form, __ = handle_attachment(request, document)

    if success:
        messages.success(request, _("Successfully saved changes"))
        return HttpResponseRedirect(
            reverse(document.get_view_url_name(), args=[document.url_title]))
    else:
        return render(
            request, template_name, {
                'document':
                document,
                'form':
                form,
                'attachment_form':
                attachment_form,
                'active_page':
                'edit',
                'creation':
                document.is_in_creation,
                'new_autosaved_pages':
                new_autosaved_pages,
                'permission_overview':
                document_permission_overview(request.user, document),
                'supported_image_types':
                settings.SUPPORTED_IMAGE_TYPES,
                'formset':
                formset,
            })