本文整理汇总了Python中forms.GroupForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python GroupForm.save方法的具体用法?Python GroupForm.save怎么用?Python GroupForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.GroupForm
的用法示例。
在下文中一共展示了GroupForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_group
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def create_group(request):
if request.method == 'POST':
form = GroupForm(request.POST)
if form.is_valid():
form.save()
return redirect('accounts:administration:groups_list')
else:
form = GroupForm()
return render(request, 'accounts/administration/create_group.html', {
'form': form
})
示例2: group_create
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def group_create(request):
"""
create a form a user can use to create a custom group, on POST save this group to the database
and automatically add the creator to the said group as a manager.
"""
nav_selected = "communities"
if request.method == "POST":
form = GroupForm(request.POST, request.FILES)
if form.is_valid():
group = form.save()
GroupUsers.objects.create(group=group, user=request.user, is_manager=True)
Stream.objects.get(slug="community-create").enqueue(content_object=group, start=group.created)
Record.objects.create_record(request.user, 'group_create', group)
badge_cache.possibly_award_badge('created_a_community', user=request.user)
messages.success(request, _("%(group)s has been created.") % {
'group': group})
return redirect("group_detail", group_slug=group.slug)
else:
form = GroupForm()
return render_to_response("groups/group_create.html", {
"form": form,
"site": Site.objects.get_current(),
"nav_selected": nav_selected,
'external_group': False,
}, context_instance=RequestContext(request))
示例3: edit_group
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def edit_group(request, id):
group = get_object_or_404(Group, id=id)
try:
group_title = models.GroupTitle.objects.get(group=group)
except models.GroupTitle.DoesNotExist:
group_title = None
if request.method == 'POST':
form = GroupForm(request.POST, instance=group)
group_title_form = GroupTitleForm(request.POST, prefix='gtf', instance=group_title)
if form.is_valid() and group_title_form.is_valid():
group = form.save(commit=False)
if form.cleaned_data['permissions']:
group.permissions = form.cleaned_data['permissions']
else:
group.permissions.clear()
group.save()
if not group_title:
group_title = group_title_form.save(commit=False)
group_title.group = group
group_title.save()
else:
group_title_form.save()
return redirect('accounts:administration:groups_list')
else:
form = GroupForm(instance=group)
group_title_form = GroupTitleForm(prefix='gtf', instance=group_title)
return render(request, 'accounts/administration/edit_group.html', {
'form': form,
'group_title_form': group_title_form
})
示例4: group_add
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def group_add(request):
temp_name = "cmdb/cmdb-header.html"
if request.method == "POST":
group_form = GroupForm(request.POST)
if group_form.is_valid():
group_form.save()
tips = u"增加成功!"
display_control = ""
else:
tips = u"增加失败!"
display_control = ""
return render(request, "cmdb/group_base.html", locals())
else:
display_control = "none"
group_form = GroupForm()
return render(request, "cmdb/group_base.html", locals())
示例5: group_edit
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def group_edit(request, group_slug):
nav_selected = "communities"
group = get_object_or_404(Group, slug=group_slug, is_geo_group=False)
if not group.is_user_manager(request.user):
return forbidden(request)
if group.is_external_link_only:
return _group_external_link_only_edit(request, group)
external_group = False
if request.method == "POST":
if "change_group" in request.POST:
group_form = GroupForm(request.POST, request.FILES, instance=group)
if group_form.is_valid():
group = group_form.save()
messages.success(request, _("%(group)s has been updated.") % {'group': group})
return redirect("group_edit", group_slug=group.slug)
else:
membership_form = MembershipForm(group=group)
discussions_form = DiscussionSettingsForm(instance=group)
if "discussion_settings" in request.POST:
discussions_form = DiscussionSettingsForm(request.POST, instance=group)
if discussions_form.is_valid():
group = discussions_form.save()
messages.success(request, _("%(group)s has been updated.") % {'group': group})
return redirect("group_edit", group_slug=group.slug)
else:
membership_form = MembershipForm(group=group)
group_form = GroupForm(instance=group)
elif "delete_group" in request.POST:
group.delete()
messages.success(request, _("%(group)s has been deleted.") % {'group': group})
return redirect("group_list")
elif "change_membership" in request.POST:
membership_form = MembershipForm(group=group, data=request.POST)
if membership_form.is_valid():
membership_form.save()
if group.is_user_manager(request.user):
messages.success(request, _("%(group)s's memberships have been updated.") % {
'group': group})
return render_to_response("groups/group_edit.html", locals(),
context_instance=RequestContext(request))
else:
messages.success(request,
_("You no longer have permissions to edit %(group)s") % {
'group': group})
return redirect("group_detail", group_slug=group.slug)
else:
group_form = GroupForm(instance=group)
discussions_form = DiscussionSettingsForm(instance=group)
else:
messages.error(request, _("No action specified."))
else:
group_form = GroupForm(instance=group)
membership_form = MembershipForm(group=group)
discussions_form = DiscussionSettingsForm(instance=group)
site = Site.objects.get_current()
requesters = group.requesters_to_grant_or_deny(request.user)
return render_to_response("groups/group_edit.html", locals(),
context_instance=RequestContext(request))
示例6: edit_group
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def edit_group(request, group_id):
context = {}
group = Group.objects.get(pk=group_id)
if not request.user.is_staff and request.user.email != group.added_by.email:
return HttpResponseRedirect("/group/%s" % group_id)
if request.method == "POST":
form = GroupForm(request.POST, instance=group)
if form.is_valid():
form.save()
return HttpResponseRedirect("/group/%s" % group_id)
else:
form = GroupForm(instance=group)
context["form"] = form
return r2r(request, "edit_group", context)
示例7: group_edit
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def group_edit(request, group_id):
project = HostGroup.objects.get(id=group_id)
temp_name = "cmdb/cmdb-header.html"
if request.method == 'POST':
form = GroupForm(request.POST, instance=project)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('group'))
else:
form = GroupForm(instance=project)
display_control = "none"
results = {
'group_form': form,
'group_id': group_id,
'request': request,
'temp_name': temp_name,
'display_control': display_control,
}
return render(request, 'cmdb/group_base.html', results)
示例8: add_group
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def add_group(request):
if request.method == 'POST':
groupForm = GroupForm(request.POST)
if groupForm.is_valid():
group = groupForm.save()
request.user.message_set.create(message=_('Group created'))
return redirect('picket-admin-users')
else:
groupForm = GroupForm()
return direct_to_template(request, 'picket/admin/group_add.html',
{'group_form': groupForm,})
示例9: edit_group
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def edit_group(request, group_id=None):
if group_id:
group = get_object_or_404(Group, pk=group_id)
else:
group = None
if request.method == "POST":
if group:
form = GroupForm(request.POST, instance=group)
else:
form = GroupForm(request.POST)
if form.is_valid():
form.save()
return redirect("index")
else:
if group:
form = GroupForm(instance=group)
else:
form = GroupForm()
data = dict(form=form, group_id=group_id)
return render_to_response("group/add_group.html", data, context_instance=RequestContext(request))
示例10: edit_group
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def edit_group(request, groupId):
group = get_object_or_404(Group, id=groupId)
if request.method == 'POST':
groupForm = GroupForm(request.POST, instance=group)
if groupForm.is_valid():
group = groupForm.save()
request.user.message_set.create(message=_('Group updated'))
return redirect('picket-admin-users')
else:
groupForm = GroupForm(instance=group)
return direct_to_template(request, 'picket/admin/group_edit.html',
{'group_form': groupForm,})
示例11: add_group
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def add_group(request):
context = {}
if request.method == "POST":
form = GroupForm(request.POST)
if form.is_valid():
group = form.save(commit=False)
group.added_by = request.user
group.save()
return HttpResponseRedirect("/group/%s" % group.id)
else:
form = GroupForm()
context["form"] = form
return r2r(request, "add_group", context)
示例12: post
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def post(self, request, format=None, *args, **kwargs):
if format == 'html' or format == None:
form = GroupForm(request.POST)
if form.is_valid():
group = form.save(commit=False)
group.creator = request.user
group.save()
group.members.add(request.user)
group.save()
return redirect('/groups/' + str(group.id))
elif format == 'json':
serializer = GroupSerializer(data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors)
示例13: edit_group
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def edit_group(request, group_id):
projects = Project.objects.all()
print(request.POST)
try:
group = ReportGroup.objects.get(pk=group_id)
except Exception as e:
print("Exception: " + str(e))
try:
members = GroupMember.objects.filter(group=group)
except Exception as e:
print("Exception: " + str(e))
try:
users = User.objects.all()
user_list = []
for user in users:
keep = True
for member in members:
if member.user == user:
keep = False
if keep:
user_list.append(user)
except Exception as e:
print("Exception: " + str(e))
if request.method == 'POST':
try:
form = GroupForm(request.POST, instance=group)
added_members = request.POST.getlist('new_members')
removed_members = request.POST.getlist('del_members')
if form.is_valid():
group = form.save()
for member in added_members:
temp = User.objects.get(pk=member)
new_member = GroupMember(group=group, user=temp)
new_member.save()
for member in removed_members:
temp = User.objects.get(pk=member)
old_member = GroupMember.objects.get(user=temp, group=group)
old_member.delete()
return redirect('daily_reports.views.request_report_summary')
except Exception as e:
print(e)
else:
form = GroupForm(instance=group)
return render_to_response('daily_reports/edit_report_group.html', {'members': members, 'users': user_list, 'form': form, 'projects': projects, 'group': group}, context_instance=RequestContext(request))
示例14: group_add
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def group_add(request, response_format='html'):
"Group add"
if request.POST:
if 'cancel' not in request.POST:
form = GroupForm(request.POST)
if form.is_valid():
group = form.save()
return HttpResponseRedirect(reverse('core_admin_group_view', args=[group.id]))
else:
return HttpResponseRedirect(reverse('core_admin_index_groups'))
else:
form = GroupForm()
return render_to_response('core/administration/group_add',
{'form': form},
context_instance=RequestContext(request), response_format=response_format)
示例15: create_group
# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import save [as 别名]
def create_group(request):
if request.method == 'POST':
form = GroupForm(request.POST)
group_title_form = GroupTitleForm(request.POST, prefix='gtf')
if form.is_valid() and group_title_form.is_valid():
group = form.save(commit=False)
group.save()
group_title = group_title_form.save(commit=False)
group_title.group = group
group_title.save()
return redirect('accounts:administration:groups_list')
else:
form = GroupForm()
group_title_form = GroupTitleForm(prefix='gtf')
return render(request, 'accounts/administration/create_group.html', {
'form': form,
'group_title_form': group_title_form
})