当前位置: 首页>>代码示例>>Python>>正文


Python DocumentForm.clean_content方法代码示例

本文整理汇总了Python中forms.DocumentForm.clean_content方法的典型用法代码示例。如果您正苦于以下问题:Python DocumentForm.clean_content方法的具体用法?Python DocumentForm.clean_content怎么用?Python DocumentForm.clean_content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.DocumentForm的用法示例。


在下文中一共展示了DocumentForm.clean_content方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload2

# 需要导入模块: from forms import DocumentForm [as 别名]
# 或者: from forms.DocumentForm import clean_content [as 别名]
def upload2(request):
        # Handle file upload
    logger = logging.getLogger(__name__)
    
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
                                  
        if form.is_valid():
            
            newdoc = Document(docfile = request.FILES['docfile'], docfile1 = request.FILES['docfile1'],  docfile2 = request.FILES['docfile2'])
            newdoc.usersname = request.user.username
            newdoc.price=request.POST.get('price','')
            newdoc.category= request.POST.get('category','')
            newdoc.isover18s =request.POST.get('isover18s','')
            newdoc.name =request.POST.get('name','')
            newdoc.description =request.POST.get('description','')
   
            
            form.clean_content()
            
               
            newdoc.save()

            return HttpResponseRedirect(reverse('main.views.upload'))
    else:
        form = DocumentForm() # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render_to_response(
        'upload2.html',
        {'documents': documents, 'form': form},
        context_instance=RequestContext(request)
    )
开发者ID:maralad,项目名称:shabingo,代码行数:38,代码来源:views.py

示例2: edit_preview

# 需要导入模块: from forms import DocumentForm [as 别名]
# 或者: from forms.DocumentForm import clean_content [as 别名]
def edit_preview(request, document_id):
        ##This is where a user can go in and edit all the details 
        ##of and existing video that they have uploaded
        ##This is all a bit verbose but at least its clear whats going on
    
        if request.method == 'POST':
            form = DocumentForm(request.POST, request.FILES)
            form.fields['docfile'].required = False
            form.fields['docfile1'].required = False
            form.fields['docfile2'].required = False
            form.fields['category'].required = False
            form.fields['document_type'].required = False
            form.fields['price'].required = False
            form.fields['description'].required = False
            form.fields['name'].required = False

            if form.is_valid():
                
                #Get the particular video uploaded record from the database
                newdoc = Document.objects.get(id=document_id)
                newdoc.usersname = request.user.username                
                
                #Certain fields may or may not have changed
                #If they are present then they will be updated 
                #otherwise they wont

                if request.FILES.get('docfile'):
                    myfile=request.FILES.get('docfile')
                else:
                    myfile=None
                
                if request.FILES.get('docfile1'):
                    myfile1=request.FILES.get('docfile1')
                else:
                    myfile1=None
                
                if request.FILES.get('docfile2'):
                    myfile2=request.FILES.get('docfile2')
                else:
                    myfile2=None
                
                if myfile:
                   newdoc.docfile = myfile
                if myfile1:
                   newdoc.docfile1 = myfile1
                if myfile2:
                   newdoc.docfile2 = myfile2
                   
                              
                newdoc.price=request.POST.get('price','')
                newdoc.category= request.POST.get('category','')
                if request.POST.get('document_type',''):
                    newdoc.document_type=1
                newdoc.isover18s =request.POST.get('isover18s','')
                newdoc.name =request.POST.get('name','')
                newdoc.description =request.POST.get('description','')
                
                #Clean the fields and save the record
                form.clean_content()
                if myfile:
                    newdoc.save(update_fields=['docfile'])
                if myfile1:   
                    newdoc.save(update_fields=['docfile1'])
                if myfile2: 
                    newdoc.save(update_fields=['docfile2'])
                if request.POST.get('price'):
                    newdoc.save(update_fields=['price'])
                if request.POST.get('category'):
                    newdoc.save(update_fields=['category'])
                if request.POST.get('document_type'):
                    newdoc.save(update_fields=['document_type'])
                if request.POST.get('isover18s'):
                    newdoc.save(update_fields=['isover18s'])
                if request.POST.get('name'):
                    newdoc.save(update_fields=['name'])
                
                if request.POST.get('description'):   
                    newdoc.save(update_fields=['description'])
                    
                p =request.POST.get('docfile')
                
                messages.error(request, 'docfile  is: %s ' %p)
                
                
                
                
                messages.error(request, 'Form Errors: %s' %form.errors)
                
           
        document = Document.objects.get(id=document_id)

        form = DocumentForm() 
        
        #Return the updated record to be rendered on the front end
        return render_to_response(
            'edit_preview.html',
            {'document': document, 'form': form},
            context_instance=RequestContext(request)
        )
开发者ID:maralad,项目名称:shabingo,代码行数:101,代码来源:views.py


注:本文中的forms.DocumentForm.clean_content方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。