示例#1
0
文件: utils.py 项目: Nef10/1327
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
示例#2
0
文件: utils.py 项目: xasetl/1327
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()
示例#3
0
文件: utils.py 项目: Yingmin-Li/1327
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()
示例#4
0
文件: utils.py 项目: Bartzi/1327
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()
示例#5
0
文件: utils.py 项目: Yingmin-Li/1327
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