本文整理汇总了Python中projects.forms.ProjectForm类的典型用法代码示例。如果您正苦于以下问题:Python ProjectForm类的具体用法?Python ProjectForm怎么用?Python ProjectForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProjectForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_project_view
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'))
示例2: projectsubmit
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})
示例3: __project_edit
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
示例4: edit_project
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)
示例5: project_create
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))
示例6: submit_project
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))
示例7: create
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})
示例8: post
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))
示例9: project_edit
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",},
})
示例10: new_project
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)
示例11: add_project
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))
示例12: post
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)
示例13: submit_project
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))
示例14: view_project
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)
示例15: edit_project
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)