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


Python GroupForm.is_valid方法代码示例

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


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

示例1: group_create

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [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))
开发者ID:ejucovy,项目名称:localpower,代码行数:27,代码来源:views.py

示例2: edit_group

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [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
    })
开发者ID:VBelozyorov,项目名称:libcms,代码行数:36,代码来源:views.py

示例3: group_edit

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [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))
开发者ID:ejucovy,项目名称:localpower,代码行数:62,代码来源:views.py

示例4: new_group

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [as 别名]
def new_group(request):
    if request.method == 'POST':
        form = GroupForm(request.POST)
        if form.is_valid():
            group_code = helper.post_request("https://a6.cfapps.io/groups", {})
            groupID = json.loads(group_code)['groupId']
            group = Group.objects.create(code=groupID, name=form.cleaned_data['name'])
            group.save()
            #Create a new subscription for group
            url = "https://a6.cfapps.io/subscriptions"
            payload = {}
            payload['groupId'] = group.code
            payload['insights'] = [
                "home.window.open",
                "home.window.closed",
                "home.garage.open",
                "home.garage.closed",
                "home.smoke.alarm_on",
                "home.smoke.alarm_off",
                "home.smoke.alarm_battery_low",
                "home.fire.alarm_on",
                "home.fire.alarm_off",
                "home.water.sensor.alarm_on",
                "home.water.sensor.alarm_off",
                "vehicle.trip.arrived",
                "vehicle.health.arrived"]
            payload['webhookUrl'] = 'https://homesensing.cfapps.io/callback'
            result = helper.post_request(url, payload)
            print result
            return HttpResponseRedirect("/index")
    else:
        form = GroupForm()
    return render_to_response('new_group.html', { 'form' : form }, context_instance=RequestContext(request))
开发者ID:sameetandpotatoes,项目名称:Homesense,代码行数:35,代码来源:views.py

示例5: create_group

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [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
    })
开发者ID:isergey,项目名称:liart_portal,代码行数:13,代码来源:views.py

示例6: save_new_group

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [as 别名]
def save_new_group(request):

    if request.method == 'POST':
        form = GroupForm(request.POST)
        if form.is_valid():
            group = Group()
            group.name = form.cleaned_data['name']
            group.max_loan_days = form.cleaned_data['max_loan_days']
            group.save()

    return HttpResponseRedirect('/webconf/couchauth/')
开发者ID:GaloC,项目名称:gplib,代码行数:13,代码来源:webconf.py

示例7: save_new_group

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [as 别名]
def save_new_group(request):

    if request.method == 'POST':

        form = GroupForm(request.POST)
        if form.is_valid():

            group = Group()
            group.name = form.cleaned_data['name']
            group.save()

    return HttpResponseRedirect('/webconf/aclsmanager/show_groups/')
开发者ID:GaloC,项目名称:gplib,代码行数:14,代码来源:aclsmanager.py

示例8: add_group

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [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,})
开发者ID:lig,项目名称:picket_classic,代码行数:15,代码来源:views.py

示例9: save_group

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [as 别名]
def save_group(request, group_id):
    try:
        group = Group.objects.get(id=group_id)
    except Group.DoesNotExist:
        return HttpResponseRedirect('/webconf/aclsmanager/show_groups/')

    if request.method == 'POST':
        form = GroupForm(request.POST)
        if form.is_valid():
            group.name = form.cleaned_data['name']
            group.save()

    return HttpResponseRedirect('/webconf/aclsmanager/show_groups/')
开发者ID:GaloC,项目名称:gplib,代码行数:15,代码来源:aclsmanager.py

示例10: add_group

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [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)
开发者ID:Veterun,项目名称:questions,代码行数:17,代码来源:views.py

示例11: edit_group

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [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,})
开发者ID:lig,项目名称:picket_classic,代码行数:17,代码来源:views.py

示例12: group_add

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [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())
开发者ID:ccc520,项目名称:adminset,代码行数:18,代码来源:group.py

示例13: post

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [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)
开发者ID:TownHall,项目名称:TownHall,代码行数:19,代码来源:views.py

示例14: edit_group

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [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)
开发者ID:Veterun,项目名称:questions,代码行数:19,代码来源:views.py

示例15: edit_group

# 需要导入模块: from forms import GroupForm [as 别名]
# 或者: from forms.GroupForm import is_valid [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))
开发者ID:tekton,项目名称:DocuCanvas,代码行数:47,代码来源:views.py


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