本文整理汇总了Python中forms.DocumentForm类的典型用法代码示例。如果您正苦于以下问题:Python DocumentForm类的具体用法?Python DocumentForm怎么用?Python DocumentForm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DocumentForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: document_add_typed
def document_add_typed(request, folder_id=None, response_format='html'):
"Document add to preselected folder"
folder = None
if folder_id:
folder = get_object_or_404(Folder, pk=folder_id)
if not request.user.profile.has_permission(folder, mode='x'):
folder = None
document = Document()
if request.POST:
if 'cancel' not in request.POST:
form = DocumentForm(
request.user.profile, folder_id, request.POST, instance=document)
if form.is_valid():
document = form.save()
document.set_user_from_request(request)
return HttpResponseRedirect(reverse('documents_document_view', args=[document.id]))
else:
return HttpResponseRedirect(reverse('document_index'))
else:
form = DocumentForm(request.user.profile, folder_id)
context = _get_default_context(request)
context.update({'form': form,
'folder': folder})
return render_to_response('documents/document_add_typed', context,
context_instance=RequestContext(request),
response_format=response_format)
示例2: import_file
def import_file(request):
models = [
'inventory.inventory',
'inventory.inventorytransaction',
'assets.itemgroup',
'assets.itemstate',
'inventory.itemtemplate',
'inventory.location',
'assets.person',
'assets.state',
'inventory.supplier',
'assets.item',
]
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES, models=models)
if form.is_valid():
temp_file = handle_uploaded_file(form.cleaned_data['local_document'])
return HttpResponseRedirect(
'?'.join(
[reverse('import_next_steps'),
urlencode({
'temp_file':temp_file,
'model_name':form.cleaned_data['model_name'],
})]))
else:
form = DocumentForm(models=models)
return render_to_response('generic_form.html', {
'form':form,
'title':_(u'Upload a file to import'),
},
context_instance=RequestContext(request))
示例3: document_edit
def document_edit(request, document_id, response_format='html'):
"Document edit page"
document = get_object_or_404(Document, pk=document_id)
if not request.user.profile.has_permission(document, mode='w'):
return user_denied(request, message="You don't have access to this Document")
if request.POST:
if 'cancel' not in request.POST:
form = DocumentForm(
request.user.profile, None, request.POST, instance=document)
if form.is_valid():
document = form.save()
return HttpResponseRedirect(reverse('documents_document_view', args=[document.id]))
else:
return HttpResponseRedirect(reverse('documents_document_view', args=[document.id]))
else:
form = DocumentForm(
request.user.profile, None, instance=document)
context = _get_default_context(request)
context.update({'form': form,
'document': document})
return render_to_response('documents/document_edit', context,
context_instance=RequestContext(request),
response_format=response_format)
示例4: add_document
def add_document(request):
""" Add a document """
label_options = {'labels': {'item_type': 'Document type'}}
dform = DocumentForm(user=request.user)
# rform = ReferenceForm()
tag_formset = get_tag_formset(**label_options)
if request.method == 'POST':
# rform = ReferenceForm(request.POST)
dform = DocumentForm(request.POST, request.FILES, user=request.user)
tag_formset = get_tag_formset(dform.instance, data=request.POST, **label_options)
#this avoids ignoring the evaluation of the form to show the errors
# rf_is_valid = rform.is_valid()
rf_is_valid = True
df_is_valid = dform.is_valid()
if rf_is_valid and df_is_valid and tag_formset.is_valid():
# rform.save()
# dform.instance.reference = rform.instance
dform.save()
# file = dform.cleaned_data['file']
# dform.instance.seet_file(file=file, filename=file.name)
assign_perm('documents.access_document', request.user, dform.instance)
tag_formset.save()
return HttpResponseRedirect(reverse('documents.views.list_documents'))
return render_to_response('add_document.html', {
'dform': dform,
'rform': None,
'formset': tag_formset,
}, context_instance=RequestContext(request))
示例5: cargar_mod
def cargar_mod(request):
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(docfile=request.FILES['docfile'])
newdoc.save()
#print(newdoc.docfile.name)
manejo_mods.insmod('/home/pi/SO2TP3PerezFederico/PaginaTP3/media/'+newdoc.docfile.name)
archivo = open('salida.txt','r')
lista = []
for linea in archivo:
lista.append(linea)
return render_to_response(
'list.html',
{'documents': lista},
context_instance=RequestContext(request))
# Redirect to the document list after POST
# return HttpResponseRedirect(reverse('cargar_mod'))
else:
form = DocumentForm() # A empty, unbound form
# Render list page with the documents and the form
return render_to_response(
'list.html',
{'form': form},
context_instance=RequestContext(request)
)
示例6: executeUpload
def executeUpload(request):
# Save the files
form = DocumentForm(request.POST, request.FILES)
file_new = request.FILES['docfile']
if form.is_valid():
#Save temporary file
newdoc = Document(docfile = file_new)
newdoc.save()
fn = file_new.name
fn = fn.replace (" ", "_")
#Move the file to the new folder
src = os.path.join(django_settings.FILE_UPLOAD_TEMP_DIR, 'uploads', fn)
file_upload = src
path = os.path.join(request.session['projectPath'],'Uploads')
target = os.path.join(path, fn)
if os.path.exists(target):
os.remove(target)
shutil.move(src, path)
#Delete the temporary file
newdoc.delete()
示例7: list
def list(request):
# Handle file upload
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(pk=1)
f = request.FILES['docfile']
newdoc.docfile = f
newdoc.name = f.name
newdoc.save()
# Redirect to the document list after POST
#return HttpResponseRedirect(reverse('myproject.myapp.views.list'))
else:
form = DocumentForm() # A empty, unbound form
# Load documents for the list page
try:
document = Document.objects.get(pk=1)
except Document.DoesNotExist:
document = None
#update game
if gameHeart:
gameHeart.restart()
# Render list page with the documents and the form
return render_to_response(
'list.html',
{'document': document, 'form': form},
context_instance=RequestContext(request)
)
示例8: investing
def investing(request):
# Handle file upload
file_form = FileForm(request.POST)
form = DocumentForm(request.POST, request.FILES)
if request.method == 'POST' and "uploadFile" in request.POST:
# Upload
if form.is_valid():
newdoc = Document(docfile = request.FILES['docfile'])
newdoc.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('dataloader.views.investing'))
elif request.method == 'POST' and "invest" in request.POST:
# Make Investments
if file_form.is_valid():
file_name = file_form.cleaned_data['file_input']
print "### FILE FOR INVESTMENTS: " + file_name
file_path = settings.MEDIA_ROOT + "/" + file_name
print file_path
cr = csv.reader(open(file_path))
# Starting from second row
for row in cr:
if row[0] == 'fund' or row[0] == 'individual':
investment_manager.fund(row)
elif row[0] == 'buy':
investment_manager.buy(row)
elif row[0] == 'sell':
investment_manager.sell(row)
elif row[0] == 'sellbuy':
investment_manager.sellbuy(row)
return HttpResponseRedirect(reverse('dataloader.views.investing'))
elif request.method == 'POST' and "clear" in request.POST:
# Clear Investments
print "### This should clear everything"
Activity.objects.all().delete()
StakeHold.objects.all().delete()
Port_Indi.objects.all().delete()
print "### OK check porfolio page"
else:
form = DocumentForm() # A empty, unbound form
file_form = FileForm()
# Load documents for the list page
documents = Document.objects.all()
return render_to_response(
'nav/investing.html',
{'documents': documents, 'form': form, 'file_form':file_form},
context_instance=RequestContext(request)
)
示例9: edit_document
def edit_document(request, id=None):
"""Edit a document"""
ctx = copy.copy(default_ctx)
if id is None:
doc = None
cur_revision = 0
else:
doc = get_object_or_404(Document, id=id)
if request.user != doc.owner and not doc.contributors.filter(id=request.user.id).exists():
raise Http404
cur_revision = doc.revision
if request.method == 'POST':
# giving doc to the form may change its contents, so copy them now
if doc is not None:
cur_content = doc.content
form = DocumentForm(request.POST, instance=doc)
if form.is_valid():
if cur_revision == form.cleaned_data['revision']:
new_doc = form.save(commit=False)
# update revision
new_doc.revision = cur_revision + 1
if doc is None:
# owner is not set when creating a new document
new_doc.owner = request.user
new_doc.save()
return redirect('show_document', new_doc.id)
else:
# document was changed during editing
ctx['diff_warning'] = True
ctx['cur_content'] = cur_content
ctx['diff'] = ''.join(difflib.ndiff(doc.content.splitlines(1), cur_content.splitlines(1)))
form = DocumentForm(instance=doc, initial={'revision': cur_revision })
ctx['doc'] = doc
ctx['form'] = form
return render_to_response('edit_document.html', ctx, RequestContext(request))
示例10: web_import_xml
def web_import_xml(request):
"""
redirects to login page if user is not logged in
otherwise, renders page with import functionality
if called with POST request...
check imported data against schema using minixsv
puts data into database if validation succeeds
"""
if request.user.is_authenticated():
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
imported_file = request.FILES['docfile'].read()
f_import = open('importXML.xml', 'w')
f_import.write(imported_file)
f_import.close()
try:
bo = check_imported_file(imported_file)
except Exception:
bo = False
if bo:
import_xml(imported_file)
return render_to_response('importing.html', {'import_status': 'Import succeeded.'})
else:
return render_to_response('importing.html', {'import_status': 'Import failed.'})
else:
form = DocumentForm()
return render_to_response('import.html', {'form': form}, context_instance=RequestContext(request))
else:
return render_to_response('login.html', context_instance=RequestContext(request))
示例11: edi_translator
def edi_translator(request):
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
new_file = models.edi_address(edi_file = request.FILES['docfile'])
new_file.save()
print new_file.id
return HttpResponseRedirect(('{}').format(new_file.id))
return render(request, 'EDI/traducir.html', {'form': form})
示例12: upload_document_with_type
def upload_document_with_type(request, document_type_id, multiple=True):
check_permissions(request.user, "documents", [PERMISSION_DOCUMENT_CREATE])
document_type = get_object_or_404(DocumentType, pk=document_type_id)
local_form = DocumentForm(prefix="local", initial={"document_type": document_type})
if USE_STAGING_DIRECTORY:
staging_form = StagingDocumentForm(prefix="staging", initial={"document_type": document_type})
if request.method == "POST":
if "local-submit" in request.POST.keys():
local_form = DocumentForm(
request.POST, request.FILES, prefix="local", initial={"document_type": document_type}
)
if local_form.is_valid():
try:
if (not UNCOMPRESS_COMPRESSED_LOCAL_FILES) or (
UNCOMPRESS_COMPRESSED_LOCAL_FILES
and not _handle_zip_file(request, request.FILES["local-file"], document_type)
):
instance = local_form.save()
_handle_save_document(request, instance, local_form)
messages.success(request, _(u"Document uploaded successfully."))
except Exception, e:
messages.error(request, e)
if multiple:
return HttpResponseRedirect(request.get_full_path())
else:
return HttpResponseRedirect(reverse("document_list"))
elif "staging-submit" in request.POST.keys() and USE_STAGING_DIRECTORY:
staging_form = StagingDocumentForm(
request.POST, request.FILES, prefix="staging", initial={"document_type": document_type}
)
if staging_form.is_valid():
try:
staging_file = StagingFile.get(staging_form.cleaned_data["staging_file_id"])
if (not UNCOMPRESS_COMPRESSED_STAGING_FILES) or (
UNCOMPRESS_COMPRESSED_STAGING_FILES
and not _handle_zip_file(request, staging_file.upload(), document_type)
):
document = Document(file=staging_file.upload(), document_type=document_type)
document.save()
_handle_save_document(request, document, staging_form)
messages.success(
request, _(u"Staging file: %s, uploaded successfully.") % staging_file.filename
)
if DELETE_STAGING_FILE_AFTER_UPLOAD:
staging_file.delete()
messages.success(request, _(u"Staging file: %s, deleted successfully.") % staging_file.filename)
except Exception, e:
messages.error(request, e)
if multiple:
return HttpResponseRedirect(request.META["HTTP_REFERER"])
else:
return HttpResponseRedirect(reverse("document_list"))
示例13: upload_file
def upload_file(request):
documents = Document.objects.all()
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(name = request.POST['name'], label = request.POST['label'], docfile = request.FILES['docfile'])
newdoc.save()
return redirect('/docs')
else:
form = DocumentForm()
documents = Document.objects.all()
return render(request, 'network/docs.html', {'documents': documents, 'form': form})
示例14: create_document
def create_document(request):
"""View for creating new documents"""
if request.method == 'POST':
form = DocumentForm(request.POST)
if form.is_valid():
d = form.save(commit=False)
d.owner = request.user
d.save()
return redirect('show_document', d.id)
else:
form = DocumentForm()
ctx = copy.copy(default_ctx)
ctx['form'] = form
return render_to_response('create_document.html', ctx, RequestContext(request))
示例15: expuploads
def expuploads(request):
# Handle file uploads
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES, request.POST.get('dirName', 'error'))
# redirect to the document after POST
return HttpResponseRedirect(reverse('uploads.views.expuploads'))
else:
form = DocumentForm() # An empty, unbound form
experiments = Experiment.objects.all()
# Render list page with the documents and the form
return render(request, 'expuploads.html', {'form': form, 'experiments': experiments})