本文整理汇总了Python中projects.forms.ProjectForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectForm.save方法的具体用法?Python ProjectForm.save怎么用?Python ProjectForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类projects.forms.ProjectForm
的用法示例。
在下文中一共展示了ProjectForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: project_edit
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [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",},
})
示例2: view_project
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [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)
示例3: edit_project
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [as 别名]
def edit_project(request, slug):
if request.method == 'POST':
project = get_object_or_404(Project, slug=slug)
form = ProjectForm(request.POST, instance=project)
if form.is_valid():
form.save()
return HttpResponseRedirect(project.get_absolute_url())
else:
project = get_object_or_404(Project, slug=slug)
form = ProjectForm(instance=project)
return render_to_response('projects/new_project.html', {'form': form}, context_instance=RequestContext(request))
示例4: edit_project
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [as 别名]
def edit_project(request, id):
project = Project.objects.get(pk=id)
if request.method == 'POST':
form = ProjectForm(request.POST, instance=project)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('project_index'))
else:
return render(request, 'projects/edit_project.html', {'form': form})
else:
form = ProjectForm(instance=project)
return render(request, 'projects/edit_project.html', {'form': form})
示例5: project_save
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [as 别名]
def project_save(request, project_id):
project = get_object_or_404(Project, pk=project_id, course=request.course)
if not project.can_edit(request) or not request.method == "POST":
return HttpResponseRedirect(project.get_absolute_url())
# verify user is in course
in_course_or_404(project.author.username, request.course)
projectform = ProjectForm(request, instance=project, data=request.POST)
if projectform.is_valid():
# 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',
'is_assignment': projectform.instance.is_assignment(request),
'title': projectform.instance.title,
'revision': {
'id': v_num,
'public_url': projectform.instance.public_url(),
'visibility': project.visibility_short(),
'due_date': project.get_due_date()
}
}, indent=2), mimetype='application/json')
else:
ctx = {'status': 'error', 'msg': ""}
for key, value in projectform.errors.items():
if key == '__all__':
ctx['msg'] = ctx['msg'] + value[0] + "\n"
else:
ctx['msg'] = \
'%s "%s" is not valid for the %s field.\n Please %s\n' % \
(ctx['msg'], projectform.data[key],
projectform.fields[key].label,
value[0].lower())
return HttpResponse(simplejson.dumps(ctx, indent=2),
mimetype='application/json')
示例6: submit_project
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [as 别名]
def submit_project(request):
form = ProjectForm()
add_tier_formset = inlineformset_factory(Project, Tier, extra=0, exclude=[])
project = form.save(commit=False)
if request.method == 'POST':
form = ProjectForm(request.POST, request.FILES)
if 'add_tier' in request.POST:
copy = request.POST.copy()
copy['tier-TOTAL_FORMS'] = int(copy['tier-TOTAL_FORMS'])+ 1
new_tier = add_tier_formset(copy, prefix='tier', instance=project)
elif 'submit' in request.POST:
project = form.save(commit=False)
if form.is_valid():
user = request.user
project.user = user
project.video = request.FILES['video']
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 " + user.userprofile.first_name + " " + user.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()
new_tier = add_tier_formset(request.POST, prefix='tier', instance=project)
if new_tier.is_valid():
new_tier.save()
return redirect(project)
else:
new_tier = add_tier_formset(prefix='tier',instance=project)
return render_to_response('add_project.html',
{'form': form, 'tier': new_tier},
context_instance=RequestContext(request))
示例7: submit_project
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [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))
示例8: create
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [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})
示例9: new_project
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [as 别名]
def new_project(request):
if request.method == 'POST':
project = Project()
form = ProjectForm(request.POST, instance=project)
if form.is_valid():
form.save(commit=False)
project.user = request.user
project.admingroup = request.organization.admingroup
project.save()
form.save_m2m()
return HttpResponseRedirect(project.get_absolute_url())
else:
project = Project()
form = ProjectForm(instance=project)
return render_to_response('projects/new_project.html', {'form': form}, context_instance=RequestContext(request))
示例10: post
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [as 别名]
def post(self, request, *args, **kwargs):
project_form = ProjectForm(request.POST)
if project_form.is_valid():
project_form.save()
return super(AddProjectView, self).post(request, *args, **kwargs)
else:
# Redisplay the create project form.
return render(
request,
"projects/project_form.html",
{
"form": ProjectForm,
#'error_message': project_form.errors,
"error_message": "All the fields are required.",
},
)
示例11: projectsubmit
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [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})
示例12: edit_project
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [as 别名]
def edit_project(request):
c = get_common_context(request)
user = request.user
profile = user.get_profile()
proj = Participant.get_project(user)
c['slug'] = proj.slug
if request.method == 'GET':
c['form'] = ProjectForm(instance=proj)
else:
form = ProjectForm(request.POST, request.FILES, instance=proj)
if form.is_valid():
form.save()
return HttpResponseRedirect('/project/%s/' % Participant.get_project(user))
else:
pass
c['form'] = form
return render_to_response('edit_project.html', c, context_instance=RequestContext(request))
示例13: add_project
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [as 别名]
def add_project(request):
"""
view to display the form to add a new project
"""
#make sure form was submitted via post
if request.method == "POST":
form = ProjectForm(request.POST)
if form.is_valid():
form.instance.user_id = request.user.id
form.save()
#redirect to home after successful save
return HttpResponseRedirect('/')
else:
context = {'form': form}
return render_to_response('add_project.html', context, context_instance=RequestContext(request))
else:
return render_to_response('add_project.html', {'form': ProjectForm()}, context_instance=RequestContext(request))
示例14: post
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [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))
示例15: new_project
# 需要导入模块: from projects.forms import ProjectForm [as 别名]
# 或者: from projects.forms.ProjectForm import save [as 别名]
def new_project(request):
names= ['Create New Project','OnGoing Projects','Completed Projects']
links = [reverse('new_project'),reverse('projects'),reverse('old_projects')]
submenus = create_sub(names,links)
context = {'proj_selected':'current'}
if len(request.POST) <= 0:
form = ProjectForm()
context.update({'form':form,'entity':'Project','submenus':submenus})
return render(request , "new.html", context)
else :
form = ProjectForm(request.POST)
if form.is_valid() :
form.save(commit=True)
url = reverse('projects')
return HttpResponseRedirect("%s?success=2"%(url))
else :
context.update({'title':'Create New Project','form': form,'entity':'Project','errors':'Invalid Entry or required fields not filled'})
return render(request, "new.html", context )