コード例 #1
0
ファイル: views.py プロジェクト: VBelozyorov/libcms
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
    })
コード例 #2
0
ファイル: views.py プロジェクト: VBelozyorov/libcms
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
    })
コード例 #3
0
ファイル: views.py プロジェクト: Kirito1899/libcms
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
    })
コード例 #4
0
ファイル: views.py プロジェクト: Kirito1899/libcms
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
    })