Beispiel #1
0
def handle_edit(request, document):
	if request.method == 'POST':
		form = document.Form(request.POST, instance=document)
		if form.is_valid():
			cleaned_data = form.cleaned_data

			document.url_title = cleaned_data['url_title']

			# save the document and also save the user and the comment the user added
			with transaction.atomic(), reversion.create_revision():
				document.save()
				reversion.set_user(request.user)
				reversion.set_comment(cleaned_data['comment'])

			# delete Autosave
			try:
				autosave = TemporaryDocumentText.objects.get(document=document)
				autosave.delete()
			except TemporaryDocumentText.DoesNotExist:
				pass

			return True, form
	else:
		# load Autosave
		autosave = None
		try:
			autosave = TemporaryDocumentText.objects.get(document=document)
			autosaved = True
		except TemporaryDocumentText.DoesNotExist:
			autosaved = False

		if 'restore' in request.GET:
			autosaved = False

		if 'restore' in request.GET and autosave is not None:
			form_data = {
				'text': autosave.text,
				'url_title': document.url_title,
			}
			form = DocumentForm(initial=form_data, instance=document)
		else:
			form = DocumentForm(instance=document)
		form.autosave = autosaved
		if autosaved:
			form.autosave_date = autosave.created

	return False, form
Beispiel #2
0
def handle_autosave(request, document):
	if request.method == 'POST':
		form = DocumentForm(request.POST, user=request.user, creation=document.is_in_creation)
		form.is_valid()
		text_strip = request.POST['text'].strip()
		if text_strip != '':
			cleaned_data = form.cleaned_data

			if document is None:
				temporary_document_text = TemporaryDocumentText.objects.create(author=request.user)
			elif document.text != cleaned_data['text']:
				temporary_document_text, __ = TemporaryDocumentText.objects.get_or_create(document=document, author=request.user)
			else:
				return

			temporary_document_text.text = cleaned_data['text']
			temporary_document_text.save()
Beispiel #3
0
def handle_autosave(request, document):
    if request.method == 'POST':
        form = DocumentForm(request.POST)
        form.is_valid()
        text_strip = request.POST['text'].strip()
        if text_strip != '':
            cleaned_data = form.cleaned_data

            if document is None:
                temporary_document_text = TemporaryDocumentText(
                    author=request.user)
            elif document.text != cleaned_data['text']:
                temporary_document_text, created = TemporaryDocumentText.objects.get_or_create(
                    document=document, author=request.user)
                temporary_document_text.document = document
            else:
                return

            temporary_document_text.text = cleaned_data['text']
            temporary_document_text.save()
Beispiel #4
0
def handle_autosave(request, document):
    if request.method == "POST":
        form = DocumentForm(request.POST, user=request.user, creation=(not document.has_perms()))
        form.is_valid()
        text_strip = request.POST["text"].strip()
        if text_strip != "":
            cleaned_data = form.cleaned_data

            if document is None:
                temporary_document_text = TemporaryDocumentText(author=request.user)
            elif document.text != cleaned_data["text"]:
                temporary_document_text, __ = TemporaryDocumentText.objects.get_or_create(
                    document=document, author=request.user
                )
                temporary_document_text.document = document
            else:
                return

            temporary_document_text.text = cleaned_data["text"]
            temporary_document_text.save()
Beispiel #5
0
def handle_edit(request, document):
    if request.method == 'POST':
        form = document.Form(request.POST, instance=document)
        if form.is_valid():
            cleaned_data = form.cleaned_data

            document.url_title = cleaned_data['url_title']

            # save the document and also save the user and the comment the user added
            with transaction.atomic(), reversion.create_revision():
                document.save()
                reversion.set_user(request.user)
                reversion.set_comment(cleaned_data['comment'])

            # delete Autosave
            try:
                autosave = TemporaryDocumentText.objects.get(document=document)
                autosave.delete()
            except TemporaryDocumentText.DoesNotExist:
                pass

            return True, form
    else:
        # load Autosave
        autosave = None
        try:
            autosave = TemporaryDocumentText.objects.get(document=document)
            autosaved = True
        except TemporaryDocumentText.DoesNotExist:
            autosaved = False

        if 'restore' in request.GET:
            autosaved = False

        if 'restore' in request.GET and autosave is not None:
            form_data = {
                'text': autosave.text,
                'url_title': document.url_title,
            }
            form = DocumentForm(initial=form_data, instance=document)
        else:
            form = DocumentForm(instance=document)
        form.autosave = autosaved
        if autosaved:
            form.autosave_date = autosave.created

    return False, form