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


Python ProjectForm.is_valid方法代码示例

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


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

示例1: add_project_view

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def add_project_view(request):
    if request.user.is_authenticated() and request.user.is_staff:
        if request.POST:
            form = ProjectForm(request.POST)
            if form.is_valid():
                data = form.cleaned_data
                td = data['end_date'] - data['start_date']
                if td.total_seconds()>0:
                    project = Project()
                    project.name = data['name']
                    project.description = data['description']
                    project.start_date = data['start_date']
                    project.end_date = data['end_date']
                    project.user = User.objects.get(username = request.user.username)
                    project.save()
                else:
                    messages.add_message(request, messages.ERROR,
                        " end date is less than start date!")
                    return (redirect(reverse('Home:add_project')))
                return (redirect(reverse('Home:manager')))
            else:
                messages.add_message(request, messages.ERROR, 
                    "invalid form")
                return (redirect(reverse('Home:add_project')))
        else:
            form = ProjectForm()
            send_dict={}
            send_dict['form'] = form
            return render_to_response('managers/add_project.html',send_dict,context_instance=RequestContext(request))
    else:
        return redirect(reverse('Login:login'))
开发者ID:Adikeshav,项目名称:intern,代码行数:33,代码来源:views.py

示例2: projectsubmit

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def projectsubmit(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            pd = form.save(commit=False)
            pd.sub_date = timezone.now()
            pd.approved = False

            # format the authors list
            al = pd.authors.strip().replace('\r\n', '*').replace('\r', '*').replace('\n', '*').split('*')
            print al
            if len(al) > 1:
                al[-1] = 'and ' + al[-1].strip()

            if len(al) > 2:
                pd.authors = ', '.join(al)
            else:
                pd.authors = ' '.join(al)

            # make the thumbnail url a direct link if not already
            if pd.thumbnail_url:
                thumb = pd.thumbnail_url.strip()
                if 'imgur' in thumb and 'i.' not in thumb:
                    pd.thumbnail_url = 'i.' + thumb.replace('https://', '').replace('http://', '')
                if '.jpg' not in pd.thumbnail_url:
                    pd.thumbnail_url += '.jpg'

            pd.save()
            return render(request, 'projects/projectsubmit.html', {'submitted': True})
    else:
        form = ProjectForm()
    return render(request, 'projects/projectsubmit.html', {'form': form, 'submitted': False})
开发者ID:sibnerian,项目名称:penn-projects,代码行数:34,代码来源:views.py

示例3: __project_edit

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def __project_edit(project, request):
	usr = request.user
	# print(request.POST)
	tasksToRemove = request.POST["tasksToRemove"]
	peopleToRemove = request.POST["peopleToRemove"]
	filesToRemove = request.POST["filesToRemove"]
	peopleToAdd = request.POST["peopleToAdd"]

	form = ProjectForm(request.POST)
	if form.is_valid():
		project.name = form.cleaned_data['name']
		project.complete = form.cleaned_data['complete']
		project.description = form.cleaned_data['description']
		project.createdBy =request.user
		project.save(False,True)
		# remove composites
		try:
			# TODO
			tasksToRemove = json.loads(tasksToRemove)
			peopleToRemove = json.loads(peopleToRemove)
			peopleToAdd = json.loads(peopleToAdd)
			with transaction.atomic():
				Task.objects.filter(projectId=project).filter(id__in=tasksToRemove).delete()
				PersonInProject.objects.filter(projectId=project).filter(userId__in=peopleToRemove).delete()
				# 	File.objects.filter(projectId=project).filter(id__in=filesToRemove).delete()
				for userId in peopleToAdd:
					print(">>"+str(userId))
					u = User.objects.get(id=userId)
					if u:
						PersonInProject(projectId=project, userId=u, createdBy=usr).save()
		except (User.DoesNotExist,Exception) as e:
			print("Error modifying project's companion objects: "+ str(e))
		return True, {}
	else:
		return False, list(form.errors.keys()) if form.errors else None
开发者ID:ProjectIT,项目名称:Project_ZTW,代码行数:37,代码来源:views.py

示例4: edit_project

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def edit_project(request,projectid):
    names= ['Material Purchase','Make Payment','Invoices','Payments']
    links = ['/projects/'+projectid+'/purchases','/projects/'+projectid+'/payments','/projects/'+projectid+'/invoices','/projects/'+projectid+'/allpayments']
    submenus = create_sub(names,links)
    proj = get_object_or_404(Project, pk=projectid)
    context = {'proj_selected':'current'}
    
    if len(request.POST) <= 0:
        data = {'name':proj.name,'location':proj.location,'city':proj.city,'owner':proj.owner,'start_date':proj.start_date,'end_date':proj.end_date}
        form = ProjectForm(data)
        context.update({'title':'Update Project Details','form':form,'submenus':submenus})
        return render(request, "edit.html", context)
    else:
        form = ProjectForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            proj.name = cd.get('name')
            proj.location = cd.get('location')
            proj.city = cd.get('city')
            proj.owner = cd.get('owner')
            proj.start_date = cd.get('start_date')
            proj.end_date = cd.get('end_date')
            proj.save();
            url = reverse('projects')
            return HttpResponseRedirect("%s?success=1"%(url))
        else:
            context.update({'title':'Update Project Details','form':form,'submenus':submenus})
            return render(request, "edit.html",context)
开发者ID:mhaleemullah,项目名称:ica,代码行数:30,代码来源:views.py

示例5: project_create

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def project_create(request):
	usr = request.user
	if request.method == "POST" and request.is_ajax():
		print(request.POST)
		form = ProjectForm(request.POST)
		if form.is_valid():
			p = Project(name=form.cleaned_data['name'],
						complete=form.cleaned_data['complete'],
						description=form.cleaned_data['description'],
						createdBy=usr)
			p.save(True,False)
			# add creator as admin !
			pip = PersonInProject(projectId=p,
					  	userId=usr,
						role=PersonInProject.PERSON_ROLE[1][0],
						createdBy=usr)
			pip.save(True,False)
			return HttpResponse(json.dumps({"status":"OK","id":p.id}))
		else:
			errors_fields = dict()
			if form.errors:
				errors_fields["fields"] = list(form.errors.keys())
			return HttpResponseBadRequest(json.dumps(errors_fields), content_type="application/json")
	else:
		template = loader.get_template('project_write.html')
		context = RequestContext(request, get_context({
			'new_project': True,
			'data_page_type': 'projects'
		}, request))
		return HttpResponse(template.render(context))
开发者ID:ProjectIT,项目名称:Project_ZTW,代码行数:32,代码来源:views.py

示例6: submit_project

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def submit_project(request):
    form = ProjectForm(request.POST or None)
    if form.is_valid():
        project = form.save(commit=False)
        project.user = request.user
        project.save()

        subject = "Project Submission Notice"
        message = "This is to inform you that your project '" + project.name + "' has been submitted for vetting."
        project_owner = request.user.email


        to_owner_email = EmailMessage(subject, message, [project_owner])
        to_owner_email.send()

        subject = "Project Submission Notice"
        message = "This is to inform you that " + request.user.userprofile.first_name + " " + request.userprofile.last_name " has submitted a project named " + project.name + " with you listed as an adviser."
        project_adviser = project.adviser_email
    

        to_adviser_email = EmailMessage(subject, message, [project_adviser])
        to_adviser_email.send()

        return redirect(project)
    return render_to_response('add_project.html',
                              {'form': form},
                              context_instance=RequestContext(request))
开发者ID:mgfcm,项目名称:cs191-crowdfunding,代码行数:29,代码来源:views.py

示例7: create

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def create(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)

        if form.is_valid():
            project = form.save(commit=False)

            # On vérifie que le slug n'existe pas en bdd
            i = 0
            found = False
            while not found:
                if i > 0:
                    slug = slugify(form.cleaned_data['title']) + '-' + str(i)
                else:
                    slug = slugify(form.cleaned_data['title'])
                if Project.objects.filter(slug__iexact=slug).count() == 0:
                    project.slug = slug
                    found = True
                i += 1

            project.save()
            project.author.add(request.user.id)
            return redirect('projects_view', slug=slug)
    else:
            form = ProjectForm()

    return render(request, 'projects/edit.html', {'form': form})
开发者ID:Lucas-ech,项目名称:club_programmation,代码行数:29,代码来源:views.py

示例8: post

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
    def post(self, request, *args, **kwargs):
        try:
            # Explicitly setting the request.post to be mutable so that we can add additional values to it.
            #once done, reset the mutable property. dont need to do this if a form is a multi-part form.
            mutable = request.POST._mutable
            request.POST._mutable = True
            #Set added by updated by user on form post data
            self.set_added_by_update_by_users_on_view(request, GlobalConstants.ADD_ACTION)
            request.POST._mutable = mutable
            projectform = ProjectForm(request.POST)

            project_members_response = {}
            project_members_list = [project_member for project_member in request.POST.getlist('project_members') if
                                    project_member != ""]
            project_members_values_list = [int(project_member_value) for project_member_value in
                                           request.POST.getlist('project_members_value') if project_member_value != ""]

            if projectform.is_valid():
                #First check if the project resources has no freely typed internal user name
                if len(project_members_list) != len(project_members_values_list):
                    if project_members_values_list:
                        actual_project_members = InternalResource.objects.filter(id__in=project_members_values_list)
                        for member in project_members_list:
                            if member not in actual_project_members:
                                project_members_response[str(project_members_list[member])] = str(
                                    project_members_list[member] + " is not a valid Internal Resource")
                                # else:
                                #     project_members_response[member]
                    else:
                        project_members_response[str(project_members_list[0])] = str(
                            project_members_list[0] + " is not a valid Internal Resource")
                    context = self.get_context_data()
                    context['project_members_response'] = project_members_response
                    context['form'] = projectform
                    return self.render_to_response(context)
                else:
                    self.object = projectform.save()
                    super(AddProject, self).form_valid(projectform)
                    for member in project_members_values_list:
                        member = InternalResource.objects.get(id=int(member))
                        project_resource = ProjectResources(project_id=self.object, resource_id=member,
                                                            addedBy=request.user,
                                                            updatedBy=request.user,
                                                            is_active=True)
                        project_resource.save()
                    return HttpResponseRedirect(self.get_success_url())
            else:
                actual_project_members = InternalResource.objects.filter(id__in=project_members_values_list)
                for member in project_members_list:
                    if member not in actual_project_members:
                        project_members_response[member] = ["0", member + "-"]
                    else:
                        project_members_response[member] = [actual_project_members[member].id, ""]

                return self.form_invalid(form=projectform, project_members_response=project_members_response)

        except Exception as e:
            logger.error("Exception while adding Project: " + str(e))
开发者ID:rastafarian,项目名称:pronoun,代码行数:60,代码来源:addproject.py

示例9: project_edit

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def project_edit(request, pk):
    form = ProjectForm(request.POST or None, instance=Project.get(pk))
    if form.is_valid():
        form.save()
        return HttpResponseRedirect(reverse("projects-list"))
    return direct_to_template(request, "project_edit.html", extra_context={
        "form": form,
        "nav": {"selected": "projects",},
    })
开发者ID:erikrose,项目名称:arecibo,代码行数:11,代码来源:views.py

示例10: new_project

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def new_project(request):
    if request.method == "POST":
        form = ProjectForm(request.POST or None)
        if form.is_valid():
            if form.save():
                return redirect("/projects")
    else:
        form = ProjectForm()
    data = {"form": form}
    return render(request, "projects/new_project.html", data)
开发者ID:northDacoder,项目名称:devshop,代码行数:12,代码来源:views.py

示例11: add_project

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def add_project(request):
    """
    View to add a project.
    """
    form=ProjectForm(request.POST or None)
    if form.is_valid():
        project=form.save(commit=False)
        project.save()
        return redirect(project)
    return render_to_response('projects/project_form.html', {'form': form}, context_instance=RequestContext(request))
开发者ID:melbic,项目名称:expenses,代码行数:12,代码来源:views.py

示例12: post

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
	def post(self, request):
		form = ProjectForm(request.POST)

		if form.is_valid():
			project = form.save()
			messages.success(request, 'Project \'' + project.name + '\' was successfully created.')
			return redirect('/projects')
		else:
			messages.error(request, 'Sorry, but there was a problem with the information you supplied.')
			return render_create(request, form)
开发者ID:alextiley,项目名称:django-project-tracker,代码行数:12,代码来源:views.py

示例13: submit_project

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def submit_project(request):
    form = ProjectForm(request.POST or None)
    if form.is_valid():
        project = form.save(commit=False)
        project.user = request.user
        project.save()
        return redirect(project)
    return render_to_response('add_project.html',
                              {'form': form},
                              context_instance=RequestContext(request))
开发者ID:mgfcm,项目名称:cs191-crowdfunding,代码行数:12,代码来源:views.py

示例14: view_project

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def view_project(request, project_id):
    project = get_object_or_404(Project, pk=project_id,
                                course=request.course)
    space_owner = in_course_or_404(project.author.username, request.course)

    if not project.collaboration(request).permission_to('edit',request):
        #LEGACY: try again for legacy projects
        if not project.collaboration(request, sync_group=True).permission_to('edit',request):
            return HttpResponseRedirect(project.get_absolute_url())

    if request.method == "GET":
        if request.META.get('HTTP_ACCEPT','').find('json') >=0:
            return project_json(request, project)
        return project_workspace(request, space_owner, project)

    if request.method == "DELETE":
        project.delete()
        return HttpResponseRedirect(
            reverse('your-records', args=[request.user.username]))

    if request.method == "POST":
        projectform = ProjectForm(request, instance=project,data=request.POST)
        if projectform.is_valid():
            if "Preview" == request.POST.get('submit',None):
                #doesn't send project.author, and other non-exposed fields
                mock_project = projectform.cleaned_data.copy()
                mock_project['attribution_list'] = mock_project['participants']
                mock_project['assignment'] = projectform.instance.assignment()
                mock_project['id'] = project_id
                return project_preview(request, space_owner, mock_project, 
                                       is_participant=True, preview_num=request.GET.get('preview',1))
            
            #legacy and for optimizing queries
            projectform.instance.submitted = (request.POST.get('publish',None) != 'PrivateEditorsAreOwners')
            
            #this changes for version-tracking purposes
            projectform.instance.author = request.user
            projectform.save()

            projectform.instance.collaboration(request, sync_group=True)

            if request.META.get('HTTP_ACCEPT','').find('json') >=0:
                v_num = projectform.instance.get_latest_version()
                return HttpResponse(simplejson.dumps(
                        {'status':'success',
                         'revision':{
                                'id':v_num,
                                'url':reverse('project_version_preview',args=[project_id, v_num]),
                                'public_url':projectform.instance.public_url(),
                                }
                         }, indent=2),
                                    mimetype='application/json')

        redirect_to = '.'
        return HttpResponseRedirect(redirect_to)
开发者ID:aayman,项目名称:mediathread,代码行数:57,代码来源:views.py

示例15: edit_project

# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import is_valid [as 别名]
def edit_project(request, project_id):
    project = Project.objects.get(id=project_id)
    if request.method == "POST":
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            if form.save():
                return redirect("/projects/{}".format(project_id))
    else:
        form = ProjectForm(instance=project)
    data = {"project": project, "form": form}
    return render(request, "projects/edit_project.html", data)
开发者ID:northDacoder,项目名称:devshop,代码行数:13,代码来源:views.py


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