Beispiel #1
0
def handle_attachment(request, document):
	if request.method == "POST":
		form = AttachmentForm(request.POST, request.FILES)
		if form.is_valid():
			instance = form.save(commit=False)
			if instance.displayname == '':
				instance.displayname = instance.file.name
			instance.document = document
			instance.index = document.attachments.count() + 1
			instance.save()
			return True, form, instance
	else:
		form = AttachmentForm()
	return False, form, None
Beispiel #2
0
def handle_attachment(request, document):
    if request.method == "POST":
        form = AttachmentForm(request.POST, request.FILES)
        if form.is_valid():
            instance = form.save(commit=False)
            if instance.displayname == '':
                instance.displayname = instance.file.name
            instance.document = document
            instance.index = document.attachments.count() + 1
            instance.save()
            return True, form, instance
    else:
        form = AttachmentForm()
    return False, form, None
Beispiel #3
0
def handle_attachment(request, document):
	if request.method == "POST":
		form = AttachmentForm(request.POST, request.FILES)
		if form.is_valid():
			instance = form.save(commit=False)
			if instance.displayname == '':
				instance.displayname = instance.file.name
			if not re.search(r'\.\w+$', instance.displayname):
				file_type = re.search(r'\.(\w+)$', instance.file.name).group(1)
				instance.displayname = "{}.{}".format(instance.displayname, file_type)
			instance.document = document
			instance.save()
			return True, form
	else:
		form = AttachmentForm()
	return False, form
Beispiel #4
0
def handle_attachment(request, document):
    if request.method == "POST":
        form = AttachmentForm(request.POST, request.FILES)
        if form.is_valid():
            instance = form.save(commit=False)
            if instance.displayname == '':
                instance.displayname = instance.file.name
            if not re.search(r'\.\w+$', instance.displayname):
                file_type = re.search(r'\.(\w+)$', instance.file.name).group(1)
                instance.displayname = "{}.{}".format(instance.displayname,
                                                      file_type)
            instance.document = document
            instance.save()
            return True, form
    else:
        form = AttachmentForm()
    return False, form